簡體   English   中英

由線性回歸中的每個變量解釋的結果方差比例

[英]Proportion of variance of outcome explained by each variable in a linear regression

在下面找到的示例數據集中,我想使用線性回歸模型計算由每個自變量解釋的科學方差比例。 我如何在R中實現呢?

hsb2 <- read.table('http://www.ats.ucla.edu/stat/r/modules/hsb2.csv', header=T, sep=",")

m1<-lm(science ~ math+female+ socst+ read, data =hsb2)

一種方法是使用stats包中的anova()函數。 它為您提供了每個變量說明的殘差平方和和平方和(即方差)

anova(m1)
 Analysis of Variance Table

 Response: science
           Df Sum Sq Mean Sq  F value    Pr(>F)    
math        1 7760.6  7760.6 151.8810 < 2.2e-16 ***
female      1  233.0   233.0   4.5599  0.033977 *  
socst       1  465.6   465.6   9.1128  0.002878 ** 
read        1 1084.5  1084.5  21.2254 7.363e-06 ***
Residuals 195 9963.8    51.1                       
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

暫無
暫無

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

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