每个模型中相同结果,相似数量的协变量和一个唯一协变量的线性回归 [英] Linear regression of same outcome, similar number of covariates and one unique covariate in each model
本文介绍了每个模型中相同结果,相似数量的协变量和一个唯一协变量的线性回归的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想对相同的结果以及每个模型中的多个协变量减去一个协变量进行线性回归.我已经看过了
I want to run linear regression for the same outcome and a number of covariates minus one covariate in each model. I have looked at the example on this page but could that did not provide what I wanted.
样本数据
a <- data.frame(y = c(30,12,18), x1 = c(7,6,9), x2 = c(6,8,5),
x3 = c(4,-2,-3), x4 = c(8,3,-3), x5 = c(4,-4,-2))
m1 <- lm(y ~ x1 + x4 + x5, data = a)
m2 <- lm(y ~ x2 + x4 + x5, data = a)
m3 <- lm(y ~ x3 + x4 + x5, data = a)
如何在短时间内运行这些模型,而又不一次又一次重复相同的协变量?
How could I run these models in a short way and and without repeating the same covariates again and again?
推荐答案
Following this example you could do this:
lapply(1:3, function(i){
lm(as.formula(sprintf("y ~ x%i + x4 + x5", i)), a)
})
这篇关于每个模型中相同结果,相似数量的协变量和一个唯一协变量的线性回归的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文