简体   繁体   English

使用R中的glm在多变量分析中计算R平方

[英]calculating R-squared in a multivariate analysis using glm in R

I am doing a backward elimination in R using the step() function. 我正在使用step()函数在R中进行向后消除。 Now, I am trying to look at how each independent variable is ranked together with their AIC, F, and P values. 现在,我正在尝试查看每个自变量及其AIC,F和P值的排名方式。

step(Mod1,direction="backward",test="F")

                      Df Deviance    AIC  F value    Pr(>F)    
<none>                     6127.4 6215.4                       
- as.factor(var2)      3   6133.6 6215.6   2.6103 0.0497127 *  
- as.factor(var28)     2   6131.7 6215.7   2.7292 0.0653326 .  
- as.factor(var32)     2   6131.8 6215.8   2.7794 0.0621388 .  
- as.factor(var30)     1   6130.3 6216.3   3.6075 0.0575550 .  
- as.factor(var20)     1   6131.9 6217.9   5.7262 0.0167368 *  
- as.factor(var9)      1   6133.5 6219.5   7.6627 0.0056507 ** 
- as.factor(var15)     1   6133.7 6219.7   7.8952 0.0049691 ** 
- as.factor(var10)     1   6133.8 6219.8   8.1314 0.0043621 ** 
- as.factor(var14)     1   6134.7 6220.7   9.2528 0.0023592 ** 
- as.factor(var33)     2   6137.1 6221.1   6.0993 0.0022552 ** 
- as.factor(var16)     1   6135.9 6221.9  10.6794 0.0010881 ** 
- as.factor(var19)     4   6142.5 6222.5   4.7684 0.0007674 ***
- as.factor(var23)     2   6138.9 6222.9   7.2488 0.0007158 ***
- as.factor(var24)     2   6139.0 6223.0   7.3060 0.0006761 ***
- as.factor(var13)     1   6139.3 6225.3  14.9746 0.0001099 ***
- as.factor(var11)     1   6141.0 6227.0  17.1558 3.480e-05 ***
- as.factor(var6)      2   6149.3 6233.3  13.8110 1.030e-06 ***
- as.factor(var22)     2   6150.6 6234.6  14.6341 4.534e-07 ***
- as.factor(var8)      4   6155.4 6235.4   8.8624 3.893e-07 ***
- as.factor(var3)      4   6172.7 6252.7  14.3214 1.189e-11 ***
- as.factor(var1)      1   6230.8 6316.8 130.7555 < 2.2e-16 ***
- as.factor(var5)      4   6245.6 6325.6  37.3782 < 2.2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

Next, I would like to 接下来,我想

i) rank variables according to p-values from most (top) to less significant (bottom) i)根据p值从最高(最高)到最低有效(最低)对变量进行排名

ii) get the R-squared for each independent variable and to be shown in the last column ii)获得每个自变量的R平方,并在最后一栏中显示

Save the results as a model. 将结果另存为模型。

final_model <- step(Mod1,direction="backward",test="F")
# drop1 will give you the "type II anova" (the effect of dropping)
drop_anova <- drop1(final_model, test = 'F')
#  or the more traditional `anova` which gives the SS as 
# if they are sequentially  added to the model
anova(final_model)

You can use these to rank by p-value. 您可以使用它们按p值进行排名。 See my comment regarding r-squared for each variable -- I don't know what you mean by this. 请参阅我对每个变量的r平方的评论-我不知道您的意思是什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM