12

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?

Corvus
  • 7,548
  • 9
  • 42
  • 68
  • 3
    Out of curiosity, why are you wanting to generate a 50th order polynomial? I sincerely hope it is not for modeling... – Justin Aug 01 '13 at 16:00
  • 1
    No it's not for modelling, but now you put it like that, I'm feeling less surprised that it doesn't work for 50! I was so engrossed in what I was doing I forgot about what most people probably use this function for. (It's a bit complex to explain briefly, but it is to do with generating random analytic functions over an interval) – Corvus Aug 01 '13 at 16:06

1 Answers1

15

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.

Hong Ooi
  • 56,353
  • 13
  • 134
  • 187
  • Great thanks - I can't complain, as Justin pointed out above, this isn't really the target usage for this function! – Corvus Aug 01 '13 at 16:09