[英]How to run a regression with a single explanatory variable and multiple dependent variables?
I want to use a single explanatory variable in a data frame to explain changes in a number of other variables. 我想在数据框中使用一个解释性变量来解释许多其他变量的变化。 The data frame looks something like:
数据框如下所示:
df:
explanatory_var dep_var_1 dep_var_2 dep_var_3
1 1.05 1.75 1.98
7 3.8 2.1 9.5
4.5 2 1.9 4
in pseudo code, I want to: 用伪代码,我想:
fit_df$coefficient <- lm((dep_var_1, dep_var_2, dep_var_3) ~ explanatory_variable, na.action = na.exclude)$coefficient
fit_df$intercept <- lm((dep_var_1, dep_var_2, dep_var_3) ~ explanatory_variable, na.action = na.exclude)$intercept
fit_df$coefficient_significance_code <- lm((dep_var_1, dep_var_2, dep_var_3) ~ explanatory_variable, na.action = na.exclude)$coefficient_significance_code
fit_df$intercept_significance_code <- lm((dep_var_1, dep_var_2, dep_var_3) ~ explanatory_variable, na.action = na.exclude)$intercept_significance_code
so that I end up with something like (data totally made up, doesn't fit the above, just an example) 这样我最终得到的是(数据完全组成,不符合以上条件,仅是示例)
fit_df:
variable coefficient intercept coefficient_significance_code intercept_significance_code
dep_var_1 .35 0.5 *** ***
dep_var_2 .5 0.75 *** ***
dep_var_3 .43 1.0 *** ***
I have what I believe to be the opposite of this question: Using R's lm on a dataframe with a list of predictors 我有一个与这个问题相反的结论:在具有预测变量列表的数据帧上使用R的lm
The answer seems like it is probably related to this: Repeat regression with varying dependent variable , but I am not creating my data frame, nor am I looking for an ls mean. 答案似乎可能与此有关: 使用不同的因变量重复进行回归 ,但是我不是在创建数据框,也不是在寻找均值。
if you are using a single explanatory variable to explain changes in multiple dependent variables, a manova might be more appropriate for the task. 如果您使用单个解释性变量来解释多个因变量的变化,那么manova可能更适合该任务。
Using your data, it might go something like this: 使用您的数据,它可能像这样:
exp_var <- c(1, 7, 4.5)
dep_var_1 <- c(1.05, 3.8, 2)
dep_var_2 <- c(1.75, 2.1, 1.9)
dep_var_3 <- c(1.98, 9.5, 4)
df <- data.frame(exp_var, dep_var_1, dep_var_2, dep_var_3)
model <- manova(cbind(dep_var_1,dep_var_2,dep_var_3) ~ exp_var, data = df)
summary(model)
By the way, there is not enough observations to run that code and it will result in an error. 顺便说一句,没有足够的观察结果来运行该代码,它将导致错误。 I hope that your dataset has plenty of observations.
我希望您的数据集能有很多观察结果。 Hope this helps!
希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.