# Re: [R] glm expand model to more values

From: Greg Snow <Greg.Snow_at_imail.org>
Date: Sat, 12 Jan 2008 10:46:54 -0700

Either use the predict function to create the new predictions, or use the raw argument to poly.

From: r-help-bounces_at_r-project.org on behalf of Jarek Jasiewicz Sent: Sat 1/12/2008 9:50 AM
To: R-help_at_r-project.org
Subject: [R] glm expand model to more values

Hi

I have the problem with fitting curve to data with lm and glm. When I use polynominal dependiency, fitted values from model are OK, but I cannot recive proper values when I use coefficents to caltulate this. Let me present simple example:

I have simple data.frame: (dd)

1. 1 2 3 4 5 6
2. 3 5 6 7 9 10

I try to fit it to model:

model=glm(b~poly(a,3),data=dd)
I have following data fitted to model (as I expected)
> fitted(model)

1 2 3 4 5 6  3.095238 4.738095 6.095238 7.333333 8.619048 10.119048

and coef(model)
(Intercept) poly(a, 3)1 poly(a, 3)2 poly(a, 3)3   6.6666667 5.7370973 -0.1091089 0.2236068

so when I try to expand the model to other data (simple extrapolation), let say: s=seq(1:10,by=1)

I do:
extra=sapply(s,function(x) coef(model) %*% x^(0:3)) and here is result:
[1] 12.51826 19.49328 28.93336 42.18015 60.57528 85.46040 118.17714  [8] 160.06715 212.47207 276.73354

the data form expanding coefs are completly differnd from fitted

What's going wrong?

Jarek

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.

[[alternative HTML version deleted]]

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. Received on Sat 12 Jan 2008 - 17:54:57 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 12 Jan 2008 - 18:30:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.