2011-12-13 17 views
10

私はglmを実行しましたが、各係数の標準誤差を抽出したいだけです。私はインターネット上で関数se.coef()を見ましたが、それは動作しません、それは"Error: could not find function "se.coef""を返します。glmから標準エラーを抽出

+0

いくつかのデータとサンプルコードを載せるのに役立つかもしれない。 – screechOwl

答えて

21

お客様の情報は、summary()で返されたcoefficientsオブジェクトに保存されています。あなたはthusly、それを抽出することができます。

#Example from ?glm 
counts <- c(18,17,15,20,10,20,25,13,12) 
outcome <- gl(3,1,9) 
treatment <- gl(3,3) 
print(d.AD <- data.frame(treatment, outcome, counts)) 
glm.D93 <- glm(counts ~ outcome + treatment, family=poisson()) 

#coefficients has the data of interest 
> summary(glm.D93)$coefficients 
       Estimate Std. Error  z value  Pr(>|z|) 
(Intercept) 3.044522e+00 0.1708987 1.781478e+01 5.426767e-71 
outcome2 -4.542553e-01 0.2021708 -2.246889e+00 2.464711e-02 
outcome3 -2.929871e-01 0.1927423 -1.520097e+00 1.284865e-01 
treatment2 1.337909e-15 0.2000000 6.689547e-15 1.000000e+00 
treatment3 1.421085e-15 0.2000000 7.105427e-15 1.000000e+00 

#So extract the second column 
> summary(glm.D93)$coefficients[, 2] 
(Intercept) outcome2 outcome3 treatment2 treatment3 
    0.1708987 0.2021708 0.1927423 0.2000000 0.2000000 

summary(glm.D93)$coefficients[, 2]が返されたすべてのクイックレビューのためにnames(summary(glm.D93))を見てみましょう。具体的な計算を表示したい場合はsummary.glmをチェックすると詳細がわかりますが、< 3統計情報を除いて、毎回その詳細レベルは必要ない可能性があります。

+1

標準エラーは 'glm.D93'オブジェクトに保存されていますか? 'str()'を使って眼球を見ることができませんでした。あるいは、 'summary()'は明示的にエラーを計算しますか? –

+2

@ mindless.panda - AFAIK彼らは 'summary.glm'によって直接計算されます。あなたのコンソールに関数を入力して '()'を押して、約25行をスクロールすると、計算された場所が表示されます。 – Chase

17

別の方法:

sqrt(diag(vcov(glm.D93))) 
+0

これは美しく、純粋でシンプルです。 – zx8754

関連する問題