Learn R Programming

mice (version 2.2)

as.mids: Converts an multiply imputed dataset (long format) into a mids object

Description

This function converts imputed data stored in long format into an object of class mids. The original incomplete data set needs to be available so that we know where the missing data are. The function is useful to convert back operations applied to the imputed data back in a mids object. It may also be used to store multiply imputed data sets from other software into the format used by mice.

Usage

as.mids(data, .imp=1, .id=2)

Arguments

data
A multiply imputed data set in long format
.imp
Mandatory column indicator for the multiple imputation stream, where 0 indicates the incomplete data and 1 through m indicate the m multiple imputation streams. Default is 1.
.id
Optional column indicator for the row numbers. Default is 2.

Value

  • An object of class mids

Details

If .id is specified, row names from the original data (if supplied) will be copied to the mids object.

Examples

Run this code
# nhanes example without .id
imp <- mice(nhanes, print = FALSE)
X <- complete(imp, action = "long", include = TRUE)[, -2]
test <- as.mids(X, .id = NULL)
is.mids(test)
test.dat <- complete(test, action = "long", include = TRUE)

# Test on boys data
imp <- mice(boys, print = FALSE, maxit = 1)
X <- complete(imp, action = "long", include = TRUE)
test <- as.mids(X)
is.mids(test)
test.dat <- complete(test, action = "long", include = TRUE)
# original rownumbers are automatically copied from .id

Run the code above in your browser using DataLab