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

大憨熊 提交于 2019-12-21 09:15:02

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/17998919/why-is-poly-complaining-about-degree-less-than-number-of-unique-points

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!