問題:
いくつかの予測値が欠落しているデータセットがあります。glmer
これらの代入セットに適用されたモデルを一緒にプールしたいと思います。私はmice
パッケージを使用して代入を作成しています(私も使用amelia
しmi
ましたが、成功しませんでした)。主に固定効果を抽出したいと思います。
pool()
マウス パッケージ内の関数を使用すると、次のエラーが返されます。
Error in qhat[i, ] : incorrect number of dimensions
pool()
ここで関数の以前の書き直しを使用して適応させようとしました:
https://github.com/stefvanbuuren/mice/pull/5
おそらく、私が見落としている明白な解決策があるでしょう!
次に例を示します。
# 1. create data (that can be replicated and converge later)
data = data.frame(x1=c(rep("1",0.1*1000), rep("0",0.5*1000),
rep("1",0.3*1000), rep("0",0.1*1000)),
x2=c(rep("fact1",0.55*1000), rep("fact2",0.1*1000),
rep(NA,0.05*1000), rep("fact3",0.3*1000)),
centre=c(rep("city1",0.1*1000), rep("city2",0.2*1000),
rep("city3",0.15*1000), rep("city1",0.25*1000),
rep("city2",0.3*1000) ))
# 2. set factors
data = sapply(data, as.factor)
# 3. mice imputation
library(mice)
imp.data = mice(data, m=5, maxit=20, seed=1234, pri=F)
# 4. apply the glmer function
library(lme4)
mice.fit = with(imp.data, glmer(x1~x2+(1|centre), family='binomial'))
# 5. pool imputations together
pooled.mi = pool(mice.fit)
ステップ 4 で適用したもう 1 つの関数を以下に示しますpool()
。
mice.fit = lapply(imp.data$imp, function(d){ glmer(x1~x2+(1|centre), data=d,
family='binomial') })
メタ分析モデルを使用して、モデルの各固定効果の結果をプールすることを含む回避策がありglmer
ます。それは機能しますが、Rubin モデルが機能する方がはるかに優れています。