Imputation of most likely value within the class
Source:R/mice.impute.2lonly.mean.R
mice.impute.2lonly.mean.Rd
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.
Arguments
- y
Vector to be imputed
- ry
Logical vector of length
length(y)
indicating the the subsety[ry]
of elements iny
to which the imputation model is fitted. Thery
generally distinguishes the observed (TRUE
) and missing values (FALSE
) iny
.- x
Numeric design matrix with
length(y)
rows with predictors fory
. Matrixx
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)
. ATRUE
value indicates locations iny
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
.
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()