bootstrapping random effects using confint() in lme4
I answered this offline but wanted to encourage everyone, when in doubt, to post to r-sig-mixed-models at r-project.org rather than e-mailing me directly ... confint.merMod has a FUN argument that allows bootstrap CIs on an arbitrary function (as long as it returns a numeric vector) to be computed, e.g. confint(fitted_model,method="boot",FUN=function(m) unlist(ranef(m))) (We should probably add this as an example to the documentation ...) One can also get an estimate of the uncertainty in the conditional modes by extracting the "postVar" attributes from the elements of ranef(fitted_model,condVar=TRUE) ... if fm1 is the fitted model,
cvar <- lapply(ranef(fm1,condVar=TRUE),function(x) attr(x,"postVar")) apply(cvar[[1]],3,diag)
On 16-10-14 02:08 PM, Jonathan Miller wrote:
Dr. Bolker,
I am sorry for what I imagine is a pretty straightforward question. My
name is Jonathan Miller and I am a Phd student at NCSU in Civil
Engineering. I have tried to look through online resources for a post on
this, but have not been successful in determining what I need to do.
I have been using lme4 to run a logisitic mixed model and it has worked
very well. Recently, though, I was interested in determining the
uncertainty in the random effects in my model. It contains three levels of
random effects, estuaries(32), states(5) and programs(7). I think the
function confint() is what I need to do, but I am having trouble getting
the outputs for the individual random effects(i.e. estuaries, states,
programs).
My code is below:
m3=glmer(Pres~ Temp_mean + Sal_mean + salsq + NEAR_DIST
+ (1|STATE) + (1 | UNIQUEID) + (1|program),
data=bighead, na.action = na.exclude, nAGQ=0,
family=binomial(link="logit"))
confint.merMod(m3,method="boot",nsim=100)
My output just gives me a summary of each fixed effect and each random
effect group. I think there must be a relatively simple way to get the
output of the bootstrapping for each individual random effect. It seems
the answer lies in FUN, but I haven't gotten it to work for me yet.
2.5 % 97.5 %
sd_(Intercept)|UNIQUEID 4.720458e-01 0.98029041
sd_(Intercept)|program 3.168555e-01 1.26836628
sd_(Intercept)|STATE 3.019507e-07 1.30279935
(Intercept) -6.088106e+00 -3.81230673
Temp_mean -6.882682e-02 -0.05817473
Sal_mean 1.696714e-01 0.20005360
salsq -2.253061e+00 -1.89913153
NEAR_DIST 3.895820e-01 0.50612062
Any help would be greatly appreciated.
Thank you,
Jonathan Miller
[[alternative HTML version deleted]]
_______________________________________________ R-sig-mixed-models at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models