使用tidyverse和broom的许多回归:相同的因变量,不同的自变量

问题描述 投票:0回答:2

此链接显示了在我们具有相同的自变量但可能有许多不同的因变量的情况下如何回答我的问题:Use broom and tidyverse to run regressions on different dependent variables

但是我的问题是,我如何应用相同的方法(例如,tidyverse和broom)来进行许多回归,但情况却相反:因变量相同而自变量不同。与上一个链接中的代码一致,类似:

mod = lm(health ~ cbind(sex,income,happiness) + faculty, ds) %>% tidy()

但是,此代码无法完全实现我想要的,而是产生了:

Call:
lm(formula = income ~ cbind(sex, health) + faculty, data = ds)

Coefficients:
             (Intercept)     cbind(sex, health)sex  
                 945.049                   -47.911  
cbind(sex, health)health                   faculty  
                   2.342                     1.869 

相当于:

lm(formula = income ~ sex + health + faculty, data = ds)
r dplyr tidyverse lm broom
2个回答
1
投票

基本上,您将需要某种方式来创建所需的所有不同公式。这是一种方法


0
投票

您可以使用combn函数获取n

© www.soinside.com 2019 - 2024. All rights reserved.