sam_oi at yahoo.fr
2008-Oct-10 16:30 UTC
[R] Coefficients in a polynomial glm with family poisson/binomial
Dear R-users When running a glm polynomial model with one explanatory variable (example Y~X+X^2), with a poisson or binomial error distribution, the predicted values obtained from using the predict() function and those obtained from using the coefficients from the summary table "as is" in an equation of the form Y=INTERCEPT+ XCoef x X + XCoef x X^2, differ considerably. The former are correct and the latter are wrong. This does not occur using lm() or in a glm with family as normal. I conclude that this is due to the link function, predict() having some way of back transforming the data. But if this is so, are the estimated coefficients wortheless in this case? I need to get accurate coefficients (for use in another model using offset), and have resorted to re-estimating them by running a second polynomial (lm() this time) on the predicted values from predict() of the glm. This is clearly not a nice way of doing things. Could anyone please inform me of why this is happening and of a better way around this? Code: glm2<-glm(FEDSTATUS1~AGE+I(AGE^2), family=binomial(link="probit")) summary(glm2) ### first set of "wrong coefficients" nd1<-expand.grid(AGE=c(1:70)) Pred.Fed1<-predict(glm2,nd1,type="response") points(predict(glm2,nd1,type="response")~nd1$AGE, col=2) AGE11<-c(11:70) Pred<-t(rbind(Pred.Fed1,AGE11)) Pred<-as.data.frame(Pred) model<-lm(Pred$Pred.Fed1~Pred$AGE11+I(Pred$AGE11^2)) summary(model) ### "accurate coefficients" Thanks Samuel Riou University of Leeds
Daniel Malter
2008-Oct-10 17:58 UTC
[R] Coefficients in a polynomial glm with family poisson/binomial
I don't know what you mean by XCoef x X. But your problem is (as it works if you specify "normal" in a glm) that the functional relationship between your predictors, i.e. Intercept+X+X^2, and Y is not linear for a binomial or a poisson distribution. Generalized linear model implies that the model is linear in the predictors. It does not mean, however, that the functional relationship between the linear predictor and Y is linear. E.g. Y=exp(Intercept+X+X^2) is linear in the predictor, but it is a nonlinear function because "e" is raised to the linear predictor. Consult any book on generalized linear models for more help. The estimated coefficients are typically not worthless as allow you to say how much your Y will change with a change of delta*x at the mean of X, for example, you just have to respect the functional form of the relationship between X and Y. Thus, the coefficients you get are accurate. Just what you do with them is not. For the last part of your question, I am not sure what you are trying to do there, but it does not sound right to me in the first place. Cheers, Daniel ------------------------- cuncta stricte discussurus ------------------------- -----Urspr?ngliche Nachricht----- Von: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] Im Auftrag von sam_oi at yahoo.fr Gesendet: Friday, October 10, 2008 12:30 PM An: r-help at r-project.org Betreff: [R] Coefficients in a polynomial glm with family poisson/binomial Dear R-users When running a glm polynomial model with one explanatory variable (example Y~X+X^2), with a poisson or binomial error distribution, the predicted values obtained from using the predict() function and those obtained from using the coefficients from the summary table "as is" in an equation of the form Y=INTERCEPT+ XCoef x X + XCoef x X^2, differ considerably. The former are correct and the latter are wrong. This does not occur using lm() or in a glm with family as normal. I conclude that this is due to the link function, predict() having some way of back transforming the data. But if this is so, are the estimated coefficients wortheless in this case? I need to get accurate coefficients (for use in another model using offset), and have resorted to re-estimating them by running a second polynomial (lm() this time) on the predicted values from predict() of the glm. This is clearly not a nice way of doing things. Could anyone please inform me of why this is happening and of a better way around this? Code: glm2<-glm(FEDSTATUS1~AGE+I(AGE^2), family=binomial(link="probit")) summary(glm2) ### first set of "wrong coefficients" nd1<-expand.grid(AGE=c(1:70)) Pred.Fed1<-predict(glm2,nd1,type="response") points(predict(glm2,nd1,type="response")~nd1$AGE, col=2) AGE11<-c(11:70) Pred<-t(rbind(Pred.Fed1,AGE11)) Pred<-as.data.frame(Pred) model<-lm(Pred$Pred.Fed1~Pred$AGE11+I(Pred$AGE11^2)) summary(model) ### "accurate coefficients" Thanks Samuel Riou University of Leeds ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.