Skip to content
Prev 13978 / 20628 Next

calculation of confidence intervals for random slope model

You may use Bayesian (MCMC) model fitting procedures to get what you want.
With the brms package you may do the following (using the sleepstudy
example):

# load packages
library(lme4)
library(brms)

# fit the sample model
fm1 <- brm(Reaction ~ Days + (Days|Subject), data = sleepstudy)

# get the desired CI for you first Subject
# the 1 in "r_Subject[1,2]" indicates that you look at the first Subject
# the 2 in "r_Subject[1,2]" indicates that you look at the second random
effect
# (random intercept is the 1st, random slope of Days is the 2nd random
effect)
hypothesis(fm1, "b_Days + r_Subject[1,2] = 0", class = NULL)

# write the hypotheses for all subjects at once
subject_numbers <- 1:length(unique(sleepstudy$Subject))
hyp <- paste0("b_Days + r_Subject[", subject_numbers, ",2] = 0")

# get desired CIs for all subjects
hypothesis(fm1, hyp, class = NULL)


The code above will only work with the github version of brms to be
installed via
devtools::install_github("paul-buerkner/brms")

Since brms is based on Stan, you will need a C++ compiler to get it
working.
Further information can be found at the bottom of the Readme at
https://github.com/paul-buerkner/brms

2015-11-16 11:56 GMT+01:00 Henry Travers <henry.travers at zoo.ox.ac.uk>: