Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is `poly` complaining about degree less than number of unique points?

I am trying to generate orthogonal polynomials in R, but I keep getting an error I don't understand

> poly(1:1000, 50)
Error in poly(1:1000, 50) : 
  'degree' must be less than number of unique points

Surely the number of unique points is 1000? What does it mean? Is this a bug, and if so does anyone know I work around?

Edit: This appears to kick in for degree > 27 for any number of points - is this an undocumented limit?

like image 406
Corvus Avatar asked Aug 01 '13 15:08

Corvus


1 Answers

Numerical overflow. If you look at the code for poly, you'll see it's generating the individual polynomial terms as an intermediate step:

X <- outer(x, seq_len(n) - 1, "^")

and when n (the degree of the polynomial you want) is 50, the resulting terms go up to 1e132.

like image 73
Hong Ooi Avatar answered Nov 14 '22 14:11

Hong Ooi