generate_patterns: Missing-Data Pattern Generation

View source: R/utils.R

generate_patternsR Documentation

Missing-Data Pattern Generation

Description

Generate all possible missing patterns in a multivariate data set. The function can be used to complement the function ampute() from package mice in which a matrix of patterns is needed to allow for general missing-data patterns with missing-data mechanism missing at random (MAR). Using this function, each observation can have more than one missing value.

Usage

generate_patterns(d)

Arguments

d

The number of variables or columns of the data set. d must be an integer greater than 1.

Details

An observation cannot have all values missing values. A complete observation is not qualified for missing-data pattern. Note that a large value of d may result in memory allocation error.

Value

A matrix where 0 indicates that a variable should have missing values and 1 indicates that a variable should remain complete. This matrix has d columns and 2^d - 2 rows.

Examples

generate_patterns(4)

#++++ To use with the function ampute() from package mice ++++#
library(mice)

patterns_matr <- generate_patterns(4)
data_missing <- ampute(iris[1:4], prop = 0.5, patterns = patterns_matr)$amp


MixtureMissing documentation built on Oct. 16, 2024, 1:09 a.m.