R: Imputation of most likely value within the class

mice.impute.2lonly.mean {mice} | R Documentation

## Imputation of most likely value within the class

### Description

Method `2lonly.mean` replicates the most likely value within a class of a second-level variable. It works for numeric and factor data. The function is primarily useful as a quick fixup for data in which the second-level variable is inconsistent.

### Usage

    mice.impute.2lonly.mean(y, ry, x, type, wy = NULL, ...)

### Arguments

`y` | Vector to be imputed
`ry` | Logical vector of length `length(y)` indicating the the subset `y[ry]` of elements in `y` to which the imputation model is fitted. The `ry` generally distinguishes the observed (`TRUE`) and missing values (`FALSE`) in `y`.
`x` | Numeric design matrix with `length(y)` rows with predictors for `y`. Matrix `x` may have no missing values.
`type` | Vector of length `ncol(x)` identifying random and class variables. The class variable (only one is allowed) is coded as `-2`.
`wy` | Logical vector of length `length(y)`. A `TRUE` value indicates locations in `y` for which imputations are created.
`...` | Other named arguments.

### Details

Observed values in `y` are averaged within the class, and replicated to the missing `y` within that class. This function is primarily useful for repairing incomplete data that are constant within the class, but vary over classes.

For numeric variables, `mice.impute.2lonly.mean()` imputes the class mean of `y`. If `y` is a second-level variable, then conventionally all observed `y` will be identical within the class, and the function just provides a quick fix for any missing `y` by filling in the class mean.

For factor variables, `mice.impute.2lonly.mean()` imputes the most frequently occuring category within the class.

If there are no observed `y` in the class, all entries of the class are set to `NA`. Note that this may produce problems later on in `mice` if imputation routines are called that expects predictor data to be complete. Methods designed for imputing this type of second-level variables include `mice.impute.2lonly.norm` and `mice.impute.2lonly.pmm`.

### Value

Vector with imputed data, same type as `y`, and of length `sum(wy)`

### Author(s)

Gerko Vink, Stef van Buuren, 2019

### References

Van Buuren, S. (2018). Flexible Imputation of Missing Data. Second Edition. Boca Raton, FL.: Chapman & Hall/CRC Press.

### See Also

Other univariate-2lonly: `mice.impute.2lonly.norm()`, `mice.impute.2lonly.pmm()`

[Package mice version 3.12.0 Index]