Package 'batchmeans'

Title: Consistent Batch Means Estimation of Monte Carlo Standard Errors
Description: Provides consistent batch means estimation of Monte Carlo standard errors.
Authors: Murali Haran <[email protected]> and John Hughes <[email protected]>
Maintainer: John Hughes <[email protected]>
License: GPL (>= 2)
Version: 1.0-4
Built: 2025-01-16 03:06:19 UTC
Source: https://github.com/cran/batchmeans

Help Index


Perform consistent batch means estimation on a vector of values from a Markov chain.

Description

Perform consistent batch means estimation on a vector of values from a Markov chain.

Usage

bm(x, size = "sqroot", warn = FALSE)

Arguments

x

a vector of values from a Markov chain.

size

the batch size. The default value is “sqroot”, which uses the square root of the sample size. “cuberoot” will cause the function to use the cube root of the sample size. A numeric value may be provided if neither “sqroot” nor “cuberoot” is satisfactory.

warn

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

Value

bm returns a list with two elements:

est

the mean of the vector.

se

the MCMC standard error based on the consistent batch means estimator.

References

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–1547.

The following article is less technical and contains a direct comparison to the Gelman-Rubin diagnostic.

Flegal, J. M., Haran, M. and Jones, G. L. (2008) Markov chain Monte Carlo: Can we trust the third significant figure? Statistical Science, 23, 250–260.

See Also

bmmat, which applies bm to each column of a matrix or data frame.

Examples

# Simulate a sample path of length 10,000 for an AR(1) chain with rho equal to 0.7.

X = numeric(10000)
X[1] = 1
for (i in 1:9999)
    X[i + 1] = 0.7 * X[i] + rnorm(1)

# Estimate the mean and MCSE.

bm(X)

Apply bm to each column of a matrix or data frame of MCMC samples.

Description

Apply bm to each column of a matrix or data frame of MCMC samples.

Usage

bmmat(x)

Arguments

x

a matrix or data frame with each row being a draw from the multivariate distribution of interest.

Value

bmmat returns a matrix with ncol(x) rows and two columns. The row names of the matrix are the same as the column names of x. The column names of the matrix are “est” and “se”. The jjth row of the matrix contains the result of applying bm to the jjth column of x.

See Also

bm, which performs consistent batch means estimation for a vector.


Estimate effective sample size (ESS) as described in Kass et al. (1998) and Robert and Casella (2004; p. 500).

Description

Estimate effective sample size (ESS) as described in Kass et al. (1998) and Robert and Casella (2004; p. 500).

Usage

ess(x, imse = TRUE, verbose = FALSE)

Arguments

x

a vector of values from a Markov chain.

imse

logical. If TRUE, use an approach that is analogous to Geyer's initial monotone positive sequence estimator (IMSE), where correlations beyond a certain lag are removed to reduce noise.

verbose

logical. If TRUE and imse = TRUE, inform about the lag at which truncation occurs, and warn if the lag is probably too small.

Details

ESS is the size of an iid sample with the same variance as the current sample. ESS is given by

ESS=T/η,\mbox{ESS}=T/\eta,

where

η=1+2all lag autocorrelations.\eta=1+2\sum \mbox{all lag autocorrelations}.

Value

The function returns the estimated effective sample size.

References

Kass, R. E., Carlin, B. P., Gelman, A., and Neal, R. (1998) Markov chain Monte Carlo in practice: A roundtable discussion. The American Statistician, 52, 93–100.

Robert, C. P. and Casella, G. (2004) Monte Carlo Statistical Methods. New York: Springer.

Geyer, C. J. (1992) Practical Markov chain Monte Carlo. Statistical Science, 7, 473–483.


Create a plot that shows how Monte Carlo estimates change with increasing sample size.

Description

Create a plot that shows how Monte Carlo estimates change with increasing sample size.

Usage

estvssamp(x, fun = mean, main = "Estimate vs Sample Size", add = FALSE,
  ...)

Arguments

x

a sample vector.

fun

a function such that E(fun(x))E(fun(x)) is the quantity of interest. The default is fun = mean.

main

an overall title for the plot. The default is “Estimates vs Sample Size”.

add

logical. If TRUE, add to a current plot.

...

additional arguments to the plotting function.

Value

NULL

Examples

# Simulate a sample path of length 10,000 for an AR(1) chain with rho equal to 0.7.

X = numeric(10000)
X[1] = 1
for (i in 1:9999)
    X[i + 1] = 0.7 * X[i] + rnorm(1)

# Plot MC estimates versus sample size.

estvssamp(X)