
[英]In `data.table` within R, is there a fast way to combine tables together?
[英]Is there a way to combine multiple MatchIt objects together in R
我有一個數據集,我正在對其進行匹配,該數據集是具有重疊成員資格的重復橫截面:
會員ID | 治療 | 學習月 | 年齡 | 性別 | 風險評分 | 慢性阻塞性肺病 | 瑞士法郎 | 糖尿病 | 復雜提供者FLG |
---|---|---|---|---|---|---|---|---|---|
123 | 1 | 1 | 54 | 米 | 1.45 | 0 | 1 | 1 | 0 |
201 | 0 | 1 | 55 | 米 | 1.54 | 0 | 1 | 1 | 0 |
205 | 0 | 1 | 85 | 米 | .8 | 1 | 0 | 0 | 0 |
155 | 1 | 2 | 56 | 米 | 1.58 | 0 | 1 | 1 | 0 |
201 | 0 | 2 | 55 | 米 | 1.54 | 0 | 1 | 1 | 0 |
208 | 0 | 2 | 58 | 米 | 1.68 | 0 | 0 | 1 | 0 |
注意成員 201 在第一個月和第二個月的橫截面。 因此,當我在一個 StudyMonth 匹配時,我需要從潛在匹配池中刪除與該截面匹配的個體,以用於未來的截面。在上面的玩具示例中,即使 201 是第 1 個月的 123 和第 1 個月的 155 的最佳控制第 2 個月,我不想讓他在控制池中兩次。
做一個 for 循環並重新運行匹配非常簡單,消除先前選擇的個體,然后將每個循環的結果綁定到一個最終的治療/對照組中,如下所示:
for (MatchMonth in 0:11){
WorkingMatchedCohort <- matchit(Treatment ~ Age + Sex + RiskScore +
CHF + COPD + Diabetes + Depression + ComplexProviderFLG,
data= filter(WorkingSet,(Treatment==0 | Treatment==1) & StudyMonth==MatchMonth))
if(exists("unionedmatches")) {
unionedmatches<-bind_rows(unionedmatches,match.data(WorkingMatchedCohort))
}else{
unionedmatches<-match.data(WorkingMatchedCohort)
}
##Flag members so that they're not reused
WorkingSet$Treatment[WorkingSet$Treatment==0 & WorkingSet$MemberID %in% unionedmatches$MemberID] <-2
}
這給了我使用match.data
在unionedmatches
中的組合結果。 但是我將如何 go 關於組合實際的 MatchIt 對象WorkingMatchedCohort
以便我可以使用內置的 MatchIt 工具來繪制擬合優度?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.