[英]Extract GAM Model Object
假設我通過這樣做來創建我的 GAM 模型:
a <- runif(10)
b <- runif(10)
gm <- gam(a ~ ns(b, df=2))
plot(gm, all.terms=T, shade=T)
我需要的是訪問gm
的元素,以便獲取包含以紅色突出顯示的點的列表或數據框。
通過查看summary(gm)
和names(gm)
的輸出,我找不到包含此類數據的字段。
> summary(gm)
Family: gaussian
Link function: identity
Formula:
a ~ ns(b, df = 2)
Parametric coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.5390 0.1524 3.536 0.00952 **
ns(b, df = 2)1 0.4935 0.4242 1.163 0.28284
ns(b, df = 2)2 -0.2203 0.2603 -0.846 0.42529
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
R-sq.(adj) = -0.0585 Deviance explained = 17.7%
GCV = 0.077126 Scale est. = 0.053988 n = 10
和
> names(gm)
[1] "coefficients" "residuals" "fitted.values" "family" "linear.predictors"
[6] "deviance" "null.deviance" "iter" "weights" "prior.weights"
[11] "df.null" "y" "converged" "sig2" "edf"
[16] "edf1" "hat" "R" "boundary" "sp"
[21] "nsdf" "Ve" "Vp" "rV" "mgcv.conv"
[26] "gcv.ubre" "aic" "rank" "gcv.ubre.dev" "scale.estimated"
[31] "method" "smooth" "formula" "var.summary" "cmX"
[36] "model" "control" "terms" "pred.formula" "pterms"
[41] "assign" "xlevels" "offset" "df.residual" "min.edf"
[46] "optimizer" "call"
檢查utils::str
(而不是使用summary
)-它為您提供對象的結構。
我認為gm$model
就是你要找的。
gm$model
a ns(b, df = 2).1 ns(b, df = 2).2
1 0.69342149 0.07841860 -0.05184526
2 0.23538533 0.52006793 0.20238728
3 0.47125666 0.24808303 -0.15840080
4 0.04405890 0.00000000 0.00000000
5 0.54696387 0.34211652 0.77302788
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.