Balance diagnostics after propensity score matching(PSM)

Standardized mean difference (SMD) is the most commonly used statistic to examine the balance of covariate distribution between treatment groups. Because SMD is independent of the unit of measurement, it allows comparison between variables with different unit of measurement. (Zhang Z et al. 2019)

  1. to create a simulated dataset
psSim<-function(CatVarN=2,ContVarN=2,
                seed=123,n=1000){
  set.seed(seed);
  Xcont <- replicate(ContVarN, rnorm(n))
  Xcat <- replicate(CatVarN, rbinom(n,size = 1,prob = 0.3))
  linpredT<-cbind(1, Xcont,Xcat) %*%
    sample(c(-5:-1,1:5), 1+CatVarN+ContVarN) +
    rnorm(n,-0.8,1)
  probTreatment <- exp(linpredT) / (1 + exp(linpredT))
  Treat <- rbinom(n, 1, probTreatment);
  linpredY <- 1 + cbind(Xcont,Xcat) %*%
    rep(1, CatVarN+ContVarN) +
    Treat + rnorm(n, -2, 2);
  prY = 1/(1+exp(-linpredY));
  mort <- rbinom(n,1,prY);
  dt <- data.frame(Xcont=Xcont,Xcat=Xcat,Treat, mort)
  return(dt)
}
dt<-psSim()

str(dt)
## 'data.frame':    1000 obs. of  6 variables:
##  $ Xcont.1: num  -0.5605 -0.2302 1.5587 0.0705 0.1293 ...
##  $ Xcont.2: num  -0.996 -1.04 -0.018 -0.132 -2.549 ...
##  $ Xcat.1 : int  0 1 0 1 0 0 1 0 0 1 ...
##  $ Xcat.2 : int  0 1 1 0 0 0 0 0 1 0 ...
##  $ Treat  : int  0 0 0 0 0 0 0 1 0 0 ...
##  $ mort   : int  0 1 1 0 1 0 1 0 1 1 ...
  1. to examine the balance of covariates between treated and untreated groups
library(tableone)
myVars <- names(dt)[1:4]
tabbefore <- CreateTableOne(vars = myVars,
                              data = dt,
                              strata = 'Treat',
                              factorVars = c('Xcat.1','Xcat.2'),
                              smd = T)
tabbefore <- print(tabbefore,
                     printToggle = FALSE,
                     noSpaces = TRUE, smd=TRUE,
                     quote=T)

tabbefore
##                        "Stratified by Treat"
##  ""                     "0"            "1"            "p"      "test" "SMD"  
##   "n"                   "766"          "234"          ""       ""     ""     
##   "Xcont.1 (mean (SD))" "0.12 (0.99)"  "-0.32 (0.94)" "<0.001" ""     "0.455"
##   "Xcont.2 (mean (SD))" "-0.25 (0.89)" "1.00 (0.77)"  "<0.001" ""     "1.499"
##   "Xcat.1 = 1 (%)"      "263 (34.3)"   "19 (8.1)"     "<0.001" ""     "0.677"
##   "Xcat.2 = 1 (%)"      "279 (36.4)"   "23 (9.8)"     "<0.001" ""     "0.665"
  1. PSM
#install.packages("MatchIt")
library(MatchIt);
m.out<-matchit(Treat~ Xcont.1+Xcont.2+Xcat.1+Xcat.2,
                 dt, method = "nearest", caliper=0.1)
  1. SMD
#install.packages("cobalt")
library(cobalt)

bal.tab(m.out,m.threshold=0.1)
## Call
##  matchit(formula = Treat ~ Xcont.1 + Xcont.2 + Xcat.1 + Xcat.2, 
##     data = dt, method = "nearest", caliper = 0.1)
## 
## Balance Measures
##              Type Diff.Adj    M.Threshold
## distance Distance   0.0455 Balanced, <0.1
## Xcont.1   Contin.   0.0271 Balanced, <0.1
## Xcont.2   Contin.   0.0506 Balanced, <0.1
## Xcat.1     Binary  -0.0114 Balanced, <0.1
## Xcat.2     Binary   0.0000 Balanced, <0.1
## 
## Balance tally for mean differences
##                    count
## Balanced, <0.1         5
## Not Balanced, >0.1     0
## 
## Variable with the greatest mean difference
##  Variable Diff.Adj    M.Threshold
##   Xcont.2   0.0506 Balanced, <0.1
## 
## Sample sizes
##           Control Treated
## All           766     234
## Matched        88      88
## Unmatched     678     146
  1. Visualization the distribution changes before and after matching
bal.plot(m.out,var.name = 'Xcont.2',which = 'both')
image.png
bal.plot(m.out,var.name = 'Xcat.1',which = 'both')
image.png
  1. Publication quality plot (change the temporary variable names)
v <- data.frame(old = c("Xcont.1","Xcont.2","Xcat.1","Xcat.2"),
                new = c("Age", "WBC", "Gender",'Surgery'))
love.plot(bal.tab(m.out, m.threshold=0.1),
            stat = "mean.diffs", var.names = v, abs = F)
## Warning: Standardized mean differences and raw mean differences are present in the same plot. 
## Use the 'stars' argument to distinguish between them and appropriately label the x-axis.
image.png
  1. to compare difference after PSM (refer to tabbefore)
df.match <- match.data(m.out)[1:ncol(dt)]
tabafter <- CreateTableOne(vars = myVars,
                             data = df.match,
                             strata = 'Treat',
                             factorVars = c('Xcat.1','Xcat.2'),
                             smd = T)
tabafter <- print(tabafter,
                    printToggle = FALSE,
                    noSpaces = TRUE,smd=TRUE)

tabafter;
##                      Stratified by Treat
##                       0              1              p       test SMD     
##   n                   "88"           "88"           ""      ""   ""      
##   Xcont.1 (mean (SD)) "-0.18 (0.93)" "-0.15 (1.04)" "0.864" ""   "0.026" 
##   Xcont.2 (mean (SD)) "0.50 (0.67)"  "0.54 (0.76)"  "0.719" ""   "0.054" 
##   Xcat.1 = 1 (%)      "9 (10.2)"     "8 (9.1)"      "1.000" ""   "0.038" 
##   Xcat.2 = 1 (%)      "12 (13.6)"    "12 (13.6)"    "1.000" ""   "<0.001"

8.1 SMD calculation in CreateTableOne()

abs((mean(df.match[df.match$Treat==1,'Xcont.1'])-
       mean(df.match[df.match$Treat==0,'Xcont.1'])))/
  sqrt((var(df.match[df.match$Treat==1,'Xcont.1'])+
          var(df.match[df.match$Treat==0,'Xcont.1']))/2)
## [1] 0.02581165

8.2 SMD calculation in tab():

(mean(df.match[df.match$Treat==1,'Xcont.1'])-
    mean(df.match[df.match$Treat==0,'Xcont.1']))/
  sqrt((var(dt[dt$Treat==1,'Xcont.1'])))
## [1] 0.02705606
  1. Variance ratio

Note: A variance ratio of 1 in matched sample indicates a good matching, and a variance ratio below 2 is generally acceptable.

bal.tab(m.out,v.threshold=2)
## Call
##  matchit(formula = Treat ~ Xcont.1 + Xcont.2 + Xcat.1 + Xcat.2, 
##     data = dt, method = "nearest", caliper = 0.1)
## 
## Balance Measures
##              Type Diff.Adj V.Ratio.Adj  V.Threshold
## distance Distance   0.0455      1.0950 Balanced, <2
## Xcont.1   Contin.   0.0271      1.2512 Balanced, <2
## Xcont.2   Contin.   0.0506      1.2954 Balanced, <2
## Xcat.1     Binary  -0.0114           .             
## Xcat.2     Binary   0.0000           .             
## 
## Balance tally for variance ratios
##                  count
## Balanced, <2         3
## Not Balanced, >2     0
## 
## Variable with the greatest variance ratio
##  Variable V.Ratio.Adj  V.Threshold
##   Xcont.2      1.2954 Balanced, <2
## 
## Sample sizes
##           Control Treated
## All           766     234
## Matched        88      88
## Unmatched     678     146
  1. Prognostic score for assessing balance

The prognostic score is defined as the predicted probability of outcome under the control condition. It can be estimated by regressing the outcome on covariates in the control group. Then that fitted model is used to predict outcome for all subjects.

ctrl.data <- dt[dt$Treat == 0,]
ctrl.fit <- glm(mort ~ Xcont.1+Xcont.2+Xcat.1+Xcat.2,
                  data = ctrl.data)
dt$prog.score <- predict(ctrl.fit, dt)

bal.tab(m.out, distance = dt["prog.score"])
## Call
##  matchit(formula = Treat ~ Xcont.1 + Xcont.2 + Xcat.1 + Xcat.2, 
##     data = dt, method = "nearest", caliper = 0.1)
## 
## Balance Measures
##                Type Diff.Adj
## prog.score Distance   0.0360
## distance   Distance   0.0455
## Xcont.1     Contin.   0.0271
## Xcont.2     Contin.   0.0506
## Xcat.1       Binary  -0.0114
## Xcat.2       Binary   0.0000
## 
## Sample sizes
##           Control Treated
##  All           766     234
## Matched        88      88
## Unmatched     678     146
  1. to identify evidence of model misspecification
library(car)
mod1<-glm(Treat~Xcont.1+Xcont.2+Xcat.1+Xcat.2,
            dt,family = binomial)
residualPlots(mod1,terms=~Xcont.1+Xcont.2,fitted=T)

##         Test stat Pr(>|Test stat|)
## Xcont.1    0.5216           0.4701
## Xcont.2    0.6596           0.4167
image.png

Reference:
Zhang Z, Kim HJ, Lonjon G, Zhu Y; written on behalf of AME Big-Data Clinical Trial Collaborative Group. Balance diagnostics after propensity score matching. Ann Transl Med 2019;7(1):16. doi: 10.21037/atm.2018.12.10

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末谭确,一起剝皮案震驚了整個濱河市液兽,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖离赫,帶你破解...
    沈念sama閱讀 222,183評論 6 516
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件坚踩,死亡現(xiàn)場離奇詭異墓阀,居然都是意外死亡毡惜,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,850評論 3 399
  • 文/潘曉璐 我一進店門斯撮,熙熙樓的掌柜王于貴愁眉苦臉地迎上來经伙,“玉大人,你說我怎么就攤上這事勿锅∨聊ぃ” “怎么了?”我有些...
    開封第一講書人閱讀 168,766評論 0 361
  • 文/不壞的土叔 我叫張陵溢十,是天一觀的道長垮刹。 經(jīng)常有香客問我,道長张弛,這世上最難降的妖魔是什么荒典? 我笑而不...
    開封第一講書人閱讀 59,854評論 1 299
  • 正文 為了忘掉前任,我火速辦了婚禮乌庶,結(jié)果婚禮上种蝶,老公的妹妹穿的比我還像新娘。我一直安慰自己瞒大,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 68,871評論 6 398
  • 文/花漫 我一把揭開白布搪桂。 她就那樣靜靜地躺著透敌,像睡著了一般。 火紅的嫁衣襯著肌膚如雪踢械。 梳的紋絲不亂的頭發(fā)上酗电,一...
    開封第一講書人閱讀 52,457評論 1 311
  • 那天,我揣著相機與錄音内列,去河邊找鬼撵术。 笑死,一個胖子當(dāng)著我的面吹牛话瞧,可吹牛的內(nèi)容都是我干的嫩与。 我是一名探鬼主播,決...
    沈念sama閱讀 40,999評論 3 422
  • 文/蒼蘭香墨 我猛地睜開眼交排,長吁一口氣:“原來是場噩夢啊……” “哼划滋!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起埃篓,我...
    開封第一講書人閱讀 39,914評論 0 277
  • 序言:老撾萬榮一對情侶失蹤处坪,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體同窘,經(jīng)...
    沈念sama閱讀 46,465評論 1 319
  • 正文 獨居荒郊野嶺守林人離奇死亡玄帕,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,543評論 3 342
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了想邦。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片桨仿。...
    茶點故事閱讀 40,675評論 1 353
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖案狠,靈堂內(nèi)的尸體忽然破棺而出服傍,到底是詐尸還是另有隱情,我是刑警寧澤骂铁,帶...
    沈念sama閱讀 36,354評論 5 351
  • 正文 年R本政府宣布吹零,位于F島的核電站,受9級特大地震影響拉庵,放射性物質(zhì)發(fā)生泄漏灿椅。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 42,029評論 3 335
  • 文/蒙蒙 一钞支、第九天 我趴在偏房一處隱蔽的房頂上張望茫蛹。 院中可真熱鬧,春花似錦烁挟、人聲如沸婴洼。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,514評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽柬采。三九已至,卻和暖如春且警,著一層夾襖步出監(jiān)牢的瞬間粉捻,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,616評論 1 274
  • 我被黑心中介騙來泰國打工斑芜, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留肩刃,地道東北人。 一個月前我還...
    沈念sama閱讀 49,091評論 3 378
  • 正文 我出身青樓杏头,卻偏偏與公主長得像盈包,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子大州,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 45,685評論 2 360

推薦閱讀更多精彩內(nèi)容