[R-sig-ME] calculation of confidence intervals for random slope model
Paul Buerkner
paul.buerkner at gmail.com
Tue Nov 17 11:23:58 CET 2015
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>:
> I have what I hope is a relatively straightforward question about how to
> interpret the results of a mixed effects model of the form:
>
> fm1 <- lmer(Reaction ~ Days + (Days | Subject))
>
> I am running an experiment such that I am most interested in the
> (equivalent of the) effect of Days for each Subject, rather than say fitted
> values. I understand how to derive the point estimates for this effect, but
> I am struggling to see how to calculate confidence intervals for these
> estimates that take account of both the standard error in the parameter
> estimate for Days and the uncertainty in the corresponding slope estimates
> for each Subject.
>
> I would be very grateful if someone could point me in the right direction
> or to a suitable reference.
>
> ------------------------------------------------
> Henry Travers, PhD
> Research Associate
>
> Interdisciplinary Centre for Conservation Science
> Department of Zoology
> University of Oxford
>
>
>
>
>
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-mixed-models at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>
[[alternative HTML version deleted]]
More information about the R-sig-mixed-models
mailing list