Learn R Programming

missMethods (version 0.2.0)

impute_EM: 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)?

Value

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

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.

See Also

Examples

Run this code
# NOT RUN {
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)
# }

Run the code above in your browser using DataLab