为什么
例子:
ns(0.8)
或 ns(c(0.8))
返回 NA/NaN/在外部函数调用中使用的参数1中存在无限值
?
ns(c(0.8, 1.0))
可以正常工作,但我想知道为什么只给 ns
提供一个值会导致 NA/NaN/在外部函数调用中使用的参数1中存在无限值
。例子:
> library(splines)
> ns(0.8)
Error in qr.default(t(const)) :
NA/NaN/Inf in foreign function call (arg 1)
> ns(c(0.8, 1.0))
1
[1,] 0.0000000
[2,] 0.8017837
attr(,"degree")
[1] 3
attr(,"knots")
numeric(0)
attr(,"Boundary.knots")
[1] 0.8 1.0
attr(,"intercept")
[1] FALSE
attr(,"class")
[1] "ns" "basis" "matrix"
ns()
函数的结果取决于第一个参数,因为它可以用来确定节点的位置(包括边界节点)。只有一个数据点是不足以提供足够信息做出明智的选择,因此该方法失败是合理的。 - stephematician