2
$\begingroup$

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),     
family=binomial(link=logit), data = df, na.action=na.omit)

Treatment, wetland, and year are all factors, while the rest of the variables are numeric variables.

I used treatment contrasts for treatment, such that treatment 1 is the reference level.

A subset of the data looks like this:

data image

I’m looking to generate the mean predicted value for each treatment within each year. So if I have 3 treatments and 6 years, I’m looking for 18 mean values.

Thanks in advance for any insights.

$\endgroup$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.