# Generating predicted mean values and CIs across different groups in lme4

I’ve run a mixed-effects model with crossed random effects in glmer and ultimately want to show a bar graph depicting mean predicted values (and associated confidence intervals) across years within treatments.

My understanding is that the best way to generate the CIs is to bootstrap (via the ‘boot’ package), using the mean predicted values as the statistic of interest.

I tried to do this, using the relevant help files and leaning heavily on the code from Hans Ekbrand (Obtaining adjusted (predicted) proportions with lme4 - using the glmer-function), but have a few questions.

1) I understand most of Han’s code, except for his use of ‘indices’ when he is defining the function to generate the bootstrap statistic. E.g.:

my.bootstrap.predictions.f <- function(data, indices){
return(mean(predict(my.fit, newdata = data[indices, ], type =
"response", allow.new.levels=TRUE), na.rm=TRUE))
}


To what do the indices refer in these two instances? (I understand that data generally can be indexed, but am not sure about the use of the term in these particular cases).

2) More importantly, I can’t figure out how to adjust the code so that it produces the mean predicted values for the individual groups.

Here is my original glmer equation:

m2 <- glmer(cbind(recap, newcap)~treatment+dv1.yr+ dv2.yr +
mean.hyd + sd.hyd+ (1|wetland) + (1|year),