1

モデル内のすべての変数の予測値 (標準化されていない実際の値) を追加する方法を探しています

> model<-gam(LN_Brutto~s(agecont,by=Sex)+factor(Sex)+te(Month,Age)+s(Month,by=Sex), data=bears)

これは私のモデルの要約です:

> summary(m13)

Family: gaussian 
Link function: identity 

Formula:
LN_Brutto ~ s(agecont, by = Sex) + factor(Sex) + te(Month, Age) + 
    s(Month, by = Sex)

Parametric coefficients:
             Estimate Std. Error t value Pr(>|t|)    
(Intercept)   4.32057    0.01071  403.34   <2e-16 ***
factor(Sex)m  0.27708    0.01376   20.14   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Approximate significance of smooth terms:
                    edf  Ref.df      F  p-value    
s(agecont):Sexf  8.1611  8.7526 20.170  < 2e-16 ***
s(agecont):Sexm  6.6695  7.5523 32.689  < 2e-16 ***
te(Month,Age)   10.3651 12.7201  6.784 2.19e-12 ***
s(Month):Sexf    0.9701  0.9701  0.641    0.430    
s(Month):Sexm    1.3750  1.6855  0.193    0.787    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Rank: 60/62
R-sq.(adj) =  0.781   Deviance explained = 78.7%
GCV = 0.048221  Scale est. = 0.046918  n = 1093

予測値は、次のコードによって提供されます。

> predict<-predict(m13, type = "terms")

結果は次のようになります。

    factor(Sex) s(agecont):Sexf s(agecont):Sexm te(Month,Age)   s(Month):Sexf   s(Month):Sexm
1   0.2770806   0.000000000     0.111763696     -0.077845764    0.000000000     0.0007840912
2   0.2770806   0.000000000     0.240016156     -0.049143798    0.000000000     0.0007840912
3   0.2770806   0.000000000     0.034328752     0.046524454     0.000000000     -0.0058871897
4   0.0000000   -0.786533918    0.000000000     -0.067942427    0.021990192     0.0000000000
5   0.0000000   0.074434715     0.000000000     0.046524454     0.021990192     0.0000000000
6   0.0000000   0.161121563     0.000000000     0.089599601     0.021990192     0.0000000000
7   0.0000000   0.074434715     0.000000000     0.046524454     0.021990192     0.0000000000
8   0.2770806   0.000000000     -0.298597370    -0.007877328    0.000000000     -0.0058871897
...

しかし、これらは標準化された予測値であり、実際の値ではないと思います (実際の値には負の値があってはなりません!?)。

実際の値を取得するために、コードで何を変更する必要があるかを誰かが知っていますか? 何か案が?ありがとうございました!

4

2 に答える 2

2

私があなたを正しくフォローしているかどうかはよくわかりませpredict(model, type = "terms")んが、あなたが探している解決策かもしれません.

アップデート

これらは標準化されていないと思います。おそらく、係数のいくつかは単に負です。

ヘルプ ファイルの例を考えてみましょう?mgcv:::predict.gam

library(mgcv)
n<-200
sig <- 2
dat <- gamSim(1,n=n,scale=sig)

b<-gam(y~s(x0)+s(I(x1^2))+s(x2)+offset(x3),data=dat)

以下の結果は、これらが実際には、各予測子が適合値を計算するために使用されている寄与であることを示しています (これらの寄与のそれぞれの合計を計算し、切片とオフセットを加算することによって)。

> head(predict(b))
        1         2         3         4         5         6 
 9.263322  2.822200  7.137201  4.902631 14.558401 11.889092 
> head(rowSums(predict(b, type = "terms")) + attr(predict(b, type = "terms"), "constant") + dat$x3)
        1         2         3         4         5         6 
 9.263322  2.822200  7.137201  4.902631 14.558401 11.889092 
于 2014-11-19T16:04:33.147 に答える