I want to generate descriptive statistics for different subgroups after multiple imputation with MICE.
I have a dataset that include a medicine and age, which I imputed.
id <- c(1,2,3,4,5,6,7,8,9,10)
age <- c(60, 80, 70, NA, 49, 30, NA, 59, 79, NA)
medication <- c("yes", "no")
dat <- data.frame(id, age, medication)
imp_1 <- mice(dat, maxit = 0)
meth <- imp_1$method
pred <- imp_1$predictorMatrix
imp <- mice(dat, method = meth, predictorMatrix = pred, maxit = 10, m = 5, seed = 2018)
So I imputed the NA in age, using information about id and medication use (of course, it is not about the quality of the imputation, but it is just to create an example).
I want to calculate how many users of thiazide diuretics I have in the group of people aged above 75 and below 75. I tried two codes:
subgroup <- with(imp, expr= table(age>75), subset=(medication=="yes"))
withPool_MI(subgroup)
subgroup1 <- with(imp, expr= table(age>75, medication==1))
withPool_MI(subgroup1)
However, both codes do not work unfortunately. So what I want is the following:
0 1
age>75
age<75
I want this table filled, so the number of users and non-users of the medication in both age categories. Can someone help me?
(This is the first time I created a reproducible example, so if it is not correct or does not work, please let me know!)