| mcmc_gr_test | R Documentation |
Runs Markov chain Monte Carlo (MCMC) sampling for a user-supplied probability density function (PDF) or log-likelihood function of variable and parameters with data, and returns upgraded lugsail Gelman-Rubin convergence test statistics, effective sample sizes, parameter estimates, and termination decisions.
mcmc_gr_test(
target_pdf,
data = NULL,
start_par,
n_iter = 2000,
n_chains = 3,
burn_in = 0.5,
scale = 0.5,
alpha = 0.05,
epsilon = 0.1,
...
)
target_pdf |
Function taking parameter vector |
data |
Optional data vector, matrix, data.frame, or list passed to |
start_par |
Initial parameter vector. If named, parameter names will be preserved. |
n_iter |
Integer, total number of MCMC iterations per chain (default |
n_chains |
Integer, number of parallel MCMC chains to generate (default |
burn_in |
Numeric, fraction of initial burn-in samples to discard (default |
scale |
Numeric or vector, proposal standard deviation for random walk Metropolis-Hastings sampler (default |
alpha |
Numeric, significance level for convergence bound (default |
epsilon |
Numeric, relative volume tolerance (default |
... |
Additional parameters passed to |
An object of class "lugsail_gr" containing Gelman-Rubin test statistics,
effective sample sizes, cutoff thresholds, parameter estimates, standard errors,
and MCMC chain samples.
Vats, D. and Knudson, C. (2021). Revisiting the Gelman–Rubin Diagnostic. Statistical Science, 36(4), 518–529. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1214/20-STS812")}.
# Example 1: Normal distribution target PDF with data
set.seed(42)
true_mean <- 3
my_data <- rnorm(50, mean = true_mean, sd = 1)
# Log-posterior density function for parameter mu
log_post <- function(mu, data) {
sum(dnorm(data, mean = mu, sd = 1, log = TRUE))
}
# Run diagnostic test
fit <- mcmc_gr_test(target_pdf = log_post, data = my_data, start_par = c(mu = 0),
n_iter = 1000, n_chains = 3)
print(fit)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.