绘制带结的自然三次样条曲线时出错

Error when plotting natural cubic spline with knots

library(splines)
set.seed(3)
x <- rnorm(100)
plot(x)
lines(ns(x))

这很好用,但如果我尝试添加特定的结,即

lines(ns(x, knots = c(1, 2, 3, 50)))

运行 上面的代码给我以下错误:

Error in qr.default(t(const)) : 
  NA/NaN/Inf in foreign function call (arg 1)

编辑:

根据 Peter 的建议,50 处的结太大了,所以我将代码修改为:

> lines(ns(x, knots = sort(x, decreasing = TRUE)[1:10]))
Error in qr.default(t(const)) : 
      NA/NaN/Inf in foreign function call (arg 1)

现在我想在 x 的 10 个最高值处设置 10 节。但我仍然收到错误?这是为什么?

50 太大了。 x 是均值 0 和 sd 1 的正态分布。因此,例如

lines(ns(x, knots = c(1, 1.5)))

工作正常。 (无用的 R 错误消息的另一个示例)。