有可能解決這一更有效的方法,但這裏有一個起點,讓你建立實施羅蘭簡要建議的策略。該summ
對象有定義樣條函數所需的信息,但它是一種葬
names(summ)
[1] "call" "terms" "family" "deviance" "aic"
[6] "contrasts" "df.residual" "null.deviance" "df.null" "iter"
[11] "deviance.resid" "coefficients" "aliased" "dispersion" "df"
[16] "cov.unscaled" "cov.scaled"
而綜觀目前terms
葉的結構,我們看到花細節埋設較深仍在predvars
subleaf內:
str(summ$terms)
Classes 'terms', 'formula' language y ~ x + ns(z, df = 2) + k
..- attr(*, "variables")= language list(y, x, ns(z, df = 2), k)
..- attr(*, "factors")= int [1:4, 1:3] 0 1 0 0 0 0 1 0 0 0 ...
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:4] "y" "x" "ns(z, df = 2)" "k"
.. .. ..$ : chr [1:3] "x" "ns(z, df = 2)" "k"
..- attr(*, "term.labels")= chr [1:3] "x" "ns(z, df = 2)" "k"
..- attr(*, "order")= int [1:3] 1 1 1
..- attr(*, "intercept")= int 1
..- attr(*, "response")= int 1
..- attr(*, ".Environment")=<environment: R_GlobalEnv>
..- attr(*, "predvars")= language list(y, x, ns(z, knots = structure(0.514993450604379, .Names = "50%"), Boundary.knots = c(0.00118412892334163, 0.99828373757191), intercept = FALSE), k)
..- attr(*, "dataClasses")= Named chr [1:4] "numeric" "numeric" "nmatrix.2" "factor"
.. ..- attr(*, "names")= chr [1:4] "y" "x" "ns(z, df = 2)" "k"
所以拉出來的屬性:
str(attributes(summ$terms)$predvars)
language list(y, x, ns(z, knots = structure(0.514993450604379, .Names = "50%"),
Boundary.knots = c(0.00118412892334163, 0.99828373757191), intercept = FALSE), k)
你可以看到它是PO ssible如果你提供所需的X,Y,Z,和k值恢復花:
with(dat, ns(z, knots = 0.514993450604379, Boundary.knots = c(0.00118412892334163,
0.99828373757191), intercept = FALSE))
#---
1 2
[1,] 5.760419e-01 -1.752762e-01
[2,] 2.467001e-01 -1.598936e-01
[3,] 4.392684e-01 4.799757e-01
snipping ....
[498,] 4.965628e-01 -2.576437e-01
[499,] 5.627389e-01 1.738909e-02
[500,] 2.393920e-02 -1.611872e-02
attr(,"degree")
[1] 3
attr(,"knots")
[1] 0.5149935
attr(,"Boundary.knots")
[1] 0.001184129 0.998283738
attr(,"intercept")
[1] FALSE
attr(,"class")
[1] "ns" "basis" "matrix"
您可以構建一個替代dat
,如果你知道你的數據的極端。請參閱?ns
及其鏈接的其他幫助頁面。
http://stats.stackexchange.com/a/101484/11849 – Roland
如果您使用的功能htat不在基本集中,您應該始終添加所需的庫調用。 –