mcse: Compute Monte Carlo standard errors for expectations.

Description Usage Arguments Value References See Also Examples

View source: R/mcmcse.R

Description

Compute Monte Carlo standard errors for expectations.

Usage

1
mcse(x, size = NULL, g = NULL, r = 3,  method = "bm", warn = FALSE)

Arguments

x

a vector of values from a Markov chain of length n.

size

represents the batch size in “bm” and the truncation point in “bartlett” and “tukey”. Default is NULL which implies that an optimal batch size is calculated using the batchSize function. Can take character values of “sqroot” and “cuberoot” or any numeric value between 1 and n/2. “sqroot” means size is \lfloor n^{1/2} \rfloor and “cuberoot” means size is \lfloor n^{1/3} \rfloor.

g

a function such that E(g(x)) is the quantity of interest. The default is NULL, which causes the identity function to be used.

r

The lugsail parameters (r) that converts a lag window into its lugsail equivalent. Larger values of r will typically imply less underestimation of “cov”, but higher variability of the estimator. Default is r = 3 and r = 1,2 are also good choices, but will likely underestimation of variance. r > 5 is not recommended.

method

any of “bm”,“obm”,“bartlett”, “tukey”. “bm” represents batch means estimator, “obm” represents overlapping batch means estimator with, “bartlett” and “tukey” represents the modified-Bartlett window and the Tukey-Hanning windows for spectral variance estimators.

warn

a logical value indicating whether the function should issue a warning if the sample size is too small (less than 1,000).

Value

mcse returns a list with three elements:

est

an estimate of E(g(x)).

se

the Monte Carlo standard error.

nsim

The number of samples in the input Markov chain.

References

Flegal, J. M. (2012) Applicability of subsampling bootstrap methods in Markov chain Monte Carlo. In Wozniakowski, H. and Plaskota, L., editors, Monte Carlo and Quasi-Monte Carlo Methods 2010, pp. 363-372. Springer-Verlag.

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.

Flegal, J. M. and Jones, G. L. (2011) Implementing Markov chain Monte Carlo: Estimating with confidence. In Brooks, S., Gelman, A., Jones, G. L., and Meng, X., editors, Handbook of Markov Chain Monte Carlo, pages 175–197. Chapman & Hall/CRC Press.

Doss, C. R., Flegal, J. M., Jones, G. L., and Neath, R. C. (2014). Markov chain Monte Carlo estimation of quantiles. Electronic Journal of Statistics, 8, 2448-2478. Jones, G. L., Haran, M., Caffo, B. S. and Neath, R. (2006) Fixed-width output analysis for Markov chain Monte Carlo. Journal of the American Statistical Association, 101, 1537–154.

See Also

mcse.mat, which applies mcse to each column of a matrix or data frame.

mcse.multi, for a multivariate estimate of the Monte Carlo standard error.

mcse.q and mcse.q.mat, which compute standard errors for quantiles.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
## Bivariate Normal with mean (mu1, mu2) and covariance sigma
n <- 1e3
mu = c(2, 50)
sigma = matrix(c(1, 0.5, 0.5, 1), nrow = 2)
out = BVN_Gibbs(n, mu, sigma)
x = out[,1]
mcse(x)
mcse.q(x, 0.1)
mcse.q(x, 0.9)

# Estimate the mean, 0.1 quantile, and 0.9 quantile with MCSEs using overlapping batch means.

mcse(x, method = "obm")
mcse.q(x, 0.1, method = "obm")
mcse.q(x, 0.9, method = "obm")

# Estimate E(x^2) with MCSE using spectral methods.

g = function(x) { x^2 }
mcse(x, g = g, method = "tukey")

mcmcse documentation built on Sept. 9, 2021, 9:06 a.m.