I used the WeightIt package to generate an a weightit object and examined covariate balance. Then I extracted weights from this object and added the weights to the original data. Then I used the survey package to generate a svydesign. Then I used svyCreateTableOne to create Table 1. However, I find that the SMD calculated by svyCreateTableOne and cobalt::bal.tab are not the same.
iptw_obj2 <- weightit(
formula = as.formula(paste("cvp_group2 ~", paste(name_cov, collapse = " + "))),
data = hfsepsis_imputed,
estimand = "ATE",
method = "gbm",
stop.method = "es.mean"
)
bal.tab(iptw_obj2,
stats = c("m", "v"),
abs = TRUE,
thresholds = c(m = 0.1, v = 2))
Balance Measures
Type Diff.Adj M.Threshold V.Ratio.Adj V.Threshold
prop.score Distance 0.3705 1.2690 Balanced, <2
age Contin. 0.0355 Balanced, <0.1 1.0978 Balanced, <2
insurance_Medicare Binary 0.0058 Balanced, <0.1 .
insurance_Medicaid Binary 0.0008 Balanced, <0.1 .
insurance_Other Binary 0.0043 Balanced, <0.1 .
insurance_Private Binary 0.0023 Balanced, <0.1 .
renal_disease Binary 0.0017 Balanced, <0.1 .
severe_liver_disease Binary 0.0100 Balanced, <0.1 .
metastatic_cancer Binary 0.0038 Balanced, <0.1 .
aids Binary 0.0036 Balanced, <0.1 .
mbp Contin. 0.0521 Balanced, <0.1 1.0301 Balanced, <2
heart_rate Contin. 0.0111 Balanced, <0.1 1.0819 Balanced, <2
spo2 Contin. 0.0570 Balanced, <0.1 1.0476 Balanced, <2
lactate Contin. 0.0107 Balanced, <0.1 1.0402 Balanced, <2
creatinine Contin. 0.0381 Balanced, <0.1 1.3537 Balanced, <2
bun Contin. 0.0020 Balanced, <0.1 1.0208 Balanced, <2
potassium Contin. 0.0319 Balanced, <0.1 1.1055 Balanced, <2
platelet Contin. 0.0185 Balanced, <0.1 1.2390 Balanced, <2
inr Contin. 0.0406 Balanced, <0.1 1.2943 Balanced, <2
sofa Contin. 0.0801 Balanced, <0.1 1.0313 Balanced, <2
apsiii Contin. 0.0134 Balanced, <0.1 1.0167 Balanced, <2
vasoactive Binary 0.0813 Balanced, <0.1 .
mechanical_ventilation Binary 0.0528 Balanced, <0.1 .
hfsepsis_imputed$iptw_w2 <- weights(iptw_obj2)
iptw_design2 <- svydesign(
id = ~1,
weights = ~iptw_w2,
data = hfsepsis_imputed
)
iptw_fit2 <- svyglm(
formula = as.formula("thirty_day_death ~ cvp_group2"),
design = iptw_design2,
family = quasibinomial(link = "logit")
)
tab2 <- svyCreateTableOne(
strata = "cvp_group2",
vars = name_cov,
data = iptw_design2)
tab2csv <- print(tab2, showAllLevels = TRUE, smd = TRUE)
Stratified by cvp_group2
level 0 1 p test SMD
n 9032.48 7325.55
age (mean (SD)) 73.08 (13.40) 72.62 (12.79) 0.282 0.036
insurance (%) Medicare 6614.5 (73.2) 5321.9 (72.6) 0.728 0.037
Medicaid 943.0 (10.4) 758.6 (10.4)
Other 110.8 ( 1.2) 121.5 ( 1.7)
Private 1364.2 (15.1) 1123.5 (15.3)
renal_disease (%) 0 5253.7 (58.2) 4248.2 (58.0) 0.922 0.004
1 3778.8 (41.8) 3077.4 (42.0)
severe_liver_disease (%) 0 8658.5 (95.9) 7095.8 (96.9) 0.094 0.054
1 374.0 ( 4.1) 229.7 ( 3.1)
metastatic_cancer (%) 0 8658.8 (95.9) 7050.3 (96.2) 0.685 0.019
1 373.6 ( 4.1) 275.3 ( 3.8)
aids (%) 0 8984.9 (99.5) 7313.6 (99.8) 0.100 0.062
1 47.6 ( 0.5) 12.0 ( 0.2)
mbp (mean (SD)) 81.27 (18.84) 80.34 (19.12) 0.179 0.049
heart_rate (mean (SD)) 90.10 (20.92) 89.89 (20.11) 0.772 0.011
spo2 (mean (SD)) 96.29 (4.65) 96.54 (4.54) 0.109 0.055
lactate (mean (SD)) 2.21 (1.75) 2.19 (1.72) 0.673 0.012
creatinine (mean (SD)) 1.92 (1.76) 1.85 (1.51) 0.256 0.038
bun (mean (SD)) 37.33 (26.16) 37.37 (25.89) 0.957 0.002
potassium (mean (SD)) 4.36 (0.82) 4.33 (0.78) 0.360 0.031
platelet (mean (SD)) 209.72 (111.16) 207.77 (99.83) 0.575 0.018
inr (mean (SD)) 1.73 (1.14) 1.69 (1.00) 0.151 0.042
sofa (mean (SD)) 6.38 (3.33) 6.65 (3.28) 0.019 0.080
apsiii (mean (SD)) 53.76 (20.07) 54.04 (20.23) 0.648 0.014
vasoactive (%) 0 4919.9 (54.5) 3394.6 (46.3) <0.001 0.163
1 4112.5 (45.5) 3930.9 (53.7)
mechanical_ventilation (%) 0 4253.6 (47.1) 3063.0 (41.8) 0.004 0.106
1 4778.8 (52.9) 4262.5 (58.2)
I tried to find out why. So I compared SMD of the raw data calculated by cobalt::bal.tab and CreateTableOne. I found that bal.tab and CreateTableOne generated the same SMD for continuous data, but different SMD for categorical data.
bal.tab(as.formula(paste("cvp_group2 ~", paste(name_cov, collapse = " + "))),
data = hfsepsis_imputed,
estimand = "ATE",
stats = c("m","v"),
abs = TRUE,
thresholds = c(m = 0.1, v = 2))
Balance Measures
Type Diff.Un M.Threshold.Un V.Ratio.Un V.Threshold.Un
age Contin. 0.2371 Not Balanced, >0.1 1.0312 Balanced, <2
insurance_Medicare Binary 0.0759 Balanced, <0.1 .
insurance_Medicaid Binary 0.0013 Balanced, <0.1 .
insurance_Other Binary 0.0057 Balanced, <0.1 .
insurance_Private Binary 0.0714 Balanced, <0.1 .
renal_disease Binary 0.0932 Balanced, <0.1 .
severe_liver_disease Binary 0.0191 Balanced, <0.1 .
metastatic_cancer Binary 0.0298 Balanced, <0.1 .
aids Binary 0.0050 Balanced, <0.1 .
mbp Contin. 0.2789 Not Balanced, >0.1 1.3304 Balanced, <2
heart_rate Contin. 0.1857 Not Balanced, >0.1 1.5630 Balanced, <2
spo2 Contin. 0.3817 Not Balanced, >0.1 1.2605 Balanced, <2
lactate Contin. 0.0599 Balanced, <0.1 1.3695 Balanced, <2
creatinine Contin. 0.2116 Not Balanced, >0.1 1.7829 Balanced, <2
bun Contin. 0.2837 Not Balanced, >0.1 1.3720 Balanced, <2
potassium Contin. 0.0620 Balanced, <0.1 1.3276 Balanced, <2
platelet Contin. 0.2331 Not Balanced, >0.1 1.4547 Balanced, <2
inr Contin. 0.0408 Balanced, <0.1 1.2697 Balanced, <2
sofa Contin. 0.3902 Not Balanced, >0.1 1.0434 Balanced, <2
apsiii Contin. 0.0815 Balanced, <0.1 1.3864 Balanced, <2
vasoactive Binary 0.4341 Not Balanced, >0.1 .
mechanical_ventilation Binary 0.3103 Not Balanced, >0.1 .
tab1 <- CreateTableOne(
strata = "cvp_group2",
vars = name_cov,
data = hfsepsis_imputed)
tab1csv <- print(tab1, showAllLevels = TRUE, smd = TRUE)
Stratified by cvp_group2
level 0 1 p test SMD
n 7182 2064
age (mean (SD)) 73.89 (13.28) 70.76 (13.08) <0.001 0.237
insurance (%) Medicare 5406 (75.3) 1397 (67.7) <0.001 0.203
Medicaid 740 (10.3) 210 (10.2)
Other 91 ( 1.3) 38 ( 1.8)
Private 945 (13.2) 419 (20.3)
renal_disease (%) 0 4049 (56.4) 1356 (65.7) <0.001 0.192
1 3133 (43.6) 708 (34.3)
severe_liver_disease (%) 0 6864 (95.6) 2012 (97.5) <0.001 0.104
1 318 ( 4.4) 52 ( 2.5)
metastatic_cancer (%) 0 6850 (95.4) 2030 (98.4) <0.001 0.171
1 332 ( 4.6) 34 ( 1.6)
aids (%) 0 7139 (99.4) 2062 (99.9) 0.007 0.085
1 43 ( 0.6) 2 ( 0.1)
mbp (mean (SD)) 82.15 (19.21) 77.13 (16.65) <0.001 0.279
heart_rate (mean (SD)) 90.84 (21.60) 87.20 (17.28) <0.001 0.186
spo2 (mean (SD)) 95.96 (4.68) 97.65 (4.17) <0.001 0.382
lactate (mean (SD)) 2.25 (1.73) 2.14 (2.02) 0.012 0.060
creatinine (mean (SD)) 1.99 (1.83) 1.64 (1.37) <0.001 0.212
bun (mean (SD)) 38.68 (26.69) 31.64 (22.78) <0.001 0.284
potassium (mean (SD)) 4.37 (0.84) 4.32 (0.73) 0.017 0.062
platelet (mean (SD)) 214.54 (113.99) 190.14 (94.51) <0.001 0.233
inr (mean (SD)) 1.74 (1.16) 1.70 (1.03) 0.113 0.041
sofa (mean (SD)) 6.14 (3.32) 7.42 (3.25) <0.001 0.390
apsiii (mean (SD)) 54.34 (19.49) 52.60 (22.95) 0.001 0.082
vasoactive (%) 0 4534 (63.1) 407 (19.7) <0.001 0.982
1 2648 (36.9) 1657 (80.3)
mechanical_ventilation (%) 0 3826 (53.3) 459 (22.2) <0.001 0.676
1 3356 (46.7) 1605 (77.8)
I used the
WeightItpackage to generate an aweightitobject and examined covariate balance. Then I extracted weights from this object and added the weights to the original data. Then I used the survey package to generate asvydesign. Then I usedsvyCreateTableOneto create Table 1. However, I find that the SMD calculated bysvyCreateTableOneandcobalt::bal.tabare not the same.I tried to find out why. So I compared SMD of the raw data calculated by
cobalt::bal.tabandCreateTableOne. I found thatbal.tabandCreateTableOnegenerated the same SMD for continuous data, but different SMD for categorical data.