1
library(splines)
x <- runif(100000)
spline <- ns(x, df=5)
如何判斷這個脊柱對象中的結是哪裏?從ns對象中提取結
> 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"
感謝。我嘗試了'spline $ knots','spline @ knots','spline ['knots']'和'spline [['knots']]''。我忘了''attr' ... – Zach 2012-02-16 21:39:34
@Zach,attrs的使用非常清楚你已經顯示的str()輸出。所以,不要蠻力,但看看輸出:) – 2012-02-17 07:28:14
@ Anton--我以前沒有遇到'attr()'函數,所以它沒有出現在我身上,那是'str'告訴我。 – Zach 2012-02-17 12:32:50