Skip to contents

This helper function creates a valid method vector. The method vector is an argument to the mice function that specifies the method for each block.

Usage

make.method(
  data,
  where = make.where(data),
  blocks = make.blocks(data),
  defaultMethod = c("pmm", "logreg", "polyreg", "polr")
)

Arguments

data

A data frame or a matrix containing the incomplete data. Missing values are coded as NA.

where

Not used. Kept for compatibility.

blocks

List of vectors with variable names per block. List elements may be named to identify blocks. Variables within a block are imputed by a multivariate imputation method (see method argument). By default each variable is placed into its own block, which is effectively fully conditional specification (FCS) by univariate models (variable-by-variable imputation). Only variables whose names appear in blocks are imputed. The relevant columns in the where matrix are set to FALSE of variables that are not block members. A variable may appear in multiple blocks. In that case, it is effectively re-imputed each time that it is visited.

defaultMethod

A vector of length 4 containing the default imputation methods for 1) numeric data, 2) factor data with 2 levels, 3) factor data with > 2 unordered levels, and 4) factor data with > 2 ordered levels. By default, the method uses pmm, predictive mean matching (numeric data) logreg, logistic regression imputation (binary data, factor with 2 levels) polyreg, polytomous regression imputation for unordered categorical data (factor > 2 levels) polr, proportional odds model for (ordered, > 2 levels).

Value

Vector of length(blocks) element with method names

Details

Every block gets the default method for the type of its variables, also a block without missing data. mice() does not call the method of a block without cells to impute, so the method has no effect there, except when mice.mids() imputes newdata. Date, POSIXct and difftime variables get the method for numeric data. A block with a variable of a type that mice cannot impute, such as character, gets the empty method "". In mice 3.20.1 and earlier, make.method() gave the empty method to blocks without cells to impute.

See also

Examples

make.method(nhanes2)
#>       age       bmi       hyp       chl 
#> "polyreg"     "pmm"  "logreg"     "pmm"