从 ns 对象中提取结

发布于 2025-01-06 04:07:15 字数 705 浏览 2 评论 0原文

library(splines)
x <- runif(100000)
spline <- ns(x, df=5)

我如何判断这个脊柱对象中的结在哪里?

> spline ['knots']
[1] NA

str 让我接近我所需要的,但我希望能够提取样条向量、格式化它,并将其打印在 Sweave 文档中。

> str(sp)
 ns [1:117542, 1:5] 0.527 0.474 0.455 0.472 0.498 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:5] "1" "2" "3" "4" ...
 - attr(*, "degree")= num 3
 - attr(*, "knots")= Named num [1:4] 1.03 1.55 1.99 2.7
  ..- attr(*, "names")= chr [1:4] "20%" "40%" "60%" "80%"
 - attr(*, "Boundary.knots")= num [1:2] 0.0214 4.9999
 - attr(*, "intercept")= logi FALSE
 - attr(*, "class")= chr [1:3] "ns" "basis" "matrix"
library(splines)
x <- runif(100000)
spline <- ns(x, df=5)

How do I tell where the knots are in this spine object?

> spline ['knots']
[1] NA

str gets me close to what I need, but I'd like to be able to extract the vector of splines, format it, and print it in an Sweave document.

> str(sp)
 ns [1:117542, 1:5] 0.527 0.474 0.455 0.472 0.498 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:5] "1" "2" "3" "4" ...
 - attr(*, "degree")= num 3
 - attr(*, "knots")= Named num [1:4] 1.03 1.55 1.99 2.7
  ..- attr(*, "names")= chr [1:4] "20%" "40%" "60%" "80%"
 - attr(*, "Boundary.knots")= num [1:2] 0.0214 4.9999
 - attr(*, "intercept")= logi FALSE
 - attr(*, "class")= chr [1:3] "ns" "basis" "matrix"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

維他命╮ 2025-01-13 04:07:15

嗯,像这样的东西肯定可以提取出这些东西:

> attr(spline, "knots")
      20%       40%       60%       80% 
0.1966951 0.3973261 0.5982386 0.7993613 

Well, something like this can definitely extract the stuff:

> attr(spline, "knots")
      20%       40%       60%       80% 
0.1966951 0.3973261 0.5982386 0.7993613 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文