【发布时间】:2021-11-10 09:27:48
【问题描述】:
我阅读了这篇关于多重插补和倾向得分匹配的文章 (https://journal.r-project.org/archive/2021/RJ-2021-073/RJ-2021-073.pdf) - 这是这篇文章的代码:
# code from "MatchThem:: Matching and Weighting after Multiple Imputation", Pishgar et al, The R Journal Vol. XX/YY, AAAA 20ZZ:
library(MatchThem)
data('osteoarthritis')
summary(osteoarthritis)
library(mice)
imputed.datasets <- mice(osteoarthritis, m = 5)
matched.datasets <- matchthem(OSP ~ AGE + SEX + BMI + RAC + SMK,
datasets = imputed.datasets,
approach = 'within',
method = 'nearest',
caliper = 0.05,
ratio = 2)
weighted.datasets <- weightthem(OSP ~ AGE + SEX + BMI + RAC + SMK,
datasets = imputed.datasets,
approach = 'across',
method = 'ps',
estimand = 'ATM')
library(cobalt)
bal.tab(matched.datasets, stats = c('m', 'ks'),
imp.fun = 'max')
bal.tab(weighted.datasets, stats = c('m', 'ks'),
imp.fun = 'max')
library(survey)
matched.models <- with(matched.datasets,
svyglm(KOA ~ OSP, family = quasibinomial()),
cluster = TRUE)
weighted.models <- with(weighted.datasets,
svyglm(KOA ~ OSP, family = quasibinomial()))
matched.results <- pool(matched.models)
summary(matched.results, conf.int = TRUE)
据我了解,作者首先对小鼠 (m = 5) 使用多重插补,然后继续使用 MatchThem 进行匹配过程 - 最后 MatchThem 返回一个名为“matched.datasets”的“mimids-object”,其中包含5种不同的多重插补数据集。
有一个“完整”功能可以提取其中一个数据集,f.e.
newdataset <- complete(matched.datasets, 2) # extracts the second dataset.
所以 newdataset 是一个没有 NA 的数据框(因为已估算),可用于任何进一步的测试。
现在,我想将数据集用作数据框(就像使用完整后一样),但该数据集应该是所有数据集的某种“平均值” - 因为我该如何决定,我将 5 个数据集中的哪一个用于我的进一步分析?有没有办法做这样的事情:
meanofdatasets <- complete(matched.datasets, meanofall5datasets) # extracts a dataset which contains something like the mean values of all datasets
在我想使用此方法的数据中,我想使用原始约 500 行的估算和匹配数据集进行进一步测试,例如cox 回归、kaplan meier 图或竞争风险分析,以及简单的描述性统计数据以及关于匹配人群的图。 但是我必须在 5 个数据集中的哪一个上附加我的测试?对于这些测试,我需要一个真实的数据框,不是吗?
感谢您的帮助!
【问题讨论】:
-
"但是这个数据集应该是所有数据集的某种“平均值”——因为我怎么能决定,我使用 5 个数据集中的哪一个来进行进一步的分析?"您可能误解了多重插补的目的。您分析所有插补数据集,以便了解插补引起的可变性。
标签: r matching imputation