2017-10-13 124 views
1

假設我做這個創造我的GAM模型:提取GAM模型對象

a <- runif(10) 
b <- runif(10) 
gm <- gam(a ~ ns(b, df=2)) 
plot(gm, all.terms=T, shade=T) 

然後我得到下面的情節: enter image description here

我需要的是能夠訪問的gm的元素,在什麼爲了獲得包含以紅色突出顯示的點的列表或數據框。 enter image description here

通過查看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" 

回答

1

檢查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 
+0

偉大的方向。但我仍然無法重現以紅色突出顯示的功能 – ruggfrancesco