从R中的bs(b样条)函数输出中提取矩阵

时间:2016-08-09 11:18:17

标签: r matrix bspline

x = c(1, 2, 3)成为一个向量。我在bs的{​​{1}}包中使用splines函数生成在R评估的B样条矩阵。

x

输出require(splines) x <- c(1, 2, 3) bs.x <- bs(x, knots = c(1.5, 2.5)) 如下,

bs.x

显然,除基础矩阵外, 1 2 3 4 5 [1,] 0.00000000 0.0000000 0.0000000 0.00000000 0 [2,] 0.05555556 0.4444444 0.4444444 0.05555556 0 [3,] 0.00000000 0.0000000 0.0000000 0.00000000 1 attr(,"degree") [1] 3 attr(,"knots") [1] 1.5 2.5 attr(,"Boundary.knots") [1] 1 3 attr(,"intercept") [1] FALSE attr(,"class") [1] "bs" "basis" "matrix" 还有其他属性。 我的问题是如何摆脱这些属性。我需要这样做,因为最终,我需要运行bs.x,这会抛出以下错误消息。

Matrix(bs.x)

我想这是因为Error in as(x, "matrix") : internal problem in as(): “bs” is(object, "matrix") is TRUE, but the metadata asserts that the 'is' relation is FALSE matrix所属的类之一。此刻,我做了以下愚蠢的事情。

bs.x

有更好的选择吗?提前谢谢。

1 个答案:

答案 0 :(得分:1)

不是更好,但

attributes(bs.x) <- attributes(bs.x)["dim"]

似乎有效。 (将bs.x的属性重新指定为 dim属性。)

相关问题