Learn R Programming

missMethods (version 0.2.0)

impute_median: Median imputation

Description

Impute an observed median value for every missing value

Usage

impute_median(ds, type = "columnwise", ordered_low = FALSE)

Arguments

ds

A data frame or matrix with missing values.

type

One of: "columnwise", "rowwise", "total", "Two-Way" or "Winer" (see details).

ordered_low

Logical; used for the calculation of the median from ordered factors (for details see: median.factor).

Value

An object of the same class as ds with imputed missing values.

A Note for tibble users

If you use tibbles and an error like ‘Lossy cast from `value` double to integer’ occurs, you will first need to convert all integer columns with missing values to double. Another solution is to convert the tibble with as.data.frame() to a data frame. The data frame will automatically convert integer columns to double columns, if needed.

Details

This function behaves exactly like impute_mean. The only difference is that it imputes a median instead of a mean. All types from impute_mean are also implemented for impute_median. They are documented in impute_mean and apply_imputation. The function median is used for the calculation of the median values for imputation.

References

Beland, S., Pichette, F., & Jolani, S. (2016). Impact on Cronbach's \(\alpha\) of simple treatment methods for missing data. The Quantitative Methods for Psychology, 12(1), 57-73.

See Also

apply_imputation the workhorse for this function.

median, median.factor

Other location parameter imputation functions: impute_mean(), impute_mode()

Examples

Run this code
# NOT RUN {
ds <- data.frame(X = 1:20, Y = ordered(LETTERS[1:20]))
ds_mis <- delete_MCAR(ds, 0.2)
ds_imp <- impute_median(ds_mis)
# completely observed columns can be of any type:
ds_mis_char <- cbind(ds_mis, letters[1:20])
ds_imp_char <- impute_median(ds_mis_char)
# }

Run the code above in your browser using DataLab