Tutorials › Stochastic Processes › Monte Carlo Error Bars for Markov Chain Summaries

Simulation of Stochastic Processes · Tutorial 981 of 994

Monte Carlo Error Bars for Markov Chain Summaries

Use independent simulated paths—not individual dependent steps—to quantify the uncertainty in an estimated Markov chain summary.

Intermediate 10 min read

What You'll Learn

  • Define a path summary as one observation from each simulated trajectory.
  • Compute the replicate mean, sample variance, and Monte Carlo standard error.
  • Construct and interpret approximate confidence intervals for an expected path summary.
  • Distinguish dependence within a path from independence between paths.
  • Diagnose the underestimated error that results from treating dependent steps as independent.
  • Recognize when finite-variance and independent-replicate assumptions matter.

One Trajectory, One Replicate

A simulated Markov chain path is usually dependent over time: the state at one step can influence the next state. That dependence does not prevent us from estimating uncertainty for a summary of the path. The key is to regard each independently generated trajectory as one replicate, calculate the summary once for that trajectory, and estimate variability across the replicate summaries. The number of steps in one path is not the number of independent replicates.

Let \((\Omega,\mathcal{F},\mathbb{P})\) be a probability space, and let \((X_n)_{n\ge0}\) be a discrete-time Markov chain on a finite state space \(S\), with transition matrix \(P=(p_{ij})\). Its natural filtration is \(\mathcal{F}_n=\sigma(X_0,\ldots,X_n)\). Fix a finite path length \(m\), and let \(g:S^{m+1}\to\mathbb{R}\) be a summary of the path. For example, \(g\) might be the fraction of steps spent in a chosen state or the total accumulated reward. The summary from one path is the random variable \(Y=g(X_0,\ldots,X_m)\).

Now simulate \(R\) independent trajectories using the same initial-state rule and transition matrix. Write \(Y_r\) for the summary from trajectory \(r\), where \(1\le r\le R\). The trajectories are generated independently of one another and have the same simulation rule, so the summaries \(Y_1,\ldots,Y_R\) are independent and identically distributed. The quantity of interest is their common expectation \(\theta=\mathbb{E}[Y_r]\), estimated by their average.

Definition: The Monte Carlo estimate of the expected path summary is \(\bar{Y}=R^{-1}\sum_{r=1}^R Y_r\). For \(R\ge2\), the replicate sample variance is \(s^2=(R-1)^{-1}\sum_{r=1}^R(Y_r-\bar{Y})^2\), and the estimated Monte Carlo standard error is \(\widehat{\operatorname{SE}}(\bar{Y})=s/\sqrt{R}\). These calculations use the independent replicate summaries, not the individual states within each path.

These formulas estimate uncertainty in \(\bar{Y}\) as an estimate of \(\theta\). They do not measure how well one particular trajectory represents every feature of a chain, and they do not remove bias caused by choosing a path length or initial-state rule that does not match the target quantity. First specify the target, then make sure each replicate is generated under the intended rule.

Why the Replicate Standard Error Works

Theorem: If \(Y_1,\ldots,Y_R\) are independent and identically distributed with \(\mathbb{E}[Y_r]=\theta\) and \(\operatorname{Var}(Y_r)=\sigma^2<\infty\), then \(\mathbb{E}[\bar{Y}]=\theta\) and \(\operatorname{Var}(\bar{Y})=\sigma^2/R\). For \(R\ge2\), the sample variance \(s^2\) is unbiased for \(\sigma^2\), so \(s/\sqrt{R}\) estimates the standard deviation of \(\bar{Y}\).

Proof. Linearity of expectation gives \(\mathbb{E}[\bar{Y}]=R^{-1}\sum_{r=1}^R\mathbb{E}[Y_r]=\theta\). Independence makes the covariance between distinct replicates zero, so \(\operatorname{Var}(\bar{Y})=R^{-2}\sum_{r=1}^R\operatorname{Var}(Y_r)=R^{-2}R\sigma^2=\sigma^2/R\). For the sample variance, use the identity \(\sum_r(Y_r-\bar{Y})^2=\sum_r(Y_r-\theta)^2-R(\bar{Y}-\theta)^2\). Taking expectations, the first term on the right has expectation \(R\sigma^2\); the second has expectation \(R\operatorname{Var}(\bar{Y})=\sigma^2\). Thus \(\mathbb{E}[\sum_r(Y_r-\bar{Y})^2]=(R-1)\sigma^2\), and dividing by \(R-1\) gives \(\mathbb{E}[s^2]=\sigma^2\). Therefore \(s/\sqrt{R}\) estimates \(\sqrt{\operatorname{Var}(\bar{Y})}\). \(\square\)

The theorem explains the role of the number of replicates: when the replicate variance stays fixed, the standard deviation of the average decreases in proportion to \(1/\sqrt{R}\). Increasing the number of steps within a path can change the summary's distribution and variance, but it does not by itself create more independent replicates.

Confidence Intervals for an Expected Summary

A common approximate 95% confidence interval for \(\theta\), when \(R\) is sufficiently large, is \(\bar{Y}\pm1.96\,s/\sqrt{R}\). This uses the standard independent, identically distributed central limit theorem: with finite variance, the standardized replicate mean approaches a standard normal distribution as \(R\) increases. The theorem is a standard result; its proof is beyond this tutorial. Replacing \(\sigma\) by \(s\) gives the usual estimated-standard-error interval. Its coverage is approximate for general replicate distributions, especially when \(R\) is small or the distribution is strongly skewed. If the replicate summaries are normally distributed, the interval using the appropriate Student \(t\) quantile is exact for every \(R\ge2\); normality should not be assumed merely because the chain has many steps.

A confidence interval describes the repeated-simulation performance of the interval procedure: under its assumptions, intervals constructed from repeated sets of independent trajectories cover \(\theta\) at the stated rate (exactly or approximately as specified). It does not mean that 95% of the path summaries lie inside this interval. Nor does one realized interval have a 95% probability of containing a fixed \(\theta\); after the data are observed, it either contains that value or it does not.

Worked Example: Occupation Fractions from Four Paths

Let \(S=\{0,1\}\), and use the transition matrix \(P=\begin{bmatrix}\tfrac12&\tfrac12\\\tfrac12&\tfrac12\end{bmatrix}\). Each row sums to \(\tfrac12+\tfrac12=1\). Start every trajectory at \(X_0=0\), simulate through \(X_2\), and let \(Y\) be the fraction of \(X_1,X_2\) equal to state \(1\). Four independent simulated paths have post-start states \((0,0),(0,1),(1,0),(1,1)\), giving summaries \(0,\tfrac12,\tfrac12,1\). We estimate the expected occupation fraction under this simulation rule.

The replicate mean is \(\bar{Y}=(0+\tfrac12+\tfrac12+1)/4=2/4=\tfrac12\). The four deviations from the mean are \(-\tfrac12,0,0,\tfrac12\), so the sum of their squares is \(\tfrac14+0+0+\tfrac14=\tfrac12\). Consequently, \(s^2=(\tfrac12)/3=\tfrac16\), and \(\widehat{\operatorname{SE}}(\bar{Y})=\sqrt{(\tfrac16)/4}=\sqrt{\tfrac1{24}}\).

Using the large-sample normal critical value gives the approximate interval \(\tfrac12\pm1.96\sqrt{\tfrac1{24}}\), or approximately \([0.100,0.900]\). This interval is wide because there are only four replicates; its nominal normal coverage is not guaranteed at this small sample size. Check: the endpoints have midpoint \(\tfrac12\), and the half-width is \(1.96\sqrt{\tfrac1{24}}\), as required by the formula. The sample variance calculation also uses all four replicate summaries and has denominator \(R-1=3\).

Why Steps Within a Path Cannot Be Counted as Replicates

To see the danger of pooling steps, consider the state space \(S=\{0,1\}\) and the transition matrix \(P=\begin{bmatrix}1&0\\0&1\end{bmatrix}\). Each row sums to \(1\). Give each independently generated path an initial state with probability \(\tfrac12\) at each state. The chain remains at that state forever. Although different paths are independent, states within any one path are perfectly dependent.

Worked Example: An Incorrect Standard Error from Repeated States

Simulate \(R\) independent paths, each containing \(L\) observed states, and estimate the expected state value using the average of all \(RL\) states. The expected state value is \(\tfrac12\). For path \(r\), every observed state equals its initial value \(X_0^{(r)}\), so that path's average is \(Y_r=X_0^{(r)}\), a Bernoulli random variable with variance \(\tfrac12(1-\tfrac12)=\tfrac14\). The overall estimator is \(R^{-1}\sum_{r=1}^R Y_r\), whose variance is \(\tfrac{1}{4R}\) by the independent-replicate variance formula.

If we incorrectly treat the \(RL\) observed states as independent Bernoulli observations, we would calculate the variance as \(\tfrac{1}{4RL}\). That is too small by a factor of \(L\), because the actual variance divided by the incorrect variance is \((1/(4R))/(1/(4RL))=L\). For example, with \(R=2\) independent paths and \(L=3\) states per path, the actual variance is \(\tfrac18\), while the incorrect calculation gives \(\tfrac1{24}\); the ratio is \((\tfrac18)/(\tfrac1{24})=3=L\). The discrepancy comes from counting three identical states per path as if they were three independent pieces of information.

Check: if \(L=1\), there is only one observed state per path, and both variance formulas give \(\tfrac1{4R}\). For \(L>1\), the formulas differ because the states within each path are dependent. Averaging the states within a path first and then computing uncertainty across the \(R\) path averages respects the simulation's independence structure.

This example has extreme dependence, but the general lesson is not limited to chains that never move. Adjacent states in a slowly mixing chain can be strongly related. A formula that treats every step as independent can then give a misleadingly small error bar. The replicate method instead needs independence across trajectories; it makes no assumption that the states within a trajectory are independent.

A Small-Replicate Interval and Its Limits

Worked Example: A Confidence Interval for a Total Reward

Let \(S=\{0,1\}\) and \(P=\begin{bmatrix}\tfrac12&\tfrac12\\\tfrac12&\tfrac12\end{bmatrix}\), whose rows both sum to \(1\). Start each independent path at \(0\), simulate four steps, and define its total reward as \(Y=\sum_{n=1}^4\mathbf{1}_{\{X_n=1\}}\). Five simulated paths produce total rewards \(1,2,2,3,4\). The target is the expected total reward under this fixed starting rule and path length.

The mean is \(\bar{Y}=(1+2+2+3+4)/5=12/5\). The deviations are \(-7/5,-2/5,-2/5,3/5,8/5\); their squared values sum to \((49+4+4+9+64)/25=130/25=26/5\). Thus \(s^2=(26/5)/4=13/10\), and the estimated standard error is \(\sqrt{(13/10)/5}=\sqrt{13/50}\).

For illustration, applying the small-sample \(t\) critical value \(2.776\) with four degrees of freedom gives the interval \(\tfrac{12}{5}\pm2.776\sqrt{\tfrac{13}{50}}\), approximately \([0.985,3.815]\). Since these discrete path summaries are not normally distributed, this \(t\)-based interval is not an exact 95% interval; with only five replicates it should be treated cautiously. Check: the interval midpoint is \(\tfrac{12}{5}=2.4\), and its half-width is \(2.776\sqrt{\tfrac{13}{50}}\), matching the stated estimate and standard error.

The usual normal approximation requires independent, identically distributed replicate summaries with a finite variance. If a fixed-length summary is computed from a finite-state path and takes bounded values, its variance is finite. Unbounded summaries, such as some stopping-time quantities, require more care. For example, independent summaries with Pareto tail probability \(\mathbb{P}(Y>y)=y^{-3/2}\) for \(y\ge1\) have a finite mean but infinite variance. In that case a finite population standard deviation \(\sigma\) does not exist, so the finite-variance standard error formula and its usual central-limit justification do not apply.

Independence across replicates is also essential to the variance calculation. The identity-chain example shows exactly what can go wrong when dependent states are counted as independent observations. If the simulations share random inputs or are otherwise dependent across runs, the replicate variance formula needs additional justification; it cannot be assumed solely because the outputs are labelled as separate runs.

Practical Checks Before Reporting Error Bars

Before reporting a Monte Carlo standard error or interval, check the target, the unit of replication, and the assumptions behind the calculation.

  • Define the target. Say what one path summary measures, its path length, and its initial-state rule.
  • Use independent runs. Generate each trajectory independently under the same simulation rule when using the formulas here.
  • Calculate one summary per path. Compute \(Y_r\) first; then use the \(R\) values to calculate \(\bar{Y}\), \(s^2\), and \(s/\sqrt{R}\).
  • Check the interval's status. Distinguish a large-sample normal approximation from an exact interval under a normal-summary assumption.
  • Report the number of replicates. The uncertainty estimate depends on \(R\), not simply on how many states were generated in total.

Common mistake: If a path contains many dependent states, substituting the total number of states for \(R\) in \(s/\sqrt{R}\) treats those states as independent replicates. In the identity-chain example with \(R=2\) and \(L=3\), this uses six observations and predicts variance \(\tfrac1{24}\), although the correct variance is \(\tfrac18\). The correction is to form one path average from each trajectory and use the two independent path averages as the replicates.

Check Your Understanding

For each question, distinguish the number of independent trajectories from the number of states generated within them.

  1. Four independent trajectories produce summaries \(2,3,3,4\). Compute \(\bar{Y}\), \(s^2\), and the estimated Monte Carlo standard error.
  2. Why can adjacent states from one Markov chain not automatically be used as independent observations when calculating a standard error?
  3. A simulation uses \(R=10\) independent paths, each with 100 observed states. How many independent replicate summaries are available for the method in this tutorial?
  4. Under what additional distributional assumption is the Student \(t\) interval exact for a finite number of independent replicates?
  5. What assumption fails for independent Pareto summaries with tail probability \(\mathbb{P}(Y>y)=y^{-3/2}\), and why does that matter for the usual standard error?