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

filter.mids

Subset rows of a mids object


Description

This function takes a mids object and returns a new mids object that pertains to the subset of the data identified by the expression in .... The expression may use column values from the incomplete data in .data$data.

Usage

## S3 method for class 'mids'
filter(.data, ..., .preserve = FALSE)

Arguments

.data

A mids object.

...

Expressions that return a logical value, and are defined in terms of the variables in .data$data. If multiple expressions are specified, they are combined with the & operator. Only rows for which all conditions evaluate to TRUE are kept.

.preserve

Relevant when the .data input is grouped. If .preserve = FALSE (the default), the grouping structure is recalculated based on the resulting data, otherwise the grouping is kept as is.

Value

An S3 object of class mids

Note

The function calculates a logical vector include of length nrow(.data$data). The function constructs the elements of the filtered mids object as follows:

data Select rows in .data$data for which include == TRUE
imp Select rows each imputation data.frame in .data$imp for which include == TRUE
m Equals .data$m
where Select rows in .data$where for which include == TRUE
blocks Equals .data$blocks
call Equals .data$call
nmis Recalculate nmis based on the selected data rows
method Equals .data$method
predictorMatrix Equals .data$predictorMatrix
visitSequence Equals .data$visitSequence
formulas Equals .data$formulas
post Equals .data$post
blots Equals .data$blots
ignore Select positions in .data$ignore for which include == TRUE
seed Equals .data$seed
iteration Equals .data$iteration
lastSeedValue Equals .data$lastSeedValue
chainMean Set to NULL
chainVar Set to NULL
loggedEvents Equals .data$loggedEvents
version Replaced with current version
date Replaced with current date

Author(s)

Patrick Rockenschaub

See Also

Examples

imp <- mice(nhanes, m = 2, maxit = 1, print = FALSE)

# example with external logical vector
imp_f <- filter(imp, c(rep(TRUE, 13), rep(FALSE, 12)))

nrow(complete(imp))
nrow(complete(imp_f))

# example with calculated include vector
imp_f2 <- filter(imp, age >= 2 & hyp == 1)
nrow(complete(imp_f2))  # should be 5

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.