用小鼠读取已经多个估算的数据集(在 R 中)

问题描述 投票:0回答:1

我目前有一个已经多重插补的数据集,其结构为: Structure

clientID <- c(4,4,4,4,4,6,6,6,6,6,7,7,7,7,7,15,15,15,15,15)
impID <- c(1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5)
x <- c(1534500, 1572500, 1555500, 1571500, 1546500, 113000, 113000, 113000, 113000,113000, 4153101,4153101,4153101,4153101,4153101, 1042400, 1044400, 1092400, 1057400, 1051400)
y <- c(14200,14200,14200,14200,14200,160000,15000,14000,14200,4800,12000,14200,10500,14200,48000,150000,150000,150000,150000,150000)
z <- c(200, 200,200,200,200, 400,400,400,400,400,150,150,150,150,150,230,230,230,230,230)
data <- data.frame(clientID=clientID, impID = impID, x=x, y=y, z=z)

regs <- with(data, lm(x ~ y + z))

我想运行回归,这应该为每个插补提供一个结果(例如 impID:总共 5 个回归)。不幸的是,回归函数不区分插补 ID,并对总数据运行一个回归。

mice 包通常用于插补数据,然后可以与 with(data, lm(x ~ y + z)) 一起使用,产生多个回归。

我想知道如何将已经估算的数据转换为“识别的”估算数据,而不更改数据中的值。这样我就可以运行回归,得到 5 个结果。

非常感谢您的帮助!

我尝试在小鼠中创建一个估算数据集,但由于数据集已经估算,生成的数据已使用新条目进行扩展。

r regression imputation r-mice
1个回答
0
投票

您可以使用

impID
拆分
split()
上的数据,这将生成数据框列表。然后,您可以将它们转换为
imputationList
,然后在结果上使用
with()
MIcombine()

library(mitools)
clientID <- c(4,4,4,4,4,6,6,6,6,6,7,7,7,7,7,15,15,15,15,15)
impID <- c(1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5)
x <- c(1534500, 1572500, 1555500, 1571500, 1546500, 113000, 113000, 113000, 113000,113000, 4153101,4153101,4153101,4153101,4153101, 1042400, 1044400, 1092400, 1057400, 1051400)
y <- c(14200,14200,14200,14200,14200,160000,15000,14000,14200,4800,12000,14200,10500,14200,48000,150000,150000,150000,150000,150000)
z <- c(200, 200,200,200,200, 400,400,400,400,400,150,150,150,150,150,230,230,230,230,230)
data <- data.frame(clientID=clientID, impID = impID, x=x, y=y, z=z)

sp <- split(data, data$impID)
implist <- imputationList(sp)

regs <- with(implist, lm(x ~ y + z))

summary(MIcombine(regs))
#> Multiple imputation results:
#>       with(implist, lm(x ~ y + z))
#>       MIcombine.default(regs)
#>                   results           se       (lower       upper) missInfo
#> (Intercept)  5.294024e+06 2.300637e+06 781764.53408 9.806284e+06      5 %
#> y           -7.903431e+00 1.362453e+01    -34.60722 1.880036e+01      0 %
#> z           -1.279535e+04 9.454923e+03 -31352.04175 5.761333e+03      7 %

创建于 2024-02-06,使用 reprex v2.0.2

© www.soinside.com 2019 - 2024. All rights reserved.