Re: [R] glm expand model to more values

From: Charles Annis, P.E. <Charles.Annis_at_statisticalengineering.com>
Date: Sat, 12 Jan 2008 13:39:01 -0500

How many parameters are you trying to estimate? How many observations do you have?

What is wrong is that half of your parameter estimates are statistically meaningless:

dd <- data.frame(a=c(1, 2, 3, 4, 5, 6), b=c(3, 5, 6, 7, 9, 10))

overparameterized.model <- glm(b~poly(a,3),data=dd)

summary(overparameterized.model)

Coefficients:

            Estimate Std. Error t value Pr(>|t|)

(Intercept) 6.6667 0.1725 38.644 0.000669 ***

poly(a, 3)1 5.7371 0.4226 13.576 0.005382 **

poly(a, 3)2 -0.1091 0.4226 -0.258 0.820395

poly(a, 3)3 0.2236 0.4226 0.529 0.649562

Charles Annis, P.E.

Charles.Annis_at_StatisticalEngineering.com phone: 561-352-9699
eFax: 614-455-3265
http://www.StatisticalEngineering.com  

-----Original Message-----
From: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-project.org] On
Behalf Of Jarek Jasiewicz
Sent: Saturday, January 12, 2008 11: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.

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 - 18:47:31 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 - 19: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.

list of date sections of archive