Learn R Programming

MatchThem (version 0.8.1)

mergethem: Merges Imputed Datasets with Dataframes

Description

The mergethem() function merges a dataframe with each imputed dataset of the mimids or wimids class objects based on the variables passed to the function as by.

Usage

mergethem(datasets, data, by = "ID")

Arguments

datasets

This argument specifies an object of the mimids or wimids class.

data

This argument specifies a dataframe.

by

This argument specifies a variable name, present in both datasets and data.

Value

This function returns an object of the mimids or wimids class after merging a dataframe with each imputed dataset of the inputted object.

Details

This functions can be used similar to the cbind() function (from the mice package).

References

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/

See Also

matchthem

weightthem

bindthem

Examples

Run this code
# 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')

#Merging a (unsorted) dataframe with imputed datasets of the 'matched.datasets'
#(assume that 'data' is a dataset with information on new variables)
matched.datasets <- mergethem(matched.datasets, data, by = c("AGE", "SEX"))
# }

Run the code above in your browser using DataLab