impute_EM: EM imputation

View source: R/impute_EM.R

impute_EMR Documentation

EM imputation

Description

Impute missing values in a data frame or a matrix using parameters estimated via EM

Usage

impute_EM(
  ds,
  stochastic = TRUE,
  maxits = 1000,
  criterion = 1e-04,
  verbose = FALSE
)

Arguments

ds

A data frame or matrix with missing values.

stochastic

Logical; see details.

maxits

Maximum number of iterations for the EM, passed to norm::em.norm().

criterion

If maximum relative difference in parameter estimates is below this threshold, the EM algorithm stops. Argument is directly passed to norm::em.norm().

verbose

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

Details

At first parameters are estimated via norm::em.norm(). Then these parameters are used in regression like models to impute the missing values. If stochachstic = FALSE, the expected values (given the observed values and the estimated parameters via EM) are imputed for the missing values of an object. If stochastic = TRUE, residuals from a multivariate normal distribution are added to these expected values.

If all values in a row are NA or the required part of the covariance matrix for the calculation of the expected values is not invertible, parts of the estimated mean vector will be imputed. If stochastic = TRUE, residuals will be added to these values. If verbose = TRUE, a message will be given for these rows.

Value

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

The number of EM iterations are added as an attribute (iterations).

See Also

  • norm::em.norm(), which estimates the parameters

  • impute_expected_values(), which calculates the imputation values

Examples

ds_orig <- mvtnorm::rmvnorm(100, rep(0, 7))
ds_mis <- delete_MCAR(ds_orig, p = 0.2)
ds_imp <- impute_EM(ds_mis, stochastic = FALSE)

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