n.eff {stableGR} | R Documentation |
Effective sample size
Description
For an estimator, effective sample size is the number of independent samples with the same standard error as a correlated sample. This function calculates effective sample size for a set of Markov chains using lugsail variance estimators. This also determines whether the Markov chains have converged. If they have not, this function approximates the number of samples needed.
Usage
n.eff(
x,
multivariate = TRUE,
epsilon = 0.05,
delta = NULL,
alpha = 0.05,
method = "lug",
size = NULL,
autoburnin = FALSE
)
Arguments
x |
a list of matrices, where each matrix represents one Markov chain sample. Each row of the matrices represents one step of the chain. Each column of the matrices represents one variable. A list with a single matrix (chain) is allowed. Optionally, this can be an |
multivariate |
a logical flag indicating whether the effective sample size should be calculated for multivariate chains. |
epsilon |
relative precision level. Values less than .10 are recommended. |
delta |
desired delta value - the cutoff for potential scale reduction factor. |
alpha |
significance level for confidence regions for the Monte Carlo estimators. |
method |
the method used to compute the standard error of the chains. This is one of “ |
size |
options are |
autoburnin |
a logical flag indicating whether only the second half of the series should be used in the computation. If set to TRUE and |
Value
n.eff |
a scalar point estimate of the effective sample size. |
converged |
a logical indicating whether sufficient samples have been obtained. |
n.target |
NULL (if |
References
Vats, D. and Knudson, C. Revisiting the Gelman-Rubin Diagnostic. arXiv:1812.09384.
Vats, D. and Flegal, J. Lugsail lag windows and their application to MCMC. arXiv: 1809.04541.
Flegal, J. M. and Jones, G. L. (2010) Batch means and spectral variance estimators in Markov chain Monte Carlo. The Annals of Statistics, 38, 1034–1070.
Gelman, A and Rubin, DB (1992) Inference from iterative simulation using multiple sequences, Statistical Science, 7, 457-511.
Brooks, SP. and Gelman, A. (1998) General methods for monitoring convergence of iterative simulations. Journal of Computational and Graphical Statistics, 7, 434-455.
Examples
library(stableGR)
set.seed(100)
p <- 2
n <- 100 # n is tiny here purely for demo purposes.
# use n much larger for real problems!
sig.mat = matrix(c(1, .8, .8, 1), ncol = 2, nrow = 2)
# Making 3 chains
chain1 <- mvn.gibbs(N = n, p = p, mu = rep(1,p), sigma = sig.mat)
chain2 <- mvn.gibbs(N = n, p = p, mu = rep(1,p), sigma = sig.mat)
chain3 <- mvn.gibbs(N = n, p = p, mu = rep(1,p), sigma = sig.mat)
# find ESS using all three chains
x <- list(chain1, chain2, chain3)
n.eff(x)