如何建模R中自变量之间的所有关系? [英] how to model all relationships between independent variables in R?

查看:88
本文介绍了如何建模R中自变量之间的所有关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小型数据集,其中包含4个独立变量(分别称为a,b,c,d)和1个因变量.由于自变量很少,因此我想探索这些变量的所有组合.只能有14个模型(a,b,c,d,a + b,a + c,a + d,b + c,b + d,c + d,a + b + c,a + b + d ,b + c + d,a + b + c + d). 我手动建立所有模型,这很耗时.因此,我想使其自动化. R中有可能吗?

I have a small data set with 4 independent (call them a, b, c, d) and 1 dependent variables. Since there are few independent variables, I want to explore all combinations of these variables. There can be only 14 models (a, b, c, d, a+b, a+c, a+d, b+c, b+d, c+d, a+b+c, a+b+d, b+c+d, a+b+c+d). I build all models by hand and it is time-consuming. Therefore I want to automatize it. Is it possible in R?

glm(dep〜a,family ="binomial",数据=数据) glm(dep〜b + c,family ="binomial",数据=数据) 等等

glm(dep ~ a, family = "binomial", data = data) glm(dep ~ b + c, family = "binomial", data = data) etc

推荐答案

使用内置的anscombe数据框,将找到最佳组合(尽管如今不建议逐步回归,而希望使用套索,elasticnet和其他类似方法基于惩罚).

Using the builtin anscombe data frame, this will find the best combination (although stepwise regression is discouraged these days in favour of lasso, elasticnet and other similar approaches based on penalization).

fm <- glm(y1 ~ x1 + x2 + x3 + x4, data = anscombe)
step(fm)

另请参阅jumps和glmnet软件包.

Also see the leaps and glmnet packages.

这篇关于如何建模R中自变量之间的所有关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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