plot_coef {mcmcsae} | R Documentation |
Plot a set of model coefficients or predictions with uncertainty intervals based on summaries of simulation results or other objects.
Description
This function plots estimates with error bars. Multiple sets of
estimates can be compared. The error bars can either be based on
standard errors or on explicitly specified lower and upper bounds.
The function is adapted from function plot.sae
in package
hbsae, which in turn was adapted from function
coefplot.default
from package arm.
Usage
plot_coef(
...,
n.se = 1,
est.names,
sort.by = NULL,
decreasing = FALSE,
index = NULL,
maxrows = 50L,
maxcols = 6L,
offset = 0.1,
cex.var = 0.8,
mar = c(0.1, 2.1, 5.1, 0.1)
)
Arguments
... |
|
n.se |
number of standard errors below and above the point estimates
to use for error bars. By default equal to 1. This only refers to the
objects of class |
est.names |
labels to use in the legend for the components of the |
sort.by |
vector by which to sort the coefficients, referring to the first object passed. |
decreasing |
if |
index |
vector of names or indices of the selected areas to be plotted. |
maxrows |
maximum number of rows in a column. |
maxcols |
maximum number of columns of estimates on a page. |
offset |
space used between plots of multiple estimates for the same area. |
cex.var |
the font size for the variable names, default=0.8. |
mar |
a numerical vector of the form |
Examples
# create artificial data
set.seed(21)
n <- 100
dat <- data.frame(
x=runif(n),
f=factor(sample(1:20, n, replace=TRUE))
)
model <- ~ reg(~ x, prior=pr_normal(precision=1), name="beta") + gen(factor=~f, name="v")
gd <- generate_data(model, data=dat)
dat$y <- gd$y
# fit a base model
model0 <- y ~ reg(~ 1, name="beta") + gen(factor=~f, name="v")
sampler <- create_sampler(model0, data=dat, block=TRUE)
sim <- MCMCsim(sampler, store.all=TRUE)
(summ0 <- summary(sim))
# fit 'true' model
model <- y ~ reg(~ x, name="beta") + gen(factor=~f, name="v")
sampler <- create_sampler(model, data=dat, block=TRUE)
sim <- MCMCsim(sampler, store.all=TRUE)
(summ <- summary(sim))
# compare random effect estimates against true parameter values
plot_coef(summ0$v, summ$v, list(est=gd$pars$v), n.se=2, offset=0.2,
maxrows=10, est.names=c("base model", "true model", "true"))