Introduction to Bayesian Analysis Procedures

Assessing Markov Chain Convergence

Simulation-based Bayesian inference requires using simulated draws to summarize the posterior distribution or calculate any relevant quantities of interest. You need to treat the simulation draws with care. There are usually two issues. First, you have to decide whether the Markov chain has reached its stationary, or the desired posterior, distribution. Second, you have to determine the number of iterations to keep after the Markov chain has reached stationarity. Convergence diagnostics help to resolve these issues. Note that many diagnostic tools are designed to verify a necessary but not sufficient condition for convergence. There are no conclusive tests that can tell you when the Markov chain has converged to its stationary distribution. You should proceed with caution. Also, note that you should check the convergence of all parameters, and not just those of interest, before proceeding to make any inference. With some models, certain parameters can appear to have very good convergence behavior, but that could be misleading due to the slow convergence of other parameters. If some of the parameters have bad mixing, you cannot get accurate posterior inference for parameters that appear to have good mixing. See Cowles and Carlin (1996) and Brooks and Roberts (1998) for discussions about convergence diagnostics.

Statistical Diagnostic Tests

The Bayesian procedures include several statistical diagnostic tests that can help you assess Markov chain convergence. For a detailed description of each of the diagnostic tests, see the following subsections. Table 12 provides a summary of the diagnostic tests and their interpretations. All these diagnostics are available in the CQLIM, CNTSELECT, and SMC procedures.

Table 12: Convergence Diagnostic Tests Available in the Bayesian Procedures

Name Description Interpretation of the Test
Geweke Tests whether the mean estimates have converged by comparing means from the early and latter part of the Markov chain. Two-sided test based on a z-score statistic. Large absolute z values indicate rejection.
Heidelberger-Welch (stationarity test) Tests whether the Markov chain is a covariance (or weakly) stationary process. Failure could indicate that a longer Markov chain is needed. One-sided test based on a Cramér–von Mises statistic. Small p-values indicate rejection.
Heidelberger-Welch (half-width test) Reports whether the sample size is adequate to meet the required accuracy for the mean estimate. Failure could indicate that a longer Markov chain is needed. If a relative half-width statistic is greater than a predetermined accuracy measure, this indicates rejection.
Raftery-Lewis Evaluates the accuracy of the estimated (desired) percentiles by reporting the number of samples needed to reach the desired accuracy of the percentiles. Failure could indicate that a longer Markov chain is needed. If the total samples needed are fewer than the Markov chain sample, this indicates rejection.
Autocorrelation Measures dependency among Markov chain samples. High correlations between long lags indicate poor mixing.
Effective sample size Relates to autocorrelation; measures mixing of the Markov chain. Large discrepancy between the effective sample size and the simulation sample size indicates poor mixing.


Geweke Diagnostics

The Geweke test (Geweke 1992) compares values in the early part of the Markov chain to those in the latter part of the chain in order to detect failure of convergence. If the chain has converged, early and later parts of the chain should look similar. The statistic is constructed as follows. Two subsequences of the Markov chain StartSet theta Superscript t Baseline EndSet are taken out, with StartSet theta 1 Superscript t Baseline colon t equals 1 comma ellipsis comma n 1 EndSet and StartSet theta 2 Superscript t Baseline colon t equals n Subscript a Baseline comma ellipsis comma n EndSet, where 1 less-than n 1 less-than n Subscript a Baseline less-than n. The first subsequence is called the “first window,” and the second sequence is called the “second window.” Let n 2 equals n minus n Subscript a Baseline plus 1 denote the length of the second window, and define the means of the two windows as

theta overbar Subscript 1 Baseline equals StartFraction 1 Over n 1 EndFraction sigma-summation Underscript t equals 1 Overscript n 1 Endscripts theta Superscript t Baseline and theta overbar Subscript 2 Baseline equals StartFraction 1 Over n 2 EndFraction sigma-summation Underscript t equals n Subscript a Baseline Overscript n Endscripts theta Superscript t

Let ModifyingAbove s With caret Subscript 1 Baseline left-parenthesis 0 right-parenthesis and ModifyingAbove s With caret Subscript 2 Baseline left-parenthesis 0 right-parenthesis denote consistent spectral density estimates at zero frequency (see the section Spectral Density Estimate at Zero Frequency for estimation details) for each window. If n 1 equals f 1 n and n 2 equals f 2 n, where the fractions 0 less-than f 1 less-than 1 and 0 less-than f 2 less-than 1 are fixed, f 1 plus f 2 less-than 1, and the chain is stationary, then the following statistic converges to a standard normal distribution as n right-arrow normal infinity:

upper Z Subscript n Baseline equals StartFraction theta overbar Subscript 1 Baseline minus theta 2 overbar Over StartRoot StartFraction ModifyingAbove s With caret Subscript 1 Baseline left-parenthesis 0 right-parenthesis Over n 1 EndFraction plus StartFraction ModifyingAbove s With caret Subscript 2 Baseline left-parenthesis 0 right-parenthesis Over n 2 EndFraction EndRoot EndFraction

This is a two-sided test, and the p-value is computed as upper P left-parenthesis upper X greater-than StartAbsoluteValue upper Z Subscript n Baseline EndAbsoluteValue right-parenthesis, where X is a standard normal distribution. A p-value less than alpha indicates a rejection of the null hypothesis that the first window of the chain and the second window of the chain come from the same distribution. If the null hypothesis is rejected, the Markov chain has not yet converged.

Spectral Density Estimate at Zero Frequency

For one sequence of the Markov chain StartSet theta Subscript t Baseline EndSet, the relationship between the h-lag covariance sequence of a time series and the spectral density, f, is

s Subscript h Baseline equals StartFraction 1 Over 2 pi EndFraction integral Subscript negative pi Superscript pi Baseline exp left-parenthesis sans-serif i omega h right-parenthesis f left-parenthesis omega right-parenthesis d omega

where i indicates that omega h is the complex argument. Inverting this Fourier integral,

f left-parenthesis omega right-parenthesis equals sigma-summation Underscript h equals negative normal infinity Overscript normal infinity Endscripts s Subscript h Baseline exp left-parenthesis minus sans-serif i omega h right-parenthesis equals s 0 left-parenthesis 1 plus 2 sigma-summation Underscript h equals 1 Overscript normal infinity Endscripts rho Subscript h Baseline cosine left-parenthesis omega h right-parenthesis right-parenthesis

It follows that

f left-parenthesis 0 right-parenthesis equals sigma squared left-parenthesis 1 plus 2 sigma-summation Underscript h equals 1 Overscript normal infinity Endscripts rho Subscript h Baseline right-parenthesis

which gives an autocorrelation adjusted estimate of the variance. In this equation, sigma squared is the naive variance estimate of the sequence StartSet theta Subscript t Baseline EndSet and rho Subscript h is the lag h autocorrelation. Due to obvious computational difficulties, such as calculation of autocorrelation at infinity, you cannot effectively estimate f left-parenthesis 0 right-parenthesis by using the preceding formula. The usual route is to first obtain the periodogram p left-parenthesis omega right-parenthesis of the sequence, and then estimate f left-parenthesis 0 right-parenthesis by smoothing the estimated periodogram. The periodogram is defined to be

p left-parenthesis omega right-parenthesis equals StartFraction 1 Over n EndFraction left-bracket left-parenthesis sigma-summation Underscript t equals 1 Overscript n Endscripts theta Subscript t Baseline sine left-parenthesis omega t right-parenthesis right-parenthesis squared plus left-parenthesis sigma-summation Underscript t equals 1 Overscript n Endscripts theta Subscript t Baseline cosine left-parenthesis omega t right-parenthesis right-parenthesis squared right-bracket

The procedures use the following way to estimate ModifyingAbove f With caret left-parenthesis 0 right-parenthesis from p (Heidelberger and Welch 1981). In p left-parenthesis omega right-parenthesis, let omega equals omega Subscript k Baseline equals 2 pi k slash n and k equals 1 comma ellipsis comma left-bracket StartFraction n Over 2 EndFraction right-bracket.[2] A smooth spectral density in the domain of left-parenthesis 0 comma pi right-bracket is obtained by fitting a gamma model with the log link function, using p left-parenthesis omega Subscript k Baseline right-parenthesis as response and x 1 left-parenthesis omega Subscript k Baseline right-parenthesis equals StartRoot 3 EndRoot left-parenthesis 4 omega Subscript k Baseline slash left-parenthesis 2 pi right-parenthesis minus 1 right-parenthesis as the only regressor. The predicted value ModifyingAbove f With caret left-parenthesis 0 right-parenthesis is given by

ModifyingAbove f With caret left-parenthesis 0 right-parenthesis equals exp left-parenthesis ModifyingAbove beta With caret Subscript 0 Baseline minus StartRoot 3 EndRoot ModifyingAbove beta With caret Subscript 1 Baseline right-parenthesis

where ModifyingAbove beta With caret Subscript 0 and ModifyingAbove beta With caret Subscript 1 are the estimates of the intercept and slope parameters, respectively.

Heidelberger-Welch Diagnostics

The Heidelberger-Welch test (Heidelberger and Welch 1981, 1983) consists of two parts: a stationary test and a half-width test. The stationarity test assesses the stationarity of a Markov chain by testing the hypothesis that the chain comes from a covariance stationary process. The half-width test checks whether the Markov chain sample size is adequate to estimate the mean values accurately.

Given StartSet theta Superscript t Baseline EndSet, set upper S 0 equals 0, upper S Subscript n Baseline equals sigma-summation Underscript t equals 1 Overscript n Endscripts theta Superscript t, and theta overbar equals left-parenthesis 1 slash n right-parenthesis sigma-summation Underscript t equals 1 Overscript n Endscripts theta Superscript t. You can construct the following sequence with s coordinates on values from StartFraction 1 Over n EndFraction comma StartFraction 2 Over n EndFraction comma ellipsis comma 1:

upper B Subscript n Baseline left-parenthesis s right-parenthesis equals left-parenthesis upper S Subscript left-bracket n s right-bracket Baseline minus left-bracket n s right-bracket theta overbar right-parenthesis slash left-parenthesis n ModifyingAbove p With caret left-parenthesis 0 right-parenthesis right-parenthesis Superscript 1 slash 2

where left-bracket right-bracket is the rounding operator and ModifyingAbove p With caret left-parenthesis 0 right-parenthesis is an estimate of the spectral density at zero frequency that uses the second half of the sequence (see the section Spectral Density Estimate at Zero Frequency for estimation details). For large n, upper B Subscript n converges in distribution to a Brownian bridge (Billingsley 1986). So you can construct a test statistic by using upper B Subscript n. The statistic that these procedures use is the Cramér–von Mises statistic;[3] that is, integral Subscript 0 Superscript 1 Baseline upper B Subscript n Baseline left-parenthesis s right-parenthesis squared d s equals normal upper C normal upper V normal upper M left-parenthesis upper B Subscript n Baseline right-parenthesis. As n right-arrow normal infinity, the statistic converges in distribution to a standard Cramér–von Mises distribution. The integral integral Subscript 0 Superscript 1 Baseline upper B Subscript n Baseline left-parenthesis s right-parenthesis squared d s is numerically approximated using Simpson’s rule.

Let y Subscript i Baseline equals upper B Subscript n Baseline left-parenthesis s right-parenthesis squared, where s equals 0 comma StartFraction 1 Over n EndFraction comma ellipsis comma StartFraction n minus 1 Over n EndFraction comma 1 and i equals n s equals 0 comma 1 comma ellipsis comma n. If n is even, let m equals n slash 2; otherwise, let m equals left-parenthesis n minus 1 right-parenthesis slash 2. The Simpson’s approximation to the integral is

integral Subscript 0 Superscript 1 Baseline upper B Subscript n Baseline left-parenthesis s right-parenthesis squared d s almost-equals StartFraction 1 Over 3 n EndFraction left-bracket y 0 plus 4 left-parenthesis y 1 plus midline-horizontal-ellipsis plus y Subscript 2 m minus 1 Baseline right-parenthesis plus 2 left-parenthesis y 2 plus midline-horizontal-ellipsis plus y Subscript 2 m minus 2 Baseline right-parenthesis plus y Subscript 2 m Baseline right-bracket

Note that Simpson’s rule requires an even number of intervals. When n is odd, y Subscript n is set to 0 and the value does not contribute to the approximation.

This is a one-sided test, and the p-value is computed as upper P left-parenthesis upper X greater-than normal upper C normal upper V normal upper M left-parenthesis upper B Subscript n Baseline right-parenthesis right-parenthesis, where X has a standard Cramér–von Mises distribution. A p-value less than alpha indicates rejection of the null hypothesis that the chain is stationary. This test can be performed repeatedly on the same chain, and it helps you identify a time t when the chain has reached stationarity. The whole chain, StartSet theta Superscript t Baseline EndSet, is first used to construct the Cramér–von Mises statistic. If it passes the test, you can conclude that the entire chain is stationary. If it fails the test, you drop the initial 10 percent-sign of the chain and redo the test by using the remaining 90 percent-sign. This process is repeated until either a time t is selected or it reaches a point where there are not enough data remaining to construct a confidence interval (the cutoff proportion is set to 50 percent-sign).

The part of the chain that is deemed stationary is put through a half-width test, which reports whether the sample size is adequate to meet certain accuracy requirements for the mean estimates. Running the simulation less than this length of time would not meet the requirement, whereas running it longer would not provide any additional information that is needed. The statistic that is calculated here is the relative half-width (RHW) of the confidence interval. The RHW for a confidence interval of level 1 minus alpha is

normal upper R normal upper H normal upper W equals StartFraction z Subscript left-parenthesis 1 minus alpha slash 2 right-parenthesis Baseline dot left-parenthesis ModifyingAbove s With caret Subscript n Baseline slash n right-parenthesis Superscript 1 slash 2 Baseline Over ModifyingAbove theta With caret EndFraction

where z Subscript left-parenthesis 1 minus alpha slash 2 right-parenthesis is the z-score of the 100 left-parenthesis 1 minus alpha slash 2 right-parenthesisth percentile (for example, z Subscript left-parenthesis 1 minus alpha slash 2 right-parenthesis Baseline equals 1.96 if alpha equals 0.05), ModifyingAbove s With caret Subscript n is the variance of the chain estimated using the spectral density method (see the explanation in the section Spectral Density Estimate at Zero Frequency), n is the length, and ModifyingAbove theta With caret is the estimated mean. The RHW quantifies accuracy of the 1 minus alpha level confidence interval of the mean estimate by measuring the ratio between the sample standard error of the mean and the mean itself. The test assumes that you can stop the Markov chain if the variability of the mean stabilizes with respect to the mean—in other words, if the RHW is small enough. An implicit assumption is that large means are often accompanied by large variances. If this assumption is not met, then this test can produce false rejections (such as a small mean around 0 and large standard deviation) or false acceptance (such as a very large mean with relative small variance). As with any other convergence diagnostics, you might want to exercise caution in interpreting the results.

To perform the stationarity test, you need to select an alpha level (the default is 0.05). To perform the half-width test, you need to select another alpha level (again, the default is 0.05) and a predetermined tolerance value epsilon (the default is 0.1). If the calculated RHW is greater than epsilon, you conclude that there are not enough data to accurately estimate the mean with 1 minus alpha confidence under a tolerance of epsilon.

Raftery-Lewis Diagnostics

If your interest lies in posterior percentiles, you want a diagnostic test that evaluates the accuracy of the estimated percentiles. The Raftery-Lewis test (Raftery and Lewis 1992, 1995) is designed for this purpose. The Raftery-Lewis test evaluates the accuracy of a quantile estimate ModifyingAbove theta With caret Subscript q of order q element-of left-parenthesis 0 comma 1 right-parenthesis. In particular, it determines the number of MCMC iterations, M, that need to be discarded (burn-ins) and the number of iterations that are needed, N, in order to achieve a desired level of precision in the estimate ModifyingAbove theta With caret Subscript q. Details follow. Notation and deductions here closely resemble those in Raftery and Lewis (1995).

The quantile theta Subscript q is defined such that upper P left-parenthesis theta less-than-or-equal-to theta Subscript q Baseline vertical-bar bold y right-parenthesis equals q, where q can be an arbitrary cumulative probability, such as 0.025. This theta Subscript q can be empirically estimated by finding the 100nqth number of the sorted StartSet theta Superscript t Baseline EndSet. Let ModifyingAbove theta With caret Subscript q denote the estimand, which corresponds to an estimated probability upper P left-parenthesis theta less-than-or-equal-to ModifyingAbove theta With caret Subscript q Baseline right-parenthesis equals ModifyingAbove upper P With caret Subscript q. Because the simulated posterior distribution converges to the true distribution as the simulation sample size grows, ModifyingAbove theta With caret Subscript q can achieve any degree of accuracy if the simulator is run for a very long time. However, running a simulation for too long can be wasteful. Alternatively, you can use coverage probability to measure accuracy and stop the chain when a certain accuracy is reached.

A stopping criterion is reached when the estimated probability is within plus-or-minus r of the true cumulative probability q, with probability s, such as upper P left-parenthesis ModifyingAbove upper P With caret Subscript q Baseline element-of left-parenthesis q minus r comma q plus r right-parenthesis right-parenthesis equals s. For example, suppose you want the coverage probability s to be 0.95 and the amount of tolerance r to be 0.005. This corresponds to requiring that the estimate of the cumulative distribution function of the 2.5th percentile be estimated to within plus-or-minus 0.5 percentage points with probability 0.95. In order to perform the diagnostic, a value epsilon must be chosen for the tolerance level of a stationary test, described in the following paragraphs. For example, epsilon equals 0.001.

The Raftery-Lewis diagnostic test finds the number of iterations, M, that need to be discarded (burn-ins) and the number of iterations that are needed, N, in order to achieve a desired precision. Given a predefined cumulative probability q, these procedures first find ModifyingAbove theta With caret Subscript q, and then they construct a binary 0 minus 1 process StartSet upper Z Subscript t Baseline EndSet by setting upper Z Subscript t Baseline equals 1 if theta Superscript t Baseline less-than-or-equal-to ModifyingAbove theta With caret Subscript q and 0 otherwise for all t. The sequence StartSet upper Z Subscript t Baseline EndSet is itself not a Markov chain, but you can construct a subsequence of StartSet upper Z Subscript t Baseline EndSet that is approximately Markovian if it is sufficiently k-thinned. When k becomes reasonably large, StartSet upper Z Subscript t Superscript left-parenthesis k right-parenthesis Baseline EndSet starts to behave like a Markov chain.

Next, the procedures find this thinning parameter k. The number k is estimated by comparing the Bayesian information criterion (BIC) between two Markov models: a first-order and a second-order Markov model. A jth-order Markov model is one in which the current value of StartSet upper Z Subscript t Superscript left-parenthesis k right-parenthesis Baseline EndSet depends on the previous j values. For example, in a second-order Markov model,

StartLayout 1st Row 1st Column upper P left-parenthesis upper Z Subscript t Superscript left-parenthesis k right-parenthesis Baseline equals z Subscript t Baseline vertical-bar upper Z Subscript t minus 1 Superscript left-parenthesis k right-parenthesis Baseline equals z Subscript t minus 1 Baseline comma upper Z Subscript t minus 2 Superscript left-parenthesis k right-parenthesis Baseline equals z Subscript t minus 2 Baseline comma ellipsis comma upper Z 0 Superscript left-parenthesis k right-parenthesis Baseline equals z 0 right-parenthesis 2nd Row 1st Column Blank 2nd Column equals 3rd Column upper P left-parenthesis upper Z Subscript t Superscript left-parenthesis k right-parenthesis Baseline equals z Subscript t Baseline vertical-bar upper Z Subscript t minus 1 Superscript left-parenthesis k right-parenthesis Baseline equals z Subscript t minus 1 Baseline comma upper Z Subscript t minus 2 Superscript left-parenthesis k right-parenthesis Baseline equals z Subscript t minus 2 Baseline right-parenthesis EndLayout

where z Subscript i Baseline equals StartSet 0 comma 1 EndSet comma i equals 0 comma ellipsis comma t. Given StartSet upper Z Subscript t Superscript left-parenthesis k right-parenthesis Baseline EndSet, you can construct two transition count matrices for a second-order Markov model:

z Subscript t Baseline equals 0 z Subscript t Baseline equals 1
z Subscript t minus 1 Baseline equals 0 z Subscript t minus 1 Baseline equals 1 z Subscript t minus 1 Baseline equals 0 z Subscript t minus 1 Baseline equals 1
z Subscript t minus 2 Baseline equals 0 w 000 w 010 z Subscript t minus 2 Baseline equals 0 w 001 w 011
z Subscript t minus 2 Baseline equals 1 w 100 w 110 z Subscript t minus 2 Baseline equals 1 w 101 w 111

For each k, the procedures calculate the BIC that compares the two Markov models. The BIC is based on a likelihood ratio test statistic that is defined as

upper G Subscript k Superscript 2 Baseline equals 2 sigma-summation Underscript i equals 0 Overscript 1 Endscripts sigma-summation Underscript j equals 0 Overscript 1 Endscripts sigma-summation Underscript l equals 0 Overscript 1 Endscripts w Subscript i j l Baseline log StartFraction w Subscript i j l Baseline Over ModifyingAbove w With caret Subscript i j l Baseline EndFraction

where ModifyingAbove w With caret Subscript i j l is the expected cell count of w Subscript i j l under the null model, the first-order Markov model, where the assumption left-parenthesis upper Z Subscript t Superscript left-parenthesis k right-parenthesis Baseline up-tack upper Z Subscript t minus 2 Superscript left-parenthesis k right-parenthesis Baseline right-parenthesis vertical-bar upper Z Subscript t minus 1 Superscript left-parenthesis k right-parenthesis holds. The formula for the expected cell count is

ModifyingAbove w With caret Subscript i j l Baseline equals StartFraction sigma-summation Underscript i Endscripts w Subscript i j l Baseline dot sigma-summation Underscript l Endscripts w Subscript i j l Baseline Over sigma-summation Underscript i Endscripts sigma-summation Underscript l Endscripts w Subscript i j l Baseline EndFraction

The BIC is upper G Subscript k Superscript 2 Baseline minus 2 log left-parenthesis n Subscript k Baseline minus 2 right-parenthesis, where n Subscript k is the k-thinned sample size (every kth sample, starting with the first), with the last two data points discarded because of the construction of the second-order Markov model. The thinning parameter k is the smallest k for which the BIC is negative. When k is found, you can estimate a transition probability matrix between state 0 and state 1 for StartSet upper Z Subscript t Superscript left-parenthesis k right-parenthesis Baseline EndSet:

upper Q equals Start 2 By 2 Matrix 1st Row 1st Column 1 minus alpha 2nd Column alpha 2nd Row 1st Column beta 2nd Column 1 minus beta EndMatrix

Because StartSet upper Z Subscript t Superscript left-parenthesis k right-parenthesis Baseline EndSet is a Markov chain, its equilibrium distribution exists and is estimated by

pi equals left-parenthesis pi 0 comma pi 1 right-parenthesis equals StartFraction left-parenthesis beta comma alpha right-parenthesis Over alpha plus beta EndFraction

where pi 0 equals upper P left-parenthesis theta less-than-or-equal-to theta Subscript q Baseline vertical-bar bold y right-parenthesis and pi 1 equals 1 minus pi 0. The goal is to find an iteration number m such that after m steps, the estimated transition probability upper P left-parenthesis upper Z Subscript m Superscript left-parenthesis k right-parenthesis Baseline equals i vertical-bar upper Z 0 Superscript left-parenthesis k right-parenthesis Baseline equals j right-parenthesis is within epsilon of equilibrium pi Subscript i for i comma j equals 0 comma 1. Let e 0 equals left-parenthesis 1 comma 0 right-parenthesis and e 1 equals 1 minus e 0. The estimated transition probability after step m is

upper P left-parenthesis upper Z Subscript m Superscript left-parenthesis k right-parenthesis Baseline equals i vertical-bar upper Z 0 Superscript left-parenthesis k right-parenthesis Baseline equals j right-parenthesis equals e Subscript j Baseline left-bracket Start 2 By 2 Matrix 1st Row 1st Column pi 0 2nd Column pi 1 2nd Row 1st Column pi 0 2nd Column pi 1 EndMatrix plus StartFraction left-parenthesis 1 minus alpha minus beta right-parenthesis Superscript m Baseline Over alpha plus beta EndFraction Start 2 By 2 Matrix 1st Row 1st Column alpha 2nd Column negative alpha 2nd Row 1st Column negative beta 2nd Column beta EndMatrix right-bracket e prime Subscript j

which holds when

m equals StartStartFraction log left-parenthesis StartFraction left-parenthesis alpha plus beta right-parenthesis epsilon Over max left-parenthesis alpha comma beta right-parenthesis EndFraction right-parenthesis OverOver log left-parenthesis 1 minus alpha minus beta right-parenthesis EndEndFraction

assuming 1 minus alpha minus beta greater-than 0.

Therefore, by time m, StartSet upper Z Subscript t Superscript left-parenthesis k right-parenthesis Baseline EndSet is sufficiently close to its equilibrium distribution, and you know that a total size of upper M equals m k should be discarded as the burn-in.

Next, the procedures estimate N, the number of simulations that are needed in order to achieve the desired accuracy in percentile estimation. The estimate of upper P left-parenthesis theta less-than-or-equal-to theta Subscript q Baseline vertical-bar bold y right-parenthesis is upper Z overbar Subscript n Superscript left-parenthesis k right-parenthesis Baseline equals StartFraction 1 Over n EndFraction sigma-summation Underscript t equals 1 Overscript n Endscripts upper Z Subscript t Superscript left-parenthesis k right-parenthesis. For large n, upper Z overbar Subscript n Superscript left-parenthesis k right-parenthesis is normally distributed with mean q, the true cumulative probability, and variance

StartFraction 1 Over n EndFraction StartFraction left-parenthesis 2 minus alpha minus beta right-parenthesis alpha beta Over left-parenthesis alpha plus beta right-parenthesis cubed EndFraction

upper P left-parenthesis q minus r less-than-or-equal-to upper Z overbar Subscript n Superscript left-parenthesis k right-parenthesis Baseline less-than-or-equal-to q plus r right-parenthesis equals s is satisfied if

n equals StartFraction left-parenthesis 2 minus alpha minus beta right-parenthesis alpha beta Over left-parenthesis alpha plus beta right-parenthesis cubed EndFraction StartSet StartStartFraction normal upper Phi Superscript negative 1 Baseline left-parenthesis StartFraction s plus 1 Over 2 EndFraction right-parenthesis OverOver r EndEndFraction EndSet squared

Therefore, upper N equals n k.

By using similar reasoning, the procedures first calculate the minimal number of iterations that are needed in order to achieve the desired accuracy, assuming that the samples are independent:

upper N Subscript min Baseline equals left-brace normal upper Phi Superscript negative 1 Baseline left-parenthesis StartFraction s plus 1 Over 2 EndFraction right-parenthesis right-brace squared StartFraction q left-parenthesis 1 minus q right-parenthesis Over r squared EndFraction

If StartSet theta Superscript t Baseline EndSet does not have that required sample size, the Raftery-Lewis test is not performed. If you still want to perform the test, increase the number of Markov chain iterations.

The ratio upper N slash upper N Subscript min is sometimes referred to as the dependence factor. It measures deviation from posterior sample independence: the closer it is to 1, the less correlated the samples are. There are a few things to keep in mind when you use this test. This diagnostic tool is specifically designed for the percentile of interest and does not provide information about convergence of the chain as a whole (Brooks and Roberts 1999). In addition, the test can be very sensitive to small changes. Both N and upper N Subscript min are inversely proportional to r squared, so you can expect to see large variations in these numbers with small changes to input variables, such as the desired coverage probability or the cumulative probability of interest. Finally, the time until convergence for a parameter can differ substantially for different cumulative probabilities.

Autocorrelations

The sample autocorrelation of lag h for a parameter theta is defined in terms of the sample autocovariance function:

ModifyingAbove rho With caret Subscript h Baseline left-parenthesis theta right-parenthesis equals StartFraction ModifyingAbove gamma With caret Subscript h Baseline left-parenthesis theta right-parenthesis Over ModifyingAbove gamma With caret Subscript 0 Baseline left-parenthesis theta right-parenthesis EndFraction comma StartAbsoluteValue h EndAbsoluteValue less-than n

The sample autocovariance function of lag h of theta is defined by

ModifyingAbove gamma With caret Subscript h Baseline left-parenthesis theta right-parenthesis equals StartFraction 1 Over n minus h EndFraction sigma-summation Underscript t equals 1 Overscript n minus h Endscripts left-parenthesis theta Superscript t plus h Baseline minus theta overbar right-parenthesis left-parenthesis theta Superscript t Baseline minus theta overbar right-parenthesis comma 0 less-than-or-equal-to h less-than n
Effective Sample Size

You can use autocorrelation and trace plots to examine the mixing of a Markov chain. A closely related measure of mixing is the effective sample size (ESS) (Kass et al. 1998). ESS can be interpreted as the equivalent number of independent draws from the posterior distribution that the Markov chain represents.

ESS is defined as

normal upper E normal upper S normal upper S equals StartFraction n Over tau EndFraction equals StartFraction n Over 1 plus 2 sigma-summation Underscript k equals 1 Overscript normal infinity Endscripts rho Subscript k Baseline left-parenthesis theta right-parenthesis EndFraction

where n is the total sample size and rho Subscript k Baseline left-parenthesis theta right-parenthesis is the autocorrelation of lag k for theta. The quantity tau is referred to as the autocorrelation time. To estimate tau, the Bayesian procedures first find a cutoff point k after which the autocorrelations are very close to zero, and then sum all the rho Subscript k up to that point. The cutoff point k is such that StartAbsoluteValue rho Subscript k Baseline EndAbsoluteValue less-than min StartSet 0.01 comma 2 s Subscript k Baseline EndSet, where s Subscript k is the estimated standard deviation:

s Subscript k Baseline equals StartRoot left-parenthesis StartFraction 1 Over n EndFraction left-parenthesis 1 plus 2 sigma-summation Underscript j equals 1 Overscript k minus 1 Endscripts ModifyingAbove rho With caret Subscript j Superscript 2 Baseline left-parenthesis theta right-parenthesis right-parenthesis right-parenthesis EndRoot

ESS and tau are inversely proportional to each other, and low ESS or high tau indicates bad mixing of the Markov chain.

ESS is costly to compute when the Markov chain is highly autocorrelated because it requires so many autocorrelation lags to be computed first. To remedy this problem, you can specify the cutoff point to be no larger than some maximum lag. In the case where more than the maximum number of lags would be required, this reduces computational cost but results in poor-quality estimates of ESS and tau. However, when the maximum lag is set high enough, this problem occurs only when the Markov chain is mixing very poorly, which is precisely the issue that ESS and tau are meant to diagnose.



[2] This is equivalent to the fast Fourier transformation of the original time series theta Subscript t.

[3] The von Mises distribution was first introduced by von Mises (1918). The density function is pi left-parenthesis theta vertical-bar mu kappa right-parenthesis tilde upper M left-parenthesis mu comma kappa right-parenthesis equals left-bracket 2 pi upper I 0 left-parenthesis kappa right-parenthesis right-bracket Superscript negative 1 Baseline exp left-parenthesis kappa cosine left-parenthesis theta minus mu right-parenthesis right-parenthesis left-parenthesis 0 less-than-or-equal-to theta less-than-or-equal-to 2 pi right-parenthesis, where the function upper I 0 left-parenthesis kappa right-parenthesis is the modified Bessel function of the first kind and order zero, defined by upper I 0 left-parenthesis kappa right-parenthesis equals left-parenthesis 2 pi right-parenthesis Superscript negative 1 Baseline integral Subscript 0 Superscript 2 pi Baseline exp left-parenthesis kappa cosine left-parenthesis theta minus mu right-parenthesis right-parenthesis d theta.

Last updated: July 09, 2026