4

R パッケージ「マウス」によって作成された帰属データの集計に関して質問があります。

私が理解している限り、「マウス」の「完全な」コマンドは、たとえば最初の代入の代入値を抽出するために適用されます。ただし、合計 10 回の代入を実行すると、どの代入値を抽出するかわかりません。すべての代入にわたって(集計)代入データを抽出する方法を知っている人はいますか?

データを MS Excel に入力し、別のソフトウェア ツールでさらに計算を実行したいので、このようなコマンドは非常に役立ちます。

コメントしてくださってありがとうございます。簡単な例 (「マウス」自体から) を以下に示します。

R> library("mice")
R> nhanes
R> imp <- mice(nhanes, seed = 23109) #create imputation
R> complete(imp) #extraction of the five imputed datasets (row-stacked matrix)

5 つの帰属データセットを集計し、帰属値を Excel に抽出するにはどうすればよいですか?

4

3 に答える 3

3

同様の問題がありました。数値変数に十分な以下のコードを使用しました。他の人については、帰属結果の1つをランダムに選択することを考えました(平均化すると混乱する可能性があるため)。

私が提供するコードは(数値用)です:

tempData <- mice(data,m=5,maxit=50,meth='pmm',seed=500)
completedData <- complete(tempData, 'long')
a<-aggregate(completedData[,3:6] , by = list(completedData$.id),FUN= mean)
  1. 結果を結合する必要があります。
  2. 「Hmisc」の方が優れたパッケージだと思います。
  3. より優れた/よりエレガントな/組み込みのソリューションを既に見つけた場合は、私たちと共有してください。
于 2016-07-27T09:40:38.730 に答える
1

complete(imp,action="long")各代入の値を取得するために使用する必要があります。あなたが見れば?complete、あなたは見つけるでしょう

complete(x, action = 1, include = FALSE)

Arguments

x   
An object of class mids as created by the function mice().

action  
If action is a scalar between 1 and x$m, the function returns the data with imputation number action filled in. Thus, action=1 returns the first completed data set, action=2 returns the second completed data set, and so on. The value of action can also be one of the following strings: 'long', 'broad', 'repeated'. See 'Details' for the interpretation.

include 
Flag to indicate whether the orginal data with the missing values should be included. This requires that action is specified as 'long', 'broad' or 'repeated'.

したがって、デフォルトでは、最初の代入値が返されます。さらに、引数actionは文字列にすることもできます: longbroad、およびrepeated. と入力するlongと、データが長い形式で表示されます。include = TRUE元の欠損データが必要かどうかを設定することもできます。

于 2015-03-02T16:20:59.113 に答える