| MCMC-recover {bayesplot} | R Documentation |
Plots comparing MCMC estimates to "true" parameter values. Before fitting a model to real data it is useful to simulate data according to the model using known (fixed) parameter values and to check that these "true" parameter values are (approximately) recovered by fitting the model to the simulated data. See the Plot Descriptions section, below, for details on the available plots.
mcmc_recover_intervals(x, true, batch = rep(1, length(true)),
facet_args = list(), ..., prob = 0.5, prob_outer = 0.9,
point_est = c("median", "mean", "none"), size = 4, alpha = 1)
mcmc_recover_scatter(x, true, batch = rep(1, length(true)),
facet_args = list(), ..., point_est = c("median", "mean"), size = 3,
alpha = 1)
mcmc_recover_hist(x, true, facet_args = list(), ..., binwidth = NULL)
x |
A 3-D array, matrix, list of matrices, or data frame of MCMC draws. The MCMC-overview page provides details on how to specify each these allowed inputs. |
true |
A numeric vector of "true" values of the parameters in |
batch |
Optionally, a vector-like object (numeric, character, integer,
factor) used to split the parameters into batches. If |
facet_args |
A named list of arguments (other than |
... |
Currently unused. |
prob |
The probability mass to include in the inner interval. The
default is |
prob_outer |
The probability mass to include in the outer interval. The
default is |
point_est |
The point estimate to show. Either |
size, alpha |
Passed to |
binwidth |
An optional value used as the |
A ggplot object that can be further customized using the ggplot2 package.
mcmc_recover_intervalsCentral intervals and point estimates computed from MCMC draws, with "true" values plotted using a different shape.
mcmc_recover_scatterScatterplot of posterior means (or medians) against "true" values.
mcmc_recover_histHistograms of the draws for each parameter with the "true" value overlaid as a vertical line.
Other MCMC: MCMC-combos,
MCMC-diagnostics,
MCMC-distributions,
MCMC-intervals, MCMC-nuts,
MCMC-overview, MCMC-parcoord,
MCMC-scatterplots,
MCMC-traces
## Not run:
library(rstanarm)
alpha <- 1; beta <- rnorm(10, 0, 3); sigma <- 2
X <- matrix(rnorm(1000), 100, 10)
y <- rnorm(100, mean = c(alpha + X %*% beta), sd = sigma)
fit <- stan_glm(y ~ ., data = data.frame(y, X))
draws <- as.matrix(fit)
print(colnames(draws))
true <- c(alpha, beta, sigma)
mcmc_recover_intervals(draws, true)
# put the coefficients on X into the same batch
mcmc_recover_intervals(draws, true, batch = c(1, rep(2, 10), 1))
# equivalent
mcmc_recover_intervals(draws, true, batch = grepl("X", colnames(draws)))
# same but facets stacked vertically
mcmc_recover_intervals(draws, true,
batch = grepl("X", colnames(draws)),
facet_args = list(ncol = 1),
size = 3)
# each parameter in its own facet
mcmc_recover_intervals(draws, true, batch = 1:ncol(draws))
# same but in a different order
mcmc_recover_intervals(draws, true, batch = c(1, 3, 4, 2, 5:12))
# present as bias by centering with true values
mcmc_recover_intervals(sweep(draws, 2, true), rep(0, ncol(draws))) + hline_0()
# scatterplot of posterior means vs true values
mcmc_recover_scatter(draws, true, point_est = "mean")
# histograms of parameter draws with true value added as vertical line
color_scheme_set("brightblue")
mcmc_recover_hist(draws[, 1:4], true[1:4])
## End(Not run)