Learn R Programming

mcmcse (version 0.1)

mcse: Monte Carlo standard errors in MCMC

Description

mcse and mcse.q calculate standard errors in Markov chain Monte Carlo settings for expectations and quantiles, respectively.

Usage

mcse(vals, bs = "sqroot", g = NULL, meth = "BM", warn = FALSE)

mcse.q(vals, qval, bs = "sqroot", g = NULL, meth = "BM", warn = FALSE)

Arguments

vals
A vector of values from a Markov chain of length $N$.
qval
The quantile of interest when using mcse.q.
bs
The batch size used for the calculation (equal to the truncation point or subsampling size). The default value of sqroot uses $\sqrt{N}$.
g
A function g for mcse returns an estimate of $E(g(x))$ with an estimate of the MCSE and mcse.q returns an estimate of the qth quantile of the univariate distribution function of $g(x)$ with an estimate of the MCSE.
meth
Specifies the method used in calculating the MCSE. mcse contains options for "BM" (batch means), "OBM" (overlapping batch means), "TukeyHanning" (spectral variance methods with a Tukey-Hanning window),
warn
Provides a warning if the chain length is less than 1000.

Value

  • mcse and mcse.q return a list with the requested estimate (expectation or quantile) and corresponding MCSE.
  • $estExpectation or quantile estimate of interest.
  • $seMonte Carlo standard error.

References

Flegal, J. M. (2012). Applicability of subsampling bootstrap methods in {M}arkov chain {M}onte {C}arlo. In Wozniakowski, H. and Plaskota, L., editors, Monte Carlo and Quasi-Monte Carlo Methods 2010 (to appear). Springer-Verlag.

Flegal, J. M. and Jones, G. L. (2010). Batch means and spectral variance estimators in {M}arkov chain {M}onte {C}arlo. The Annals of Statistics, 38:1034--1070.

Flegal, J. M. and Jones, G. L. (2011). Implementing {M}arkov chain {M}onte {C}arlo: Estimating with confidence. In Brooks, S., Gelman, A., Jones, G., and Meng, X., editors, Handbook of {M}arkov Chain {M}onte {C}arlo, pages 175--197. Chapman & Hall/CRC Press.

Flegal, J. M., Jones, G. L., and Neath, R. (2012). Quantile Estimation via {M}arkov chain {M}onte {C}arlo. University of California, Riverside, Technical Report.

Jones, G. L., Haran, M., Caffo, B. S., and Neath, R. (2006). Fixed-width output analysis for {M}arkov chain {M}onte {C}arlo. Journal of the American Statistical Association, 101:1537--1547.

Examples

Run this code
# Creates 10000 iterations in an AR(1) Markov chain with rho = .9
p <- 10000
tau <- 1
mc <- double(p)
mc[1] <- 2
for(i in 1:(p-1)){
mc[(i+1)] <- .9 * mc[i] + rnorm(1, 0, tau)
}

# Estimates the mean, .1 quantile and .9 quantile with MCSE using BM
mcse(mc)
mcse.q(mc, .1)
mcse.q(mc, .9)

# Estimates the mean, .1 quantile and .9 quantile with MCSE using OBM
mcse(mc, meth="OBM")
mcse.q(mc, .1, meth="OBM")
mcse.q(mc, .9, meth="OBM")

# Estimates E(x^2) with MCSE using spectral methods
g.fun <- function(x){x^2}
mcse(mc, g=g.fun, meth="TukeyHanning")

Run the code above in your browser using DataLab