[Rd] Bug in poly() (PR#11243)
Prof Brian Ripley
ripley at stats.ox.ac.uk
Fri May 16 07:20:56 CEST 2008
The reason is that you asked for more terms than can exist.
You seem unaware that 2.6.2 is obsolete, and that there are changes
in R-patched, with the following NEWS item:
o poly() has additional checks against user error (as in PR#11243).
and that the help page now says
degree: the degree of the polynomial. Must be less than the number
of unique points.
As the FAQ says, please don't make further reports on items that have
already been addressed (as clearly marked in the bug repository).
On Fri, 16 May 2008, russell-lenth at uiowa.edu wrote:
> I don't understand why this is a bug in usage. Is it because the 2nd
> argument is not named? I get the same behavior if I do name it:
>
> =====
> [R version 2.6.2 (2008-02-08), Windows XP Pro]
>
> R> x = rep(1:4,3)
> R> y = (1:12)^1.5
> R> lm(y ~ poly(x, degree=10))
>
> Call:
> lm(formula = y ~ poly(x, degree = 10))
>
> Coefficients:
> (Intercept) poly(x, degree = 10)1 poly(x, degree = 10)2
> 18.39370 14.21385 0.58588
> poly(x, degree = 10)3 poly(x, degree = 10)4 poly(x, degree = 10)5
> -0.01770 3.34767 -11.46388
> poly(x, degree = 10)6 poly(x, degree = 10)7 poly(x, degree = 10)8
> 0.51178 0.44296 12.47199
> poly(x, degree = 10)9 poly(x, degree = 10)10
> -28.38972 18.47439
> =====
>
> Is there a case where we *would* want a 10th degree polynomial fitted to
> only 4 distinct x values? A simple modification [changing 'length(x)'
> to 'length(unique(x))' in 2 places] seems to fix this:
> =====
> R> mypoly
> ...
> if (raw) {
> if (degree >= length(unique(x)))
> stop("'degree' must be less than number of points")
> ...
> if (is.null(coefs)) {
> if (degree >= length(unique(x)))
> stop("'degree' must be less than number of points")
> ...
>
> R> lm(y ~ mypoly(x, degree=10))
> Error in mypoly(x, degree = 10) :
> 'degree' must be less than number of points
> =====
>
> Russ
> --
> Russell V. Lenth, Professor
> Department of Statistics
> & Actuarial Science (319)335-0814 FAX (319)335-3017
> The University of Iowa russell-lenth at uiowa.edu
> Iowa City, IA 52242 USA http://www.stat.uiowa.edu/~rlenth/
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-devel
mailing list