Overview of Gelman-Rubin Statistics
The Gelman-Rubin statistic (or Gelman-Rubin diagnostic, Gelman-Rubin statistical test) is a statistical method for diagnosing convergence of Markov chain Monte Carlo (MCMC) sampling methods, particularly when MCMC sampling is done with multiple chains, where each chain will be used to evaluate whether they are sampled from the same distribution. This technique is often used in the context of Bayesian statistics.
Specifically, the Gelman-Rubin statistic evaluates the ratio between the variability of samples from multiple MCMC chains and the variability within each chain, and this ratio will be close to 1 if statistical convergence is achieved.
The Gelman-Rubin statistic (usually expressed as R) is calculated as follows
1. calculate the average of the parameters within each chain
2. compute the variance of the parameter within each chain
3. compute the variance of the mean within each chain
4. calculate the variance between the mean of the parameters within each chain and the overall mean.
Using the results of these calculations, the Gelman-Rubin statistic R is defined as follows.
\[ R = \sqrt{\frac{\text{Variance of Mean}}{\text{Parameter variance within each chain}}} \]
The closer R is to 1, the more likely it is that samples from different chains are sampled from the same distribution; typically, if R is less than 1.1, it is considered convergent, but this threshold may vary by study and context.
The Gelman-Rubin statistic is widely used to confirm convergence of MCMC sampling and is an important feature in statistical modeling, especially for Bayesian statistics and Monte Carlo methods.
Algorithm for the Gelman-Rubin statistic
The following is the basic algorithmic procedure for computing the Gelman-Rubin statistics.
1. Initialization: Start each MCMC chain with a different initial value.
2. Sampling: Perform MCMC sampling on each chain to generate the desired number of iterations (samples).
3. statistical computation within each chain:
- Compute the mean of the parameters within each chain.
- Compute the variance of the parameters within each chain.
4. overall statistical computation:
- Compute the overall mean. This will be the average of the samples obtained from all chains.
- Compute the overall variance. This will be the variance of the entire sample obtained from all chains.
5. compute the Gelman-Rubin statistic:
- Compute the variance between chains (variance of the mean of each chain).
- Compute the within-chain variance (the mean of the variances of the parameters within each chain).
- The Gelman-Rubin statistic \( R \) is computed as follows
\[ R = \sqrt{\frac{\text{Total variance}}{\text{Variance in chain}}}\]
6. evaluation of convergence:
- The value of the statistic \( R \) is a measure of convergence. Normally, convergence is considered to have occurred if \( R \) is less than 1.1. 7.
7. What to do if convergence is not achieved:
- If convergence is not achieved, measures must be taken, such as adjusting the MCMC parameters and initial values and retrying.
This algorithm is a method of checking convergence using multiple chains and is one of the key tools to ensure that appropriate results are obtained in MCMC sampling.
Application of the Gelman-Rubin statistic
The Gelman-Rubin statistic is primarily used in Bayesian statistical modeling to evaluate the convergence of MCMC sampling. The following sections describe specific cases where the Gelman-Rubin statistic is applied.
1. Bayesian Statistical Modeling:
MCMC sampling is widely used in Bayesian statistics to estimate the prior distribution and the posterior distribution from the data, and the Gelman-Rubin statistic can be useful to check the convergence of Bayesian models using multiple MCMC chains.
2. parameter estimation:
In Bayesian modeling, the goal is to obtain the posterior distribution of the parameter of interest, and it is common to estimate the same parameter using several independent MCMC chains and check their convergence with the Gelman-Rubin statistic.
3. hierarchical Bayesian model:
In a hierarchical Bayesian model, parameters are stratified at several levels, and the Gelman-Rubin statistic can be useful to check for convergence of parameters at different levels.
4. model diagnostics and tuning:
MCMC sampling may not converge, and if the Gelman-Rubin statistic does not converge to 1, it suggests that the sampling algorithm, initial values, etc. need to be adjusted. This will diagnose and tune the model.
5. other applications of the Monte Carlo method:
The Gelman-Rubin statistic can be applied to other Monte Carlo methods where MCMC sampling is used. For example, it may be used to evaluate the convergence of a Markov chain.
Example implementation of an algorithm using the Gelman-Rubin statistic
An example implementation using Python and NumPy to compute the Gelman-Rubin statistic is shown.
import numpy as np
def gelman_rubin_diagnostic(chains):
"""
Function to compute Gelman-Rubin statistics
Parameters:
chains (list of numpy arrays): Samples obtained from multiple MCMC chains
Returns:
float: Gelman-Rubin statistics
"""
num_chains = len(chains)
chain_length = len(chains[0])
# Calculate the average of the parameters in each chain
chain_means = [np.mean(chain, axis=0) for chain in chains]
# Calculate the variance of parameters within each chain
chain_variances = [np.var(chain, axis=0, ddof=1) for chain in chains]
# Calculate average for entire chain
overall_mean = np.mean(chain_means, axis=0)
# Calculate the variance of the entire chain
overall_variance = np.mean([np.var(chain_means[i], ddof=1) for i in range(num_chains)], axis=0)
# Dispersion among chains
between_chain_variance = chain_length * np.var(chain_means, axis=0, ddof=1)
# Compute Gelman-Rubin statistics
R = np.sqrt((overall_variance + between_chain_variance) / overall_variance)
return R
# Example Usage
# Hypothetical sample data consisting of three chains
chain1 = np.random.normal(loc=0, scale=1, size=1000)
chain2 = np.random.normal(loc=0, scale=1, size=1000)
chain3 = np.random.normal(loc=0.2, scale=1, size=1000)
# Compile each chain as a list
chains = [chain1, chain2, chain3]
# Compute Gelman-Rubin statistics
R_statistic = gelman_rubin_diagnostic(chains)
print("Gelman-Rubin statistic:", R_statistic)
In this example, sample data consisting of three MCMC chains are generated, and these chains are passed as a list to the gelman_rubin_diagnostic function to calculate the Gelman-Rubin statistic, and if the calculated statistic is close to 1, convergence has been achieved.
Challenges of Algorithms Using Gelman-Rubin Statistics and How to Address Them
Although the Gelman-Rubin statistic is one of the useful convergence diagnostics, there are some challenges and points to keep in mind in its computation. The following are some of the issues and their countermeasures.
1. effect of sample size:
Challenge: A small sample size may reduce the validity of the Gelman-Rubin statistic. This is particularly problematic in high-dimensional parameter spaces.
Solution: If possible, the best course of action is to obtain more samples. However, if the computational cost is high, other convergence diagnostics methods may be used in conjunction or sampling methods may be devised to mitigate the problem.
2. selection of appropriate initial values:
Challenge: The choice of initial values can affect the results. Inappropriate initial values may lead to incorrect convergence decisions.
Solution: It is recommended to start multiple chains with different initial values and check for statistical convergence. The choice of a sampling technique that is not sensitive to initial value selection should also be considered.
3. non-independent sampling:
Challenge: In MCMC sampling, the Gelman-Rubin statistic may not work effectively if the samples obtained are interdependent.
Solution: Review sampling methods and models and try to improve them to reduce interdependence, or consider other convergent diagnostic methods.
4. impact of outliers:
Challenge: Outliers may affect the results. When outliers are present, they affect the variance calculation and the convergence diagnostics output incorrect results.
Solution: To mitigate the impact of outliers, methods for outlier detection and removal could be incorporated, and the use of statistical methods that are robust to outliers could be considered.
Reference Information and Reference Books
For more information on optimization in machine learning, see also “Optimization for the First Time Reading Notes” “Sequential Optimization for Machine Learning” “Statistical Learning Theory” “Stochastic Optimization” etc.
Core Textbooks Directly Covering the Gelman–Rubin Statistic
Bayesian Data Analysis (3rd Edition)
Authors: Andrew Gelman, John B. Carlin, Hal S. Stern, Donald B. Rubin, Aki Vehtari
Publisher: Chapman & Hall/CRC
This is the definitive textbook on Bayesian statistics.
It introduces and explains MCMC methods and convergence diagnostics, including the Gelman–Rubin statistic (R̂ / PSRF), with both theoretical background and practical guidance.
Why it is important:
-
Written by the original developers of the Gelman–Rubin diagnostic
-
Clear explanation of between-chain vs within-chain variance
-
Includes modern extensions and practical recommendations
Handbook of Markov Chain Monte Carlo
Editors: Steve Brooks, Andrew Gelman, Galin L. Jones, Xiao-Li Meng
Publisher: Chapman & Hall/CRC
A comprehensive reference on MCMC theory, algorithms, and diagnostics.
Several chapters are dedicated to convergence assessment, including the Gelman–Rubin diagnostic and its limitations.
Why it is important:
-
Advanced, research-oriented treatment
-
Covers multiple convergence diagnostics and their comparisons
-
Discusses improvements and pitfalls of R̂
Supporting Textbooks on MCMC and Convergence
Monte Carlo Statistical Methods
Authors: Christian P. Robert, George Casella
Publisher: Springer
A classic text focusing on the theoretical foundations of Monte Carlo and MCMC methods.
While the Gelman–Rubin statistic is not the main focus, the book provides essential insight into convergence, ergodicity, and mixing, which are critical for understanding why diagnostics like R̂ are needed.
Markov Chains and Mixing Times
Authors: David A. Levin, Yuval Peres, Elizabeth L. Wilmer
Publisher: American Mathematical Society
A mathematically rigorous treatment of Markov chain convergence and mixing properties.
This book does not directly discuss the Gelman–Rubin statistic, but it provides the theoretical underpinning for MCMC convergence behavior.
Practitioner-Oriented Bayesian Modeling Books
Statistical Rethinking (2nd Edition)
Author: Richard McElreath
Publisher: Chapman & Hall/CRC
A modern, applied Bayesian modeling book using Stan.
The book explains MCMC diagnostics, including R̂, in a highly intuitive and practical manner.
Why it is useful:
-
Excellent conceptual explanation of convergence
-
Strong focus on interpretation rather than formulas
-
Widely used in applied Bayesian analysis
Author: John K. Kruschke
Publisher: Academic Press
An applied introduction to Bayesian inference with extensive discussion of MCMC diagnostics, including the Gelman–Rubin statistic.
Reference books include Optimization for Machine Learning

“Machine Learning, Optimization, and Data Science“
“Linear Algebra and Optimization for Machine Learning: A Textbook“
コメント