with() runs a model on the
n imputed datasets of the supplied
wimids object. The typical sequence of steps to do a matching procedure on the imputed datasets are:
Impute the missing values using 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
Match or weight each imputed dataset using
weightthem(), resulting in an object of the
Check the extent of balance of covariates across the matched datasets (using functions in cobalt);
Fit the statistical model of interest on each matched dataset by the
with() function, resulting in an object of the
mimira class; and
Pool the estimates from each model into a single set of estimates and standard errors, resulting in an object of the
1 2 3 4 5
An expression (usually a call to a modeling function like
When a function from survey (e.g.,
Additional arguments to be passed to
with() applies the supplied model in
expr to the matched or weighrd imputed datasets, automatically incorporating the (matching) weights when possible. The argument to
expr should be of the form
glm(y ~ z, family = quasibinomial), for example, excluding the data or weights argument, which are automatically supplied.
Functions from the survey package, such as
svyglm(), are treated a bit differently. No
svydesign objcect needs to be supplied because
with() automatically constructs and supplies it with the imputed dataset and estimated weights. When
cluster = TRUE (or
with() detects that pairs should be clustered; see Arguments above), pair membership is supplied to the
ids argument of
For generalized linear models, it is always recommended to use
svyglm() rather than
glm() in order to correctly compute standard errors. For Cox models,
coxph() will produce correct standard errors when used with weighting but
svycoxph() will produce more accurate standard errors when matching is used.
An object of the
mimira class containing the output of the analyses.
Farhad Pishgar and Noah Greifer
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/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#Loading libraries library(MatchThem) library(survey) #Loading the dataset data(osteoarthritis) #Multiply imputing the missing values imputed.datasets <- mice::mice(osteoarthritis, m = 5) #Matching in 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(matched.datasets, svyglm(KOA ~ OSP, family = binomial), cluster = TRUE)
Loading required package: MatchIt Loading required package: WeightIt Loading required package: grid Loading required package: Matrix Loading required package: survival Attaching package: ‘survey’ The following object is masked from ‘package:graphics’: dotchart iter imp variable 1 1 BMI RAC SMK OSP KOA 1 2 BMI RAC SMK OSP KOA 1 3 BMI RAC SMK OSP KOA 1 4 BMI RAC SMK OSP KOA 1 5 BMI RAC SMK OSP KOA 2 1 BMI RAC SMK OSP KOA 2 2 BMI RAC SMK OSP KOA 2 3 BMI RAC SMK OSP KOA 2 4 BMI RAC SMK OSP KOA 2 5 BMI RAC SMK OSP KOA 3 1 BMI RAC SMK OSP KOA 3 2 BMI RAC SMK OSP KOA 3 3 BMI RAC SMK OSP KOA 3 4 BMI RAC SMK OSP KOA 3 5 BMI RAC SMK OSP KOA 4 1 BMI RAC SMK OSP KOA 4 2 BMI RAC SMK OSP KOA 4 3 BMI RAC SMK OSP KOA 4 4 BMI RAC SMK OSP KOA 4 5 BMI RAC SMK OSP KOA 5 1 BMI RAC SMK OSP KOA 5 2 BMI RAC SMK OSP KOA 5 3 BMI RAC SMK OSP KOA 5 4 BMI RAC SMK OSP KOA 5 5 BMI RAC SMK OSP KOA Matching Observations | dataset: #1 #2 #3 #4 #5
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.