IQSS / Amelia

Amelia: A Package for Missing Data
http://gking.harvard.edu/amelia
61 stars 17 forks source link

Imputed values depend on platform and R version #17

Closed izahn closed 5 years ago

izahn commented 6 years ago

The imputed values are different on OS X with R 3.5.0 than they are on other platforms or other R versions. To demonstrate:

On linux with R 3.5.0

library(Amelia)
data(africa)
set.seed(1)
a.out <- amelia(africa[ , c("infl", "trade")],
                     m = 1,
                     boot.type = "none")
saveRDS(a.out, "linux350.rds")

On Mac with R 3.4.4

library(Amelia)
data(africa)
set.seed(1)
a.out <- amelia(africa[ , c("infl", "trade")],
                     m = 1,
                     boot.type = "none")
saveRDS(a.out, "mac344.rds")

On Mac with R 3.5.0

library(Amelia)
data(africa)
set.seed(1)
a.out <- amelia(africa[ , c("infl", "trade")],
                     m = 1,
                     boot.type = "none")
saveRDS(a.out, "mac350.rds")

On any system

linux350 <- readRDS("linux350.rds")
mac344 <- readRDS("mac344.rds")
mac350 <- readRDS("mac350.rds")

all.equal(linux350, mac344)
## TRUE
all.equal(mac344, mac350)
## [1] "Component “imputations”: Component “imp1”: Component “trade”: Mean relative difference: 0.2454121"

This is a bit troubling since in some cases we would like to provide code that is exactly reproducible.

mattblackwell commented 5 years ago

This turned out to be a particularly strange one to debug, but easy to solve. We had an unused call to arma::randu that appeared to affect the RNG for R, but only in some versions of R. I just removed that call in a28777b and now they appear to give the same results across versions. You can install the develop branch and check, if you'd like.