[英]How to run a linear regression using lm() on a subset in R after multiple imputation using MICE
I want to run a linear regression analysis on my multiple imputed data.我想对我的多重插补数据进行线性回归分析。 I imputed my dataset using mice.
我使用老鼠估算了我的数据集。 The formula I used to run a linear regression on my whole imputed set is as follows:
我用来在整个估算集上运行线性回归的公式如下:
mod1 <-with(imp, lm(outc ~ age + sex))
pool_mod1 <- pool(mod1)
summary(pool_mod1)
This works fine.这工作正常。 Now I want to create a subset of BMI, by saying: I want to apply this regression analysis to the group of people with a BMI below 30 and to the group of people with a BMI above or equal to 30. I tried to do the following:
现在我想创建一个 BMI 的子集,说:我想将此回归分析应用于 BMI 低于 30 的人群和 BMI 高于或等于 30 的人群。我试图做下列的:
mod2 <-with(imp, lm(outc ~ age + sex), subset=(bmi<30))
pool_mod2 <- pool(mod2)
summary(pool_mod2)
mod3 <-with(imp, lm(outc ~ age + sex), subset=(bmi>=30))
pool_mod3 <- pool(mod3)
summary(pool_mod3)
I do not get an error, but the problem is: all three analysis give me exactly the same results.我没有收到错误消息,但问题是:所有三种分析都给了我完全相同的结果。 I thought this could be just the real life situation, however, if I use variables other than bmi (like blood pressure < 150), the same thing happens to me.
我认为这可能只是现实生活中的情况,但是,如果我使用 bmi 以外的变量(例如血压 < 150),同样的事情也会发生在我身上。
So my question is: how can I do subset analysis in R when the data is imputed using mice?所以我的问题是:当使用鼠标估算数据时,如何在 R 中进行子集分析?
(BMI is imputed as well, I do not know if that is a problem?) (BMI也是推算的,不知道是不是有问题?)
You should place subset
within lm()
, not outside of it.您应该将
subset
放在lm()
,而不是之外。
with(imp, lm(outc ~ age + sex, subset=(bmi<30)))
A reproducible example.一个可重复的例子。
with(mtcars, lm(mpg ~ disp + hp)) # Both produce the same
with(mtcars, lm(mpg ~ disp + hp), subset=(cyl < 6))
Coefficients:
(Intercept) disp hp
30.73590 -0.03035 -0.02484
with(mtcars, lm(mpg ~ disp + hp, subset=(cyl < 6))) # Calculates on the subset
Coefficients:
(Intercept) disp hp
43.04006 -0.11954 -0.04609
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.