Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

complete.mids

Extracts the completed data from a mids object


Description

Takes an object of class mids, fills in the missing data, and returns the completed data in a specified format.

Usage

## S3 method for class 'mids'
complete(data, action = 1L, include = FALSE, mild = FALSE, ...)

Arguments

data

An object of class mids as created by the function mice().

action

A numeric vector or a keyword. Numeric values between 1 and data$m return the data with imputation number action filled in. The value of action = 0 return the original data, with missing values. action can also be one of the following keywords: "all", "long", "broad" and "repeated". See the Details section for the interpretation. The default is action = 1L returns the first imputed data set.

include

A logical to indicate whether the original data with the missing values should be included.

mild

A logical indicating whether the return value should always be an object of class mild. Setting mild = TRUE overrides action keywords "long", "broad" and "repeated". The default is FALSE.

...

Additional arguments. Not used.

Details

The argument action can be length-1 character, which is matched to one of the following keywords:

"all"

produces a mild object of imputed data sets. When include = TRUE, then the original data are appended as the first list element;

"long"

produces a data set where imputed data sets are stacked vertically. The columns are added: 1) .imp, integer, referring the imputation number, and 2) .id, character, the row names of data$data;

"stacked"

same as "long" but without the two additional columns;

"broad"

produces a data set with where imputed data sets are stacked horizontally. Columns are ordered as in the original data. The imputation number is appended to each column name;

"repeated"

same as "broad", but with columns in a different order.

Value

Complete data set with missing values replaced by imputations. A data.frame, or a list of data frames of class mild.

Note

Technical note: mice 3.7.5 renamed the complete() function to complete.mids() and exported it as an S3 method of the generic tidyr::complete(). Name clashes between mice::complete() and tidyr::complete() should no longer occur.

See Also

Examples

# obtain first imputed data set
sum(is.na(nhanes2))
imp <- mice(nhanes2, print = FALSE, maxit = 1)
dat <- complete(imp)
sum(is.na(dat))

# obtain stacked third and fifth imputation
dat <- complete(imp, c(3, 5))

# obtain all datasets, with additional identifiers
head(complete(imp, "long"))

# same, but now as list, mild object
dslist <- complete(imp, "all")
length(dslist)

# same, but also include the original data
dslist <- complete(imp, "all", include = TRUE)
length(dslist)

# select original + 3 + 5, store as mild
dslist <- complete(imp, c(0, 3, 5), mild = TRUE)
names(dslist)

mice

Multivariate Imputation by Chained Equations

v3.13.0
GPL-2 | GPL-3
Authors
Stef van Buuren [aut, cre], Karin Groothuis-Oudshoorn [aut], Gerko Vink [ctb], Rianne Schouten [ctb], Alexander Robitzsch [ctb], Patrick Rockenschaub [ctb], Lisa Doove [ctb], Shahab Jolani [ctb], Margarita Moreno-Betancur [ctb], Ian White [ctb], Philipp Gaffert [ctb], Florian Meinfelder [ctb], Bernie Gray [ctb], Vincent Arel-Bundock [ctb]
Initial release
2021-01-26

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.