[R] using predict() or fitted() from a model with offset
sam_oi at yahoo.fr
sam_oi at yahoo.fr
Sun Oct 12 12:36:11 CEST 2008
Dear R-users,
I have come across some difficulties using the offset argument in a model. There is not much information in ?offset, ?lm, ?glm and therefore have resorted to post here.
Offset appears to work in the models I run becuase I get the expected coefficients when comparing offset and non-offset models . BUT the fitted values obtained from fitted() are identical in both models!! Why is this? Is there an argument to add to fitted() so that it takes the offset into accout?
Note that I have included the offset in the formula, as seen below in the code.
I have also tried to use predict, with exactly the same result: the offset is ignored. This applies to both lms and glms.
Am I missing something here?
Thank you
Samuel Riou
CODE
#no offset
lmA<-lm(MassChange24h~DATEN1, subset(Chicks1, Year==2007 & AGE>10), na.action=na.exclude)
summary(lmA)
#linear offset
lmAO<-lm(MassChange24h~DATEN1+offset(-0.37356*AGE), subset(Chicks1, Year==2007 & AGE>10), na.action=na.exclude)
summary(lmAO)
print(Chicks$DATEN1[Year==2007 & AGE>10])
print(t(fitted(lmA)))
NEW<-cbind(as.vector(t(fitted(lmA))), Chicks$DATEN1[Year==2007 & AGE>10])
NEW<-as.data.frame(NEW)
m1<-aggregate(NEW[1],NEW[2],mean, na.rm=TRUE)
plot(m1$V1~m1$V2, pch=20, col="black")
Pred<-predict(lmA)
print(Chicks$DATEN1[Year==2007 & AGE>10])
print(t(fitted(lmAO)))
NEW<-cbind(as.vector(t(fitted(lmAO))), Chicks$DATEN1[Year==2007 & AGE>10])
NEW<-as.data.frame(NEW)
m1<-aggregate(NEW[1],NEW[2],mean, na.rm=TRUE)
points(m1$V1~m1$V2, pch=20, col="red") ###but the fitted values dont seem to take into account the offset
Pred<-predict(lmAO)
More information about the R-help
mailing list