[R] Predicting complicated GAMMs on response scale
William Paterson
wdp1 at st-andrews.ac.uk
Mon May 18 20:48:44 CEST 2009
Hi,
I am using GAMMs to show a relationship of temperature differential over
time with a model that looks like this:-
gamm(Diff~s(DaysPT)+AirToC,method="REML")
where DaysPT is time in days since injury and Diff is repeat measures of
temperature differentials with regards to injury sites compared to
non-injured sites in individuals over the course of 0-24 days. I use the
following code to plot this model on the response scale with 95% CIs which
works fine:-
g.m<-gamm(Diff~s(DaysPT)+AirToC,method="REML")
p.d<-data.frame(DaysPT=seq(min(DaysPT),max(DaysPT)))
p.d$AirToC<-(6.7)
b<-predict.gam(g.m$gam,p.d,se=TRUE)
range<-c(min(b$fit-2*b$se.fit),max(b$fit+2*b$se.fit))
plot(p.d$DaysPT,b$fit,ylim=c(-4,12),xlab="Days post-tagging",ylab="dTmax
(ºC)",type="l",lab=c(24,4,12),las=1,cex.lab=1.5, cex.axis=1,lwd=2)
lines(p.d$DaysPT,b$fit+b$se.fit*1.96,lty=2,lwd=1.5)
lines(p.d$DaysPT,b$fit-b$se.fit*1.96,lty=2,lwd=1.5)
points(DaysPT,Diff)
However, when I add a correlation structure and/or a variance structure so
that the model may look like:-
gamm(Diff~s(DaysPT3)+AirToC,correlation=corCAR1(form=~DaysPT|Animal),weights=varPower(form=~DaysPT),method="REML")
I get this message at the point of inputting the line
"b<-predict.gam(g.m$gam,p.d,se=TRUE)"
Error in model.frame(formula, rownames, variables, varnames, extras,
extranames, :
variable lengths differ (found for 'DaysPT')
In addition: Warning messages:
1: not all required variables have been supplied in newdata!
in: predict.gam(g.m$gam, p.d, se = TRUE)
2: 'newdata' had 25 rows but variable(s) found have 248 rows
Is it possible to predict a more complicated model like this on the response
scale? How can I incorporate a correlation structure and variance structure
in a dataframe when using the predict function for GAMMs?
Any help would be greatly appreciated.
William Paterson
--
View this message in context: http://www.nabble.com/Predicting-complicated-GAMMs-on-response-scale-tp23603248p23603248.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list