Hi Everyone,

I'm continuing to run into trouble with polyfit. I'm using the fitting function 
of the form;

fit <- lm(y ~ poly(x,degree,raw=TRUE))

and I have found that in some cases a polynomial of certain degree can't be 
fit, the coefficient won't be calculated, because of a singularity. If I use 
orthogonal polynomials I can fit a polynomial of any degree, but I don't get 
the proper coefficients. I'm having trouble solving this partly because I 
likely don't understand enough about polynomial fitting - and for that I have 
to apologize since I know this isn't supposed to be a forum for asking 
questions about mathematical process and rather for questions about the 
functionality of R. Nevertheless, can anyone provide guidance on this point? Is 
there a way to use orthogonal polynomials (the part about the fitting process 
that I don't quite understand) and still find the polynomial coefficients? 
Alternatively, what does one do about singularities using raw polynomials? It 
seems odd to me that the orthogonal polynomials can be used to fit the data, 
even visually once plotted, predicted values that are accurate can be derived 
from the function using predict(), but the coefficients are unknown. Any help 
is appreciated,

Chris

output below:
-----------------------------------------------
> archit[,1]

[1] 1.8 1.3 2.0 2.1 1.9 1.9 1.3 1.9 2.8

> x

[1] 8752 8610 8554 8496 8482 8462 8438 8418 8384

>archi_rooms <- lm(archit[,1] ~ poly(x,4))
>summary(archi_rooms)

Call:

lm(formula = archit[, 1] ~ poly(x, 4))


Residuals:

        1         2         3         4         5         6         7         8 

-0.001790  0.042008 -0.112756  0.083040  0.005183  0.175733 -0.330450  0.137128 

        9 

 0.001905 


Coefficients:

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

(Intercept)  1.88889    0.07077  26.691 1.17e-05 ***

poly(x, 4)1 -0.47520    0.21230  -2.238   0.0888 .  

poly(x, 4)2  0.50116    0.21230   2.361   0.0776 .  

poly(x, 4)3 -0.20830    0.21230  -0.981   0.3821    

poly(x, 4)4  0.94246    0.21230   4.439   0.0113 *  

---

Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 


Residual standard error: 0.2123 on 4 degrees of freedom

Multiple R-squared: 0.8865,    Adjusted R-squared: 0.7731 

F-statistic: 7.813 on 4 and 4 DF,  p-value: 0.03570 


>archi_rooms <- lm(archit[,1] ~ poly(x,4,raw=TRUE))
> summary(archi_rooms)


Call:

lm(formula = archit[, 1] ~ poly(x, 4, raw = TRUE))


Residuals:

       1        2        3        4        5        6        7        8 

 0.04665 -0.39399  0.34009  0.37112  0.13015  0.05111 -0.67957 -0.22202 

       9 

 0.35647 


Coefficients: (1 not defined because of singularities)

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

(Intercept)              4.205e+04  9.107e+04   0.462    0.664

poly(x, 4, raw = TRUE)1 -1.461e+01  3.191e+01  -0.458    0.666

poly(x, 4, raw = TRUE)2  1.693e-03  3.726e-03   0.454    0.669

poly(x, 4, raw = TRUE)3 -6.536e-08  1.450e-07  -0.451    0.671

poly(x, 4, raw = TRUE)4         NA         NA      NA       NA


Residual standard error: 0.4623 on 5 degrees of freedom

Multiple R-squared: 0.3275,    Adjusted R-squared: -0.076 

F-statistic: 0.8116 on 3 and 5 DF,  p-value: 0.5397

                                          
_________________________________________________________________


        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to