[R] plotting gamm results in lattice

Maria Lathouri mlathouri at yahoo.gr
Mon Jun 12 12:56:39 CEST 2017


Dear all, 
I hope that you can help me on this. I have been struggling to figure this out but I haven't found any solution.
I am running a generalised mixed effect model, gamm4, for an ecology project. Below is the code for the model:
model<-gamm4(LIFE.OE_spring~s(Q95, by=super.end.group)+Year+Hms_Rsctned+Hms_Poaching+X.broadleaved_woodland             +X.urban.suburban+X.CapWks, data=spring, random=~(1|WATERBODY_ID/SITE_ID))
plot(model$gam, page=1, font.lab=2, xlab="Residual Q95")

I am trying to plot the results in lattice for publication purposes so I need to figure this out. I have been struggling but I think I have reached a dead end. 

Here is what I have been able to code:
M<-predict(model$gam,type="response",se.fit=T)
upr<- M$fit + (1.96 * M$se.fit)lwr<- M$fit - (1.96 * M$se.fit)
library(lattice)xyplot(fitted(model$gam) ~ Q95 |super.end.group, data = spring, gm=model,       prepanel=function (x,y,...)list(ylim=c(min(upr),max(lwr))),       panel = function(x,y, gm, ...){              panel.xyplot(x,y, type="smooth")         panel.lines(upr,lty=2, col="red")         panel.lines(lwr,lty=2, col="red")         panel.loess(x,y,...)         panel.rug(x = x[is.na(y)],                   y = y[is.na(x)])       }       )
But, unfortunately, this is not what I get when I have the simple plot(model$gam). 

I have also attached a reproducible example in case you want to see for yourself. I hope that someone here has come up with a similar problem and can help me on this.
Thank you very much for your time.
Kind regards,Maria 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: example.txt
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20170612/3a9fedae/attachment-0001.txt>


More information about the R-help mailing list