如何从Amelia包中提取完整的数据集 [英] How extract complete dataset from Amelia package

查看:44
本文介绍了如何从Amelia包中提取完整的数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在用于提取完整数据集的鼠标包中,您可以使用complete()命令,如下所示:

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")

但是有人可以告诉我如何在Amelia程序包中提取完整的数据集吗?

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")

推荐答案

str()函数在这里总是很有帮助.您会看到完整的数据集存储在amelia()返回的对象的imputations元素中:

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"

要单独获取每个插补,只需对您请求的所有插补进行imp2$imputations[[1]]等操作即可.在您的示例中,有五个:

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"

这篇关于如何从Amelia包中提取完整的数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆