自动使用LRT评估整个因素变量的显着性 [英] Automatically use LRT to assess significance of entire factor variable
本文介绍了自动使用LRT评估整个因素变量的显着性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
fake = data.frame( x1=rnorm(100), x2=sample(LETTERS[1:4],
size=100, replace=TRUE), y=rnorm(100) )
head(fake)
x1 x2 y
1 0.6152511 A 0.7682467
2 -0.8215727 A -0.5389245
3 -1.3287208 A -0.1797851
4 0.5837217 D 0.9509888
5 -0.2828024 C -0.9829126
6 0.3971358 B -0.4895091
m = lm(fake$y ~ fake$x1 + fake$x2)
summary(m)
如果我们要测试模型中整个变量x2
的显着性,可以拟合简化的模型m.red
并使用LRT:
m.red = lm(fake$y ~ fake$x1)
anova(m, m.red, test="LRT")
但是,如果模型中有许多因子变量,那么一遍又一遍地做起来就变得很荒谬.我必须相信有一些内置方法?
解决方案
我认为您正在寻找drop1
:
drop1(m,test="Chisq")
## Single term deletions
## Model:
## fake$y ~ fake$x1 + fake$x2
## Df Sum of Sq RSS AIC Pr(>Chi)
## <none> 79.814 -12.547
## fake$x1 1 0.33741 80.152 -14.125 0.5160
## fake$x2 3 2.88510 82.699 -14.996 0.3142
R's output for a multivariable regression model including one or more factor variable does not automatically include a likelihood ratio test (LRT) of the significance of the entire factor variable in the model. For example:
fake = data.frame( x1=rnorm(100), x2=sample(LETTERS[1:4],
size=100, replace=TRUE), y=rnorm(100) )
head(fake)
x1 x2 y
1 0.6152511 A 0.7682467
2 -0.8215727 A -0.5389245
3 -1.3287208 A -0.1797851
4 0.5837217 D 0.9509888
5 -0.2828024 C -0.9829126
6 0.3971358 B -0.4895091
m = lm(fake$y ~ fake$x1 + fake$x2)
summary(m)
If we want to test the significance of the entire variable x2
in the model, we can fit a reduced model m.red
and use the LRT:
m.red = lm(fake$y ~ fake$x1)
anova(m, m.red, test="LRT")
But if you have many factor variables in a model, doing this over and over becomes ridiculous. I have to believe there is some built-in approach?
解决方案
I think you're looking for drop1
:
drop1(m,test="Chisq")
## Single term deletions
## Model:
## fake$y ~ fake$x1 + fake$x2
## Df Sum of Sq RSS AIC Pr(>Chi)
## <none> 79.814 -12.547
## fake$x1 1 0.33741 80.152 -14.125 0.5160
## fake$x2 3 2.88510 82.699 -14.996 0.3142
这篇关于自动使用LRT评估整个因素变量的显着性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文