2011-12-13 26 views
10

我做了glm,我只是想提取每個係數的標準錯誤。我在網上看到功能se.coef()但它不起作用,它返回"Error: could not find function "se.coef""從glm中提取標準錯誤

+0

可能有助於提供一些數據和示例代碼。 – screechOwl 2011-12-13 21:01:16

回答

21

您所追求的信息存儲在由summary()返回的coefficients對象中。您可正是如此解壓:summary(glm.D93)$coefficients[, 2]

#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 

看看names(summary(glm.D93))爲返回,一切都快速審查。如果您想查看正在進行的特定計算,則可以通過查看summary.glm來找到更多詳細信息,儘管可能每次都不需要詳細級別的詳細信息,除非您有統計信息。

+1

標準錯誤是否存儲在`glm.D93`對象中?我無法用`str()`來注視它。或者`summary()`明確計算錯誤? – 2011-12-14 12:40:44

+2

@ mindless.panda - AFAIK它們是由`summary.glm`直接計算出來的。如果你在控制檯輸入函數sans`()`,然後向下滾動約25行,你會看到它的計算位置。 – Chase 2011-12-14 15:12:55

17

另一種方式:

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