Usage of formulas within mice and output of predictorMatrix #573
-
Hi everyone, I am performing multiple imputation for a single covariate in my dataset where I am specifying the formula to be used in mice. I am using logistic regression as method. The formula looks like this in principle: formula_list <- list(
y~ x1+x2+ x3+ x4
)
formula_list <- name.formulas(formula_list) The dataset I put into the mice function has more columns/covariates (.i.e continuing mice(data,formulas = formula_list) and looking at the obtained predictorMatrix I see that there is a 1 for all variables Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Good question. Here's a way to do it. library(mice, warn.conflicts = FALSE)
f <- make.formulas(nhanes)
f$bmi <- bmi ~ 1
imp <- mice(nhanes, formulas = f, method = "norm.predict", print = FALSE)
imp$formulas
#> $age
#> age ~ bmi + hyp + chl
#> <environment: 0x10a3c3bf8>
#>
#> $bmi
#> bmi ~ 1
#>
#> $hyp
#> hyp ~ age + bmi + chl
#> <environment: 0x10a3c3bf8>
#>
#> $chl
#> chl ~ age + bmi + hyp
#> <environment: 0x10a3c3bf8>
imp$imp$bmi
#> 1 2 3 4 5
#> 1 26.5625 26.5625 26.5625 26.5625 26.5625
#> 3 26.5625 26.5625 26.5625 26.5625 26.5625
#> 4 26.5625 26.5625 26.5625 26.5625 26.5625
#> 6 26.5625 26.5625 26.5625 26.5625 26.5625
#> 10 26.5625 26.5625 26.5625 26.5625 26.5625
#> 11 26.5625 26.5625 26.5625 26.5625 26.5625
#> 12 26.5625 26.5625 26.5625 26.5625 26.5625
#> 16 26.5625 26.5625 26.5625 26.5625 26.5625
#> 21 26.5625 26.5625 26.5625 26.5625 26.5625
imp$predictorMatrix
#> age bmi hyp chl
#> age 0 1 1 1
#> bmi 1 0 1 1
#> hyp 1 1 0 1
#> chl 1 1 1 0 Created on 2023-07-21 with reprex v2.0.2 What can learn from the example:
Hope this helps using formulas. |
Beta Was this translation helpful? Give feedback.
Good question. Here's a way to do it.