R 自动从线性模型中删除不重要项

R 自动从线性模型中删除不重要项,r,lm,anova,R,Lm,Anova,我正在研究一个包含分类和连续自变量的数据集,希望找出最小适当模型是什么 这是起始模型: mod1 <- lm(Richness ~ Distances*Flower*Veg*Canopy*factor(Vines), data = Data) anova(mod1) mod1按照@nongkrong关于步骤的建议,我想我找到了一个解决方案: model.null = lm(Abundance ~ 1, data=data) #define the null mod

我正在研究一个包含分类和连续自变量的数据集,希望找出最小适当模型是什么

这是起始模型:

mod1 <- lm(Richness ~ Distances*Flower*Veg*Canopy*factor(Vines), data = Data)
anova(mod1)

mod1按照@nongkrong关于
步骤的建议,我想我找到了一个解决方案:

model.null = lm(Abundance ~ 1,
            data=data) #define the null model#
model.full = lm(Abundance ~ Distances*Flower*Veg*Canopy*factor(Vines), 
            data = data) #define the max model#

step(model.full, #start at the full model#
 scope = list(lower = model.null), # the lower limit of model it can produce#
 direction = "backward", #work by deleting terms until you get to the minimum model #
 data = data
)

到目前为止,这似乎是可行的,如果有人发现此代码有问题,请发表评论。

在ISLR视频中,实际上有一个非常有用的关于模型选择的讨论。更妙的是,最后4个视频提供了使用R:Yes<代码>步骤
正是我想要的,谢谢@nongkrog@nongkrong,作为答案发布?@BenBolker我想我通过nongkrong的建议找到了解决方案,并将其作为答案发布。
model.null = lm(Abundance ~ 1,
            data=data) #define the null model#
model.full = lm(Abundance ~ Distances*Flower*Veg*Canopy*factor(Vines), 
            data = data) #define the max model#

step(model.full, #start at the full model#
 scope = list(lower = model.null), # the lower limit of model it can produce#
 direction = "backward", #work by deleting terms until you get to the minimum model #
 data = data
)