简体   繁体   English

如何使用单个解释变量和多个因变量进行回归?

[英]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.

相关问题 循环对多个因变量进行回归 - Loop to run regression on multiple dependent variables 如何在数据集上运行线性回归,每次都将一个变量作为因变量? - How to run linear regression on a dataset, taking each time a single variable as the dependent variable? 多元Logistic回归与定量解释变量的相互作用 - Multiple Logistic Regression with Interaction between Quantitative and Qualitative Explanatory Variables 因变量与多个自变量之间的线性回归 - Linear regression between dependent variable with multiple independent variables 编写 function 以运行多个回归模型,其中自变量和因变量在 R 中发生变化 - Write a function to run multiple regression models with changing independent variables and changing dependent variables in R plot 各种解释变量对响应变量的影响如何 - How to plot the effects of various explanatory variables on the response variable 具有多个类别因变量的R中的非线性回归 - Nonlinear regression in R with multiple categorical dependent variables 具有许多因变量的多元多元线性回归 - Multivariate multiple linear regression with many dependent variables r gamlss:使用具有多个解释变量的回归预测 z 分数 - r gamlss: prediction of z-scores using regression with multiple explanatory variables 如何对所有不同解释变量组合在时间序列数据上的R,Excel / VBA中运行不同的多元线性回归? - How to run different multiple linear regressions in R, Excel/VBA on a time series data for all different combinations of Explanatory Variables?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM