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 |
Perform consistent batch means estimation on a vector of values from a Markov chain.
bm(x, size = "sqroot", warn = FALSE)
bm(x, size = "sqroot", warn = FALSE)
x |
a vector of values from a Markov chain. |
size |
the batch size. The default value is “ |
warn |
a logical value indicating whether the function should issue a warning if the sample size is too small (less than 1,000). |
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. |
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.
bmmat
, which applies bm
to each column of a matrix or data frame.
# 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)
# 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)
bm
to each column of a matrix or data frame of MCMC samples.Apply bm
to each column of a matrix or data frame of MCMC samples.
bmmat(x)
bmmat(x)
x |
a matrix or data frame with each row being a draw from the multivariate distribution of interest. |
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 th row of the matrix contains the result of applying
bm
to the th column of
x
.
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).
ess(x, imse = TRUE, verbose = FALSE)
ess(x, imse = TRUE, verbose = FALSE)
x |
a vector of values from a Markov chain. |
imse |
logical. If |
verbose |
logical. If |
ESS is the size of an iid sample with the same variance as the current sample. ESS is given by
where
The function returns the estimated effective sample size.
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.
estvssamp(x, fun = mean, main = "Estimate vs Sample Size", add = FALSE, ...)
estvssamp(x, fun = mean, main = "Estimate vs Sample Size", add = FALSE, ...)
x |
a sample vector. |
fun |
a function such that |
main |
an overall title for the plot. The default is “ |
add |
logical. If |
... |
additional arguments to the plotting function. |
NULL
# 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)
# 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)