MCMCrecover {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,
breaks = NULL
)
x 
An object containing MCMC draws:

true 
A numeric vector of "true" values of the parameters in 
batch 
Optionally, a vectorlike object (numeric, character, integer,
factor) used to split the parameters into batches. If 
... 
Currently unused. 
facet_args 
A named list of arguments (other than 
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 
Passed to 
breaks 
Passed to 
A ggplot object that can be further customized using the ggplot2 package.
mcmc_recover_intervals()
Central intervals and point estimates computed from MCMC draws, with "true" values plotted using a different shape.
mcmc_recover_scatter()
Scatterplot of posterior means (or medians) against "true" values.
mcmc_recover_hist()
Histograms of the draws for each parameter with the "true" value overlaid as a vertical line.
Other MCMC:
MCMCcombos
,
MCMCdiagnostics
,
MCMCdistributions
,
MCMCintervals
,
MCMCnuts
,
MCMCoverview
,
MCMCparcoord
,
MCMCscatterplots
,
MCMCtraces
## 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), refresh = 0)
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)