with()
function performs a statistical computation on the n
imputed datasets of the mimids
or wimids
objects. The typical sequence of steps to do a matching or weighting procedure on the imputed datasets are:
Impute the missing values by the mice()
function (from the mice package) or the amelia()
function (from the Amelia package), resulting in a multiple imputed dataset (an object of the mids
or amelia
class);
Match or weight imputed datasets using a matching or weighting model by the matchthem()
or weightthem()
function, resulting in an object of the mimids
or wimids
class;
Check the extent of balance of covariates across the datasets;
Fit the statistical model of interest on each dataset by the with()
function, resulting in an object of the mira
class; and
Pool the estimates from each model into a single set of estimates and standard errors, resulting in an object of the mipo
class.
# S3 method for mimids
with(data, expr, ...)
This argument specifies an object of the mimids
or wimids
class, typically produced by a previous call to the matchthem()
or weightthem()
.
This argument specifies an expression of the usual syntax of R formula (it also accepts expressions from survey package, like svyglm()
, please note that you shouldn't include the weights = weights
argument, see the package vignette for details).
Additional arguments to be passed to expr
.
This function returns an object of the mira
class (multiply imputed repeated analyses).
with()
performs a computation on the imputed datasets.
Stef van Buuren and Karin Groothuis-Oudshoorn (2011). mice
: Multivariate Imputation by Chained Equations in R
. Journal of Statistical Software, 45(3): 1-67. https://www.jstatsoft.org/v45/i03/
# NOT RUN {
#Loading the dataset
data(osteoarthritis)
#Multiply imputing the missing values
imputed.datasets <- mice(osteoarthritis, m = 5, maxit = 10,
method = c("", "", "mean", "polyreg",
"logreg", "logreg", "logreg"))
#Matching the multiply imputed datasets
matched.datasets <- matchthem(OSP ~ AGE + SEX + BMI + RAC + SMK, imputed.datasets,
approach = 'within', method = 'nearest')
#Analyzing the matched datasets
models <- with(data = matched.datasets,
exp = glm(KOA ~ OSP, family = binomial))
#or
#Estimating weights of observations in the multiply imputed datasets
weighted.datasets <- weightthem(OSP ~ AGE + SEX + BMI + RAC + SMK, imputed.datasets,
approach = 'within', method = 'ps')
#Analyzing the weighted datasets
models <- with(data = weighted.datasets,
exp = svyglm(KOA ~ OSP, family = binomial))
# }
Run the code above in your browser using DataLab