data("sleepstudy", package = "lme4")
### Examples using a covariance prior ##
# Here we are ignoring convergence warnings just to illustate how the package
# is used: this is not a good idea in practice..
control <- lmerControl(check.conv.grad = "ignore")
(fm1 <- blmer(Reaction ~ Days + (0 + Days|Subject), sleepstudy,
control = control,
cov.prior = gamma))
(fm2 <- blmer(Reaction ~ Days + (0 + Days|Subject), sleepstudy,
control = control,
cov.prior = gamma(shape = 2, rate = 0.5, posterior.scale = 'sd')))
(fm3 <- blmer(Reaction ~ Days + (1 + Days|Subject), sleepstudy,
control = control,
cov.prior = wishart))
(fm4 <- blmer(Reaction ~ Days + (1 + Days|Subject), sleepstudy,
control = control,
cov.prior = invwishart(df = 5, scale = diag(0.5, 2))))
# Custom prior
penaltyFn <- function(sigma)
dcauchy(sigma, 0, 10, log = TRUE)
(fm5 <- blmer(Reaction ~ Days + (0 + Days|Subject), sleepstudy,
cov.prior = custom(penaltyFn, chol = TRUE, scale = "log")))
### Examples using a fixed effect prior ###
(fm6 <- blmer(Reaction ~ Days + (1 + Days|Subject), sleepstudy,
cov.prior = NULL,
fixef.prior = normal))
(fm7 <- blmer(Reaction ~ Days + (1 + Days|Subject), sleepstudy,
cov.prior = NULL,
fixef.prior = normal(cov = diag(0.5, 2), common.scale = FALSE)))
### Example using a residual variance prior ###
# This is the "eight schools" data set; the mode should be at the boundary
# of the space.
control <- lmerControl(check.conv.singular = "ignore",
check.nobs.vs.nRE = "ignore",
check.nobs.vs.nlev = "ignore")
y <- c(28, 8, -3, 7, -1, 1, 18, 12)
sigma <- c(15, 10, 16, 11, 9, 11, 10, 18)
g <- 1:8
(schools <- blmer(y ~ 1 + (1 | g), control = control, REML = FALSE,
resid.prior = point, cov.prior = NULL,
weights = 1 / sigma^2))
Run the code above in your browser using DataLab