簡體   English   中英

如何在不手動計算標准誤差的情況下打印 R 中 lm 的方差?

[英]How do I print the variance of an lm in R without computing from the Standard Error by hand?

真的很簡單的問題! 我正在運行大量y~x的線性回歸,並希望獲得每個回歸的方差,而無需根據summary.lm命令中給出的標准誤差輸出手動計算它。 只是為了節省一點時間:-)。 執行此操作的命令的任何想法? 還是我必須編寫一個函數來自己做?

m<-lm(Alopecurus.geniculatus~Year)
> summary(m)

Call:
lm(formula = Alopecurus.geniculatus ~ Year)

Residuals:
    Min      1Q  Median      3Q     Max 
-19.374  -8.667  -2.094   9.601  21.832 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)  
(Intercept) 700.3921   302.2936   2.317   0.0275 *
Year         -0.2757     0.1530  -1.802   0.0817 .
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

Residual standard error: 11.45 on 30 degrees of freedom
  (15 observations deleted due to missingness)
Multiple R-squared: 0.09762,    Adjusted R-squared: 0.06754 
F-statistic: 3.246 on 1 and 30 DF,  p-value: 0.08168 

所以我得到一個標准錯誤輸出,我希望在不手動計算的情況下得到一個方差輸出......

我不確定你想要什么方差。

如果您想要殘差方差, (summary(m)$sigma)**2(summary(m)$sigma)**2

如果您想要斜率的方差, (summary(m)$coefficients[2,2])**2(summary(m)$coefficients[2,2])**2vcov(m)[2,2]

vcov(m)

給出系數的協方差矩陣——對角線上的方差。

如果你指的是系數估計的標准誤差,答案是

summary(m)$coef[,2] 

如果你指的是估計的殘差方差,那就是

summary(m)$sigma

鍵入names( summary(m) )names(m)以獲取您可以訪問的其他信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM