如何在不手动计算标准误差的情况下打印 R 中 lm 的方差? [英] How do I print the variance of an lm in R without computing from the Standard Error by hand?

查看:61
本文介绍了如何在不手动计算标准误差的情况下打印 R 中 lm 的方差?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

真的很简单的问题!我正在运行许多 y~x 的线性回归,并希望获得每个回归的方差,而无需从 summary.lm 中给出的标准误差输出中手动计算它命令.只是为了节省一点时间:-).执行此操作的命令的任何想法?还是我必须自己写一个函数来完成?

Simple question really! I am running lots of linear regressions of y~x and want to obtain the variance for each regression without computing it from hand from the Standard Error output given in the summary.lm command. Just to save a bit of time :-). Any ideas of the command to do this? Or will I have to write a function to do it myself?

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 

所以我得到一个标准错误输出,我希望得到一个方差输出而不需要手工计算......

So I get a Standard Error output and I was hoping to get a Variance output without calculating it by hand...

推荐答案

我不确定你想要什么差异.

I'm not sure what you want the variance of.

如果你想要残差方差,它是:(summary(m)$sigma)**2.

If you want the residual variance, it's: (summary(m)$sigma)**2.

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

If you want the variance of your slope, it's: (summary(m)$coefficients[2,2])**2, or vcov(m)[2,2].

这篇关于如何在不手动计算标准误差的情况下打印 R 中 lm 的方差?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆