[R] Why missing values are not allowed in 'poly'?
wdunlap at tibco.com
Wed Mar 23 21:29:31 CET 2016
I think the worst aspect of this restriction in poly() is that when
you use poly in the formula of a model-fitting function you cannot
have any missing values in the data, even if you supply
> d <- transform(data.frame(y=c(-1,1:10)), x=log(y))
In log(y) : NaNs produced
> fit <- lm(y ~ poly(x, 3), data=d, na.action=na.exclude)
Error in poly(x, 3) : missing values are not allowed in 'poly'
Thus people are pushed to using a less stable formulation like
> fit <- lm(y ~ x + I(x^2) + I(x^3), data=d, na.action=na.exclude)
On Wed, Mar 23, 2016 at 12:59 PM, Liviu Andronic <landronimirc at gmail.com>
> Dear all,
> I'm a bit surprised by this behavior in poly:
> x <- c(NA, 1:10)
> poly(x, degree = 2, raw=TRUE)
> ## Error in poly(x, degree = 2, raw = TRUE) :
> ## missing values are not allowed in 'poly'
> ##  NA 1 4 9 16 25 36 49 64 81 100
> As you can see, poly() will fail if the vector contains NAs, whereas
> it is perfectly possible to obtain the square of the vector manually.
> Is there a reason for this limitation in poly?
> Do you think you know what math is?
> Or what it means to be intelligent?
> Think again:
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
More information about the R-help