When Conditional Enumeration Is Too Large
A conditional exact test calculates a tail probability under the null distribution given specified sufficient statistics or margins. If the conditional sample space is small, this probability can be found by summing over every table or outcome in that space. When the space is enormous, the same probability can instead be estimated by simulation. The result is then an approximation, and its Monte Carlo error must be reported or assessed separately from the uncertainty represented by the test itself.
Let \(\Omega_s\) be the set of possible outcomes consistent with the observed conditioning statistic \(S=s\). Under a specified null hypothesis, write \(q(y)=P_0(Y=y\mid S=s)\) for the conditional probability of \(y\in\Omega_s\). For a test statistic \(T\), define the inclusive upper-tail set \(A=\{y\in\Omega_s:T(y)\ge T(y_{\mathrm{obs}})\}\). The conditional exact p-value is the probability of this set under \(q\).
This definition concerns the probability under the conditional null law; it does not depend on whether that probability is computed by enumeration or simulation. The choice of tail, including the definition of \(T\), must be made as for the corresponding exact test. Simulation changes the accuracy of the calculation, not the test statistic or its null distribution.
Independent Conditional Simulation
Suppose \(Y_1,\ldots,Y_B\) are independent draws from \(q\), where \(B\) is the number of simulations. For each draw, record whether it falls in the tail set \(A\). Let \(I_b=1\) when \(Y_b\in A\), and \(I_b=0\) otherwise. The number of tail hits \(K=\sum_{b=1}^B I_b\) has a binomial distribution with parameters \(B\) and \(p\).
Proof. Each \(I_b\) is Bernoulli with \(P(I_b=1)=p\), so \(E[I_b]=p\) and \(\operatorname{Var}(I_b)=p(1-p)\). Independence gives \(E[K/B]=B^{-1}\sum_b E[I_b]=p\). It also gives \(\operatorname{Var}(K/B)=B^{-2}\sum_b\operatorname{Var}(I_b)=p(1-p)/B\), since the covariances between distinct indicators are zero. Replacing the unknown \(p\) in this variance formula with \(\hat p\) gives the stated estimated standard error. \(\square\)
For large \(B\), the central limit theorem for independent Bernoulli variables gives an approximate normal sampling distribution for \(\hat p\) when \(0<p<1\). This approximation can be poor when the expected number of hits \(Bp\) is small. In particular, the estimated standard error is zero when \(K=0\), but that does not establish that \(p=0\). A zero-hit run is evidence that the simulation has not resolved the tail at its chosen size.
Worked Example: Estimating a Fisher-Type Conditional Tail
Consider a \(2\times2\) table with fixed row totals 5 and 5 and fixed column totals 4 and 6. Under the conditional null, the upper-left cell \(X\) has a hypergeometric distribution: \(X\) counts how many of the 4 observations in the first column fall in the first row of size 5, among 10 total observations. Suppose the observed value is \(X=4\), and use the upper-tail statistic \(T(X)=X\).
The conditional exact p-value is \(P(X\ge4)\). Since 4 is the largest possible value, \[ P(X\ge4)=P(X=4)=\frac{\binom{4}{4}\binom{6}{1}}{\binom{10}{5}} =\frac{1\cdot6}{252}=\frac{1}{42}\approx0.02381. \]
Now suppose \(B=1000\) independent conditional tables are generated and \(K=24\) have \(X\ge4\). The Monte Carlo estimate is \(\hat p=24/1000=0.024\). Its estimated standard error is \(\sqrt{0.024(0.976)/1000}\approx0.00484\). The estimate is close to the enumerated value, but the standard error indicates noticeable simulation variability relative to the p-value. Reporting \(0.024\) without the simulation size or a precision assessment would conceal that limitation.
Choosing a Simulation Size and Interpreting Zero Hits
A useful planning calculation follows directly from the variance formula. The standard error is largest over \(0\le p\le1\) at \(p=1/2\), where it is \(1/(2\sqrt B)\). Thus, \(B=10{,}000\) gives a worst-case standard error of \(0.005\). For a small tail probability, relative error is often more relevant: when \(p\) is small, the relative standard error is approximately \(1/\sqrt{Bp}\). To aim for relative standard error near 10% when \(p\) is about \(0.001\), one needs roughly \(Bp=100\), or \(B=100{,}000\) simulations.
If no tail events occur, a one-sided binomial upper bound gives more information than a zero plug-in standard error. With \(K=0\), the probability of this outcome at a candidate tail probability \(p\) is \((1-p)^B\). Setting this equal to \(0.05\) gives the 95% upper bound \(p=1-0.05^{1/B}\). For \(B=1000\), this is approximately \(0.00299\). Thus, zero hits in 1000 independent draws is compatible with a tail probability of nearly 0.003; it does not justify reporting an exact p-value of zero.
Worked Example: Planning for a Small Tail Probability
Suppose a pilot calculation suggests a conditional tail probability near \(p=0.001\). To target relative Monte Carlo standard error of about 10%, use \[ \frac{\sqrt{p(1-p)/B}}{p} =\sqrt{\frac{1-p}{Bp}}\approx\frac{1}{\sqrt{Bp}}. \] Setting this to \(0.10\) gives \(Bp\approx100\), so \(B\approx100/0.001=100{,}000\).
By contrast, with only \(B=1000\), the expected number of tail hits is \(Bp=1\). The probability of observing no hits is \((1-p)^B=0.999^{1000}\approx0.368\). A zero-hit result would therefore be unsurprising at this simulation size even when the true conditional tail probability is \(0.001\). Increasing \(B\), rather than interpreting zero hits as zero probability, is the appropriate response when the aim is to resolve such a tail by direct sampling.
Monte Carlo Tests and the Plus-One Estimate
There is a useful distinction between estimating a fixed tail probability and constructing a simulation-based test. The proportion \(K/B\) estimates the conditional p-value for the observed data. For a test based on simulation, one can also count the observed outcome among the compared outcomes and use \((K+1)/(B+1)\). The added one is not a correction that makes \(K/B\) unbiased; rather, it yields a conservative simulation p-value when the observed outcome and simulations are exchangeable under the null.
Proof. Set \(m=B+1\). Because the \(m\) statistics are exchangeable, their ordering is equally likely to be any ordering after ties are broken uniformly at random. The resulting descending rank \(R^*\) of \(T(Y_0)\) is uniform on \(\{1,\ldots,m\}\). The inclusive rank \(R=1+\sum_{b=1}^B\mathbf{1}\{T(Y_b)\ge T(Y_0)\}\) is the largest rank that \(T(Y_0)\) could receive among its tied values. Therefore \(R\le k\) implies \(R^*\le k\). For \(k=\lfloor\alpha m\rfloor\), \(P(R/m\le\alpha)=P(R\le k)\le P(R^*\le k)=k/m\le\alpha\). Since \(p_{\mathrm{MC}}=R/m\), the claimed inequality follows. \(\square\)
This validity result assumes independent draws from the correct conditional null distribution, including the observed outcome in the exchangeability argument. It does not establish that a numerical estimate of a tiny p-value is precise. The value \(p_{\mathrm{MC}}\) also has a minimum of \(1/(B+1)\), so a simulation with limited \(B\) cannot report finer test resolution.
Rare Tails and Importance Sampling
When the tail is very rare, direct conditional simulation may produce few or no hits even with a substantial computational budget. One alternative is importance sampling: draw from a proposal distribution \(r\) that places more probability on the tail, then weight each draw by \(q(y)/r(y)\). The proposal must assign positive probability wherever \(q(y)\) contributes to the target tail. For independent draws \(Z_b\sim r\), the estimate \[ \hat p_{\mathrm{IS}}=\frac{1}{B}\sum_{b=1}^B \mathbf{1}\{Z_b\in A\}\frac{q(Z_b)}{r(Z_b)} \] is unbiased, because its expectation is \(\sum_{y\in A}r(y)q(y)/r(y)=\sum_{y\in A}q(y)=p\). Its variability depends on the proposal and weights; targeting the tail does not guarantee a precise estimate if a few draws receive enormous weights.
Worked Example: Importance Sampling a Rare Conditional Tail
Let \(X\) count successes in 10 independent Bernoulli trials under the null success probability \(1/2\), and consider \(A=\{X\ge9\}\). Direct calculation gives \(p=P(X\ge9)=(\binom{10}{9}+\binom{10}{10})/2^{10}=11/1024\approx0.01074\). Instead, simulate each trial with success probability \(0.8\), which produces the tail more often. For a simulated sequence with \(x\) successes, the likelihood ratio of its null probability to its proposal probability is \[ w(x)=\frac{(1/2)^x(1/2)^{10-x}}{(0.8)^x(0.2)^{10-x}} =(0.625)^x(2.5)^{10-x}. \]
The weights for the two tail counts are \(w(9)\approx0.03638\) and \(w(10)\approx0.009095\). Suppose 10,000 proposal draws yield 2,680 cases with \(X=9\) and 108 with \(X=10\). The weighted estimate is \[ \hat p_{\mathrm{IS}}= \frac{2680(0.03638)+108(0.009095)}{10000} \approx0.00985. \] For comparison, the proposal probabilities of these counts are \(P_r(X=9)=0.268435\) and \(P_r(X=10)=0.107374\); multiplying each by its weight recovers the corresponding null probabilities \(10/1024\) and \(1/1024\). The estimate uses more tail observations than direct simulation would typically produce, while the weights restore the target null probability.
Markov-Chain Sampling and Mixing
Some conditional distributions are difficult to sample independently but can be explored by a Markov chain whose stationary distribution is \(q\). For example, a chain may move between tables in \(\Omega_s\) while preserving the required margins. If the state space is finite and the chain is irreducible and aperiodic, it has a unique stationary distribution; when initialized from that distribution, each state has marginal distribution \(q\). The draws are nevertheless dependent. After a suitable initial transient, averages can converge to the desired conditional probability, but their uncertainty is not given by the independent-binomial formula.
For a stationary chain \(Y_1,\ldots,Y_B\), set \(I_b=\mathbf{1}\{Y_b\in A\}\). If the chain has summable autocorrelations \(\rho_k=\operatorname{Corr}(I_b,I_{b+k})\), then \[ \operatorname{Var}\left(\frac{1}{B}\sum_{b=1}^B I_b\right) =\frac{\operatorname{Var}(I_1)}{B} \left[1+2\sum_{k=1}^{B-1}\left(1-\frac{k}{B}\right)\rho_k\right]. \] This follows by expanding the variance of the sum: there are \(B\) individual variances and \(2(B-k)\) covariance terms at lag \(k\), and each such covariance is \(\operatorname{Var}(I_1)\rho_k\). When the chain satisfies a Markov-chain central limit theorem, the large-\(B\) variance is approximately \(\operatorname{Var}(I_1)\tau/B\), where \(\tau=1+2\sum_{k=1}^{\infty}\rho_k\). The effective sample size is approximately \(B/\tau\); positive serial correlation makes it smaller than \(B\).
Worked Example: A Slowly Mixing Conditional Sampler
Suppose a two-state Markov chain records whether the current conditional outcome is in the tail: state 1 means a tail outcome and state 0 means otherwise. Let its transition probabilities be \(P(0\to1)=0.001\) and \(P(1\to0)=0.009\). Its stationary tail probability is \(\pi_1=0.001/(0.001+0.009)=0.1\). The chain is irreducible and aperiodic, but it tends to remain in its current state.
The nontrivial eigenvalue is \(\lambda=1-0.001-0.009=0.99\), so in stationarity the lag-\(k\) autocorrelation of the state indicator is \(\rho_k=0.99^k\). Its asymptotic variance inflation factor is \[ \tau=1+2\sum_{k=1}^{\infty}0.99^k =1+2\frac{0.99}{1-0.99}=199. \] Thus 10,000 chain iterations have approximate effective sample size \(10000/199\approx50.3\), not 10,000. Since the stationary indicator variance is \(0.1(0.9)=0.09\), the approximate standard error is \(\sqrt{0.09(199)/10000}\approx0.0423\). Treating the states as independent would instead give about \(\sqrt{0.09/10000}=0.003\), a severe understatement. This example shows why stationarity alone does not ensure useful precision: a chain can have the correct target distribution and still mix too slowly for its simulation length.
Practical Checks and Common Pitfalls
Simulation output should include enough information to judge how well the conditional tail has been resolved. For independent sampling, report \(B\), \(K\), the estimate, and an appropriate uncertainty assessment; if \(K\) is small, avoid relying on a normal approximation alone. For a Markov chain, report the chain length and assess dependence in the tail indicator, not only in the raw table entries. Multiple chains and trace plots can reveal some problems, but apparent stability does not prove that all relevant regions of the conditional space have been explored.
- Mistake: treating zero hits as a zero p-value. A finite run with no hits only shows that the event was not seen. Use a binomial upper bound or increase the simulation effort.
- Mistake: using \(K/B\) as if it had no simulation error. It is an estimate of a conditional probability, not the probability itself. State its Monte Carlo uncertainty.
- Mistake: applying an independent-sampling standard error to MCMC output. Correlated draws contain less information. Account for autocorrelation or effective sample size.
- Mistake: assuming more simulations automatically fix poor mixing. A chain that repeatedly explores only part of the relevant state space can remain misleading even when it produces many iterations.
- Mistake: treating importance weights as optional. Proposal samples estimate a different distribution unless corrected by the likelihood ratio.
Check Your Understanding
Answer these questions using the definitions and calculations above.
- For independent conditional draws, why is the variance of the tail-hit proportion \(p(1-p)/B\)?
- If no tail events occur in 2,000 independent draws, does the estimated p-value equal zero? What additional quantity could you report?
- Under what exchangeability condition does the plus-one Monte Carlo test have its stated validity property?
- Why can a Markov chain with the correct stationary distribution still give a poor estimate of a conditional tail probability?
- In importance sampling, why must the proposal assign positive probability to every outcome in the target tail that has positive null probability?