Learn R Programming

mice (version 2.30)

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
# NOT RUN {
# impute the nhanes dataset
imp <- mice(nhanes, print = FALSE)
# extract the data in long format
X <- complete(imp, action = "long", include = TRUE)
# create dataset with .imp variable that is not a factor
X2 <- X
X2$.imp <- as.numeric(levels(X$.imp))[X$.imp]
# nhanes example without .id
test1 <- as.mids(X[, -2], .id = NULL)
is.mids(test1)
all(complete(test1, action = "long", include = TRUE) == X, na.rm = TRUE)
# nhanes example without .id where .imp is not a factor
test2 <- as.mids(X2[, -2], .id = NULL)
is.mids(test2)
all(complete(test1, action = "long", include = TRUE) == X, na.rm = TRUE)
# nhanes example with .id
test3 <- as.mids(X, .id = 2)
is.mids(test3)
all(complete(test1, action = "long", include = TRUE) == X, na.rm = TRUE)
# nhanes example with .id where .imp is not a factor
test4 <- as.mids(X2, .id = 2)
is.mids(test4)
all(complete(test1, action = "long", include = TRUE) == X, na.rm = TRUE)
# }

Run the code above in your browser using DataLab