I am trying to visualize the results from a glmm that I ran with the lme4 package.
M8<-glmer(abundance~ Mom+ Mom*settlment2 + (1|Pop) + (1|obs), family=poisson, data=glm)
My response variable are count data, therefore I have chosen a poisson distribution. Also, my data are overdispersed, so I have added in observation as a random effect to help account for this. However, my data still seem to be violating independence, which is why I am using a generalised linear mixed model. However, the built-in R predict function breaks down for lmer type objects, so I using the predictSE.mer command from the package (AICcmodavg).
plot(abundance, settlment2, xlab="settlment", ylab="abundance", data=glm) #plot my raw data MyData<-data.frame(settlment2=seq(from=0, to = 350, by=15.3), glm$Mom) #make a new data frame G<-predictSE.mer(M8, newdata=MyData, type="link", se.fit=TRUE, level=0, print.matrix=FALSE) #now to calculate fitted means F<-exp(G$fit) lines(MyData$settlment2, F, lty=1)
This seems to work somewhat well, but I am having trouble producing data.frames correctly as I increase the number of fixed factors and interactions.
So, I guess what I am looking for is a way to do this in ggplot2. It works well with lme objects from nlme but not glmer objects. For example using lme:
m11<-lme(abundance~settlment2*Pop + Pop + settlment2, random=~1|Mom, data=glm, method="ML", na.action=na.exclude) g0 <-ggplot(glm,aes(x=settlment2,y=abundance,colour=Pop))+geom_point(aes(group=Pop),alpha=0.3)+ theme_bw() g0 + geom_line(data=transform(glm,abundance=predict(m11)), lty=1)
Essentially, what I would like to do is use ggplot2 so that I can break up the results like the second graph, into my two populations (Pop) but using the code above for glmer and not with lme.
I have been reading Mixed Effects Models and Extension in Ecology in R (Zuur et al.) trying to reproduce their deer data (pg. 326) or (pg. 329) but instead of probabilities on the Y-axis, I would like just predicted values. I have looked into the function plotLMER.fnc in the package LMERConvienienceFunctions as well, but I would really like to know if this is possible to do in ggplot2 as I am much more familiar with that package.
Thanks in advance for the advice!