[R] Polynomial Regression and NA coefficients in R
Bert Gunter
gunter.berton at gene.com
Sat Apr 27 23:23:27 CEST 2013
Inline.
-- Bert
On Sat, Apr 27, 2013 at 8:48 AM, Lucas Holland <hollandlucas at gmail.com> wrote:
> Hey all,
>
> I'm performing polynomial regression. I'm simulating x values using runif() and y values using a deterministic function of x and rnorm().
>
> When I perform polynomial regression like this:
>
> fit_poly <- lm(y ~ poly(x,11,raw = TRUE))
>
> I get some NA coefficients. I think this is due to the high correlation between say x and x^2 if x is distributed uniformly on the unit interval (as is the case in my example). However, I'm still able to plot a polynomial fit like this:
>
> points(x, predict(fit_poly), type="l", col="green", lwd=2)
>
> What I'm interested in finding out is, how R handles the NA values I get for some coefficients (and how that affects the polynomial I see plotted).
It ignores them, i.e. treats them as 0.
You are overfitting. See the singular.ok argument.
Incidentally, using high order polynomials as data smoothers is
nowadays usually frowned on. Consider using splines or other
effectively local smoothers instead. R has many alternatives.
-- Bert
>
> Thanks!
>
> ______________________________________________
> 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.
--
Bert Gunter
Genentech Nonclinical Biostatistics
Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
More information about the R-help
mailing list