2

In mice package for extract complete dataset you can use complete() command as follow :

install.packages("mice")
library ("mice")
imp1=mice(nhanes,10) 
fill1=complete(imp,1)
fill2=complete(imp,2)
fillall=complete(imp,"long")

But can some one tell me how to extract complete dataset in Amelia package??

install.packages("Amelia")
library ("Amelia")
imp2= amelia(freetrade, m = 5, ts = "year", cs = "country")
zhyan
  • 261
  • 4
  • 14
  • How about `data(freetrade)` and then `freetrade` is in your workspace? Is that what you mean by extracting the complete data set? `str(freetrade)` shows 10 variables and 171 observations. – Bryan Hanson Jan 23 '16 at 21:04
  • @BryanHanson , `freetrade` dataset is incomplete dataset that contain NA but I want to extract this dataset without NA after imputation ,Thomas answered me and you can get it by`imp2$imputations[[1]] ` to get separately imputation , also `str(freetrade)` is helpfull . – zhyan Jan 23 '16 at 21:37
  • Ah, I see. I'm not familiar with the idea of "extraction" to be imputation, but this is not my area. To me, you can't have more data than the full, original data set! So I've learned something, which is always good. – Bryan Hanson Jan 23 '16 at 21:52

1 Answers1

2

The str() function is always helpful here. You'll see that the complete datasets are stored in the imputations element of the object returned by amelia():

> str(imp2, 1)
List of 12
 $ imputations:List of 5
  ..- attr(*, "class")= chr [1:2] "mi" "list"
 $ m          : num 5
 $ missMatrix : logi [1:171, 1:10] FALSE FALSE FALSE FALSE FALSE FALSE ...
  ..- attr(*, "dimnames")=List of 2
 $ overvalues : NULL
 $ theta      : num [1:9, 1:9, 1:5] -1 -0.0161 0.199 -0.0368 -0.0868 ...
 $ mu         : num [1:8, 1:5] -0.0161 0.199 -0.0368 -0.0868 -0.0658 ...
 $ covMatrices: num [1:8, 1:8, 1:5] 0.8997 -0.3077 0.0926 0.2206 -0.1115 ...
 $ code       : num 1
 $ message    : chr "Normal EM convergence."
 $ iterHist   :List of 5
 $ arguments  :List of 23
  ..- attr(*, "class")= chr [1:2] "ameliaArgs" "list"
 $ orig.vars  : chr [1:10] "year" "country" "tariff" "polity" ...
 - attr(*, "class")= chr "amelia"

To get each imputation alone, just do imp2$imputations[[1]], etc. up through all imputations that you requested. In your example, there are five:

> str(imp2$imputations, 1)
List of 5
 $ imp1:'data.frame':   171 obs. of  10 variables:
 $ imp2:'data.frame':   171 obs. of  10 variables:
 $ imp3:'data.frame':   171 obs. of  10 variables:
 $ imp4:'data.frame':   171 obs. of  10 variables:
 $ imp5:'data.frame':   171 obs. of  10 variables:
 - attr(*, "class")= chr [1:2] "mi" "list"
Thomas
  • 43,637
  • 12
  • 109
  • 140
  • Thank you so much for your answer that is exactly what I want `imp2$imputations[[1]]` – zhyan Jan 23 '16 at 21:29
  • Is there a way to get 1 single complete data set? In other words which of the 5 imputations do I use best for further calculations? – Juan Nov 13 '19 at 15:57