I am trying to predict values over time (Days in x axis) for a glmer model that was run on my binomial data. Total Alive and Total Dead are count data. This is my model, and the corresponding steps below.
full.model.dredge<-glmer(cbind(Total.Alive,Total.Dead)~(CO2.Treatment+Lime.Treatment+Day)^3+(Day|Container)+(1|index),
data=Survival.data,family="binomial")
We have accounted for overdispersion as you can see in the code (1:index).
We then use the dredge command to determine the best fitted models with the main effects (CO2.Treatment, Lime.Treatment, Day) and their corresponding interactions.
dredge.models<-dredge(full.model.dredge,trace=FALSE,rank="AICc")
Then made a workspace variable for them
my.dredge.models<-get.models(dredge.models)
We then conducted a model average to average the coefficients for the best fit models
silly<-model.avg(my.dredge.models,subset=delta<10)
But now I want to create a graph, with the Total Alive on the Y axis, and Days on the X axis, and a fitted line depending on the output of the model. I understand this is tricky because the model concatenated the Total.Alive and Total.Dead (see cbind(Total.Alive,Total.Dead)
in the model.
When I try to run a predict command I get the error
# 9: In UseMethod("predict") :
# no applicable method for 'predict' applied to an object of class "mer"
Most of your problem is that you're using a pre-1.0 version of
lme4
, which doesn't have thepredict
method implemented. (Updating would be easiest, but I believe that if you can't for some reason, there's a recipe at http://glmm.wikidot.com/faq for doing the predictions by hand by extracting the fixed-effect design matrix and the coefficients ...)There's actually not a problem with the predictions, which predict the log-odds (by default) or the probability (iftype="response"
); if you wanted to predict numbers, you'd have to multiply by N appropriately.You didn't give one, but here's a reproducible (albeit somewhat trivial) example using the built-in
cbpp
data set (I do get some warning messages --no non-missing arguments to max; returning -Inf
-- but I think this may be due to the fact that there's only one non-trivial fixed-effect parameter in the model?)It's convenient for later use (with
ggplot
) to add a variable for the proportion:Fit the model (you could also use
glmer(prop~..., weights=size, ...)
)Prediction does work:
Creating a plot:
Set up a prediction frame:
Predict at the population level (
ReForm=NA
-- this may have to beREForm=NA
in lme4 `1.0.5):Add it to the graph: