impute_expected_values: Impute expected values

View source: R/impute_expected_values.R

impute_expected_valuesR Documentation

Impute expected values

Description

Impute the missing values with expected values given the observed values and estimated parameters assuming a multivariate normal distribution

Usage

impute_expected_values(
  ds,
  mu,
  S,
  stochastic = FALSE,
  M = is.na(ds),
  verbose = FALSE
)

Arguments

ds

A data frame or matrix with missing values.

mu

Vector of means for the variables.

S

Covariance matrix of the variables.

stochastic

Logical, should residuals be added to the expected values.

M

Missing data indicator matrix.

verbose

Should messages be given for special cases (see details)?

Details

Normally, this function is called by other imputation function and should not be called directly. The function imputes the missing values assuming a multivariate normal distribution. This is equivalent to imputing the least squares estimate of the missing values in some kind of way.

If no values is observed in a row or a relevant submatrix of the covariance matrix (S_22) is not invertible, the missing values are imputed with (parts of) mu (plus a residuum, if stochastich = TRUE). If verbose = TRUE, these cases will be listed in a message. Otherwise, they will be imputed silently.

Value

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

Examples

ds_orig <- mvtnorm::rmvnorm(100, rep(0, 2))
ds_mis <- delete_MCAR(ds_orig, p = 0.2)
# impute using true parameters:
ds_imp <- impute_expected_values(ds_mis, mu = c(0, 0), diag(1, 2))

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