4
$\begingroup$

I am trying to impute missing values with R. I would like to use the EM algorithm for that.

As it seems this algorithm is implemented in the Amelia package. However, Amelia is designed for multiple imputations (which I cannot use because of several reasons). Because of this Amelia imputes based on bootstrapped data and not the full original data set.

Is there a way to impute with EM using the full original dataset? Is this possible with Amelia or any other package?

$\endgroup$

2 Answers 2

7
$\begingroup$

A quick update on this question. We've updated Amelia to run without a bootstrap using the "boot.type" argument and setting it to "none":

library(Amelia)
data(africa)
a.out <- amelia(africa, ts = "year", cs = "country", m = 1, boot.type = "none")

This will run the EM algorithm on the original data once and works as of version 1.7.3.

$\endgroup$
1
$\begingroup$

Amelia is not able to do EM imputation without bootstrapping out of the box at the moment (this information is based on a personal conversation with the package maintainer). However, I came up with a short and somehow dirty hack that helps you to do EM imputation in R (similar to the functionality in SPSS).

  1. Download the current stable Amelia version from http://r.iq.harvard.edu/src/contrib/
  2. Decompress the *.tar.gz on your computer
  3. Open the file emb.R in the folder R/
  4. Find the following function:

    bootx<-function(x,priors=NULL){....

  5. There, replace the following lines:

    order<-trunc(runif(nrow(x), min=1, max=nrow(x)+1))

    xboot<-x[order,]

with

## Changed part, instead of bootstrapping just use the
## whole data set
#order<-trunc(runif(nrow(x), min=1, max=nrow(x)+1))
#xboot<-x[order,]
cat("CAUTION: THIS VERSION OF AMELIA DOES NOT BOOTSTRAP!")
xboot<-x
  1. Save the source file
  2. Compress the whole folder
  3. Install the packages from your just changed source (see here).

I tested it with Amelia v1.6.4 and it works fine. Amelia now just uses the whole dataset for EM imputation.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.