impute_median: Median imputation

View source: R/impute_location_parameter.R

impute_medianR Documentation

Median imputation

Description

Impute an observed median value for every missing value

Usage

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

Arguments

ds

A data frame or matrix with missing values.

type

A string specifying the values used for imputation; 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).

convert_tibble

If ds is a tibble, should it be converted (see section A note for tibble users).

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.

Value

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

A note for tibble users

If you use tibbles and convert_tibble is TRUE the tibble is first converted to a data frame, then imputed and converted back. If convert_tibble is FALSE no conversion is done. However, depending on the tibble and the package version of tibble you use, imputation may not be possible and some errors will be thrown.

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

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)

missMethods documentation built on Sept. 16, 2022, 5:08 p.m.