In [ ]:
system("ln -s /home/ec2-user/anaconda3/envs/R_Beta/bin/x86_64-conda_cos6-linux-gnu-c++ /home/ec2-user/anaconda3/bin/x86_64-conda_cos6-linux-gnu-c++")
system("ln -s /home/ec2-user/anaconda3/envs/R_Beta/bin/x86_64-conda_cos6-linux-gnu-cc /home/ec2-user/anaconda3/bin/x86_64-conda_cos6-linux-gnu-cc")

In [ ]:
install.packages('pROC')
install.packages('Matching')
knitr::opts_chunk$set(echo = TRUE)

In [1]:
wdpath = path.expand("./")
setwd(wdpath)
dataset = read.csv(file="aline_data.csv",head=TRUE,sep=",")

In [2]:
dataset$icustay_id = factor(dataset$icustay_id)
dataset$day_28_flag = factor(dataset$day_28_flag, levels=c(0,1))
dataset$gender = factor(dataset$gender, levels=c("F","M"))
dataset$day_icu_intime = factor(dataset$day_icu_intime)
dataset$hour_icu_intime = factor(dataset$hour_icu_intime)
dataset$icu_hour_flag = factor(dataset$icu_hour_flag, levels=c(0,1))
#dataset$sepsis_flag = factor(dataset$sepsis_flag, levels=c(0,1))
dataset$sedative_flag = factor(dataset$sedative_flag, levels=c(0,1))
dataset$fentanyl_flag = factor(dataset$fentanyl_flag, levels=c(0,1))
dataset$midazolam_flag = factor(dataset$midazolam_flag, levels=c(0,1))
dataset$propofol_flag = factor(dataset$propofol_flag, levels=c(0,1))
#dataset$dilaudid_flag = factor(dataset$dilaudid_flag, levels=c(0,1))
dataset$chf_flag = factor(dataset$chf_flag, levels=c(0,1))
dataset$afib_flag = factor(dataset$afib_flag, levels=c(0,1))
dataset$renal_flag = factor(dataset$renal_flag, levels=c(0,1))
dataset$liver_flag = factor(dataset$liver_flag, levels=c(0,1))
dataset$copd_flag = factor(dataset$copd_flag, levels=c(0,1))
dataset$cad_flag = factor(dataset$cad_flag, levels=c(0,1))
dataset$stroke_flag = factor(dataset$stroke_flag, levels=c(0,1))
dataset$malignancy_flag = factor(dataset$malignancy_flag, levels=c(0,1))
dataset$respfail_flag = factor(dataset$respfail_flag, levels=c(0,1))
dataset$ards_flag = factor(dataset$ards_flag, levels=c(0,1))
dataset$pneumonia_flag = factor(dataset$pneumonia_flag, levels=c(0,1))

# custom factor
dataset$service_surg = factor( dataset$service_unit == 'SURG', levels=c(FALSE,TRUE))

In [3]:
# we could impute data if we like - e.g. the below imputes the mean
# we currently do complete case analysis however
imputeFlag = 0
if (imputeFlag != 0){
  print("Imputing missing data for some features...")
for (col in c("weight_first","temp_first","spo2_first",
              "bun_first","creatinine_first", "chloride_first", "hgb_first",
              "platelet_first", "potassium_first", "sodium_first", "tco2_first", "wbc_first"))
{
  print(paste("Imputing data for: ", col))
  dataset[is.na(dataset[,col]),col] = mean(dataset[,col], na.rm=TRUE)
}
}

In [4]:
# subselect the variables
dat = dataset[,c("aline_flag",
                  "age","gender","weight_first","sofa_first","service_surg",
                  "day_icu_intime","hour_icu_intime",
                  "chf_flag","afib_flag","renal_flag",
                  "liver_flag","copd_flag","cad_flag","stroke_flag",
                  "malignancy_flag","respfail_flag",
                  "map_first","hr_first","temp_first","spo2_first",
                  "bun_first","chloride_first","creatinine_first",
                  "hgb_first","platelet_first",
                  "potassium_first","sodium_first","tco2_first","wbc_first")]

idxKeep = complete.cases(dat)
dat = dat[idxKeep,]
y <- dataset[idxKeep,"day_28_flag"]

print(paste('Removed', sum(!idxKeep),'rows with missing data.'))


[1] "Removed 161 rows with missing data."

In [5]:
# fit GLM
glm_fitted = glm(aline_flag ~ ., data=dat, family="binomial", na.action = na.exclude)

In [6]:
# run step-wise AIC
library(MASS);  
glm_fitted  <- stepAIC(glm_fitted )

X <- fitted(glm_fitted, type="response")
Tr <- dat$aline_flag

library("pROC")    
roccurve <- roc(Tr ~ X)
plot(roccurve, col=rainbow(7), main="ROC curve", xlab="Specificity", ylab="Sensitivity")
auc(roccurve)


Start:  AIC=3053.01
aline_flag ~ age + gender + weight_first + sofa_first + service_surg + 
    day_icu_intime + hour_icu_intime + chf_flag + afib_flag + 
    renal_flag + liver_flag + copd_flag + cad_flag + stroke_flag + 
    malignancy_flag + respfail_flag + map_first + hr_first + 
    temp_first + spo2_first + bun_first + chloride_first + creatinine_first + 
    hgb_first + platelet_first + potassium_first + sodium_first + 
    tco2_first + wbc_first

                   Df Deviance    AIC
- hour_icu_intime  23   2976.6 3044.6
- day_icu_intime    6   2947.5 3049.5
- creatinine_first  1   2939.1 3051.1
- hr_first          1   2939.2 3051.2
- afib_flag         1   2939.2 3051.2
- temp_first        1   2939.2 3051.2
- cad_flag          1   2939.4 3051.4
- age               1   2939.5 3051.5
- chf_flag          1   2939.6 3051.6
- spo2_first        1   2939.6 3051.6
- gender            1   2939.6 3051.6
- malignancy_flag   1   2939.7 3051.7
- hgb_first         1   2939.9 3051.9
- respfail_flag     1   2940.0 3052.0
- bun_first         1   2940.1 3052.1
<none>                  2939.0 3053.0
- potassium_first   1   2941.1 3053.1
- platelet_first    1   2941.5 3053.5
- weight_first      1   2942.5 3054.5
- renal_flag        1   2944.2 3056.2
- tco2_first        1   2944.3 3056.3
- liver_flag        1   2944.6 3056.6
- copd_flag         1   2946.6 3058.6
- map_first         1   2952.2 3064.2
- sodium_first      1   2960.3 3072.3
- sofa_first        1   2964.5 3076.5
- wbc_first         1   2968.7 3080.7
- stroke_flag       1   2976.8 3088.8
- chloride_first    1   2978.2 3090.2
- service_surg      1   2990.9 3102.9

Step:  AIC=3044.6
aline_flag ~ age + gender + weight_first + sofa_first + service_surg + 
    day_icu_intime + chf_flag + afib_flag + renal_flag + liver_flag + 
    copd_flag + cad_flag + stroke_flag + malignancy_flag + respfail_flag + 
    map_first + hr_first + temp_first + spo2_first + bun_first + 
    chloride_first + creatinine_first + hgb_first + platelet_first + 
    potassium_first + sodium_first + tco2_first + wbc_first

                   Df Deviance    AIC
- day_icu_intime    6   2982.9 3038.9
- creatinine_first  1   2976.6 3042.6
- hr_first          1   2976.7 3042.7
- afib_flag         1   2976.8 3042.8
- age               1   2976.8 3042.8
- spo2_first        1   2976.9 3042.9
- gender            1   2977.0 3043.0
- temp_first        1   2977.0 3043.0
- cad_flag          1   2977.1 3043.1
- malignancy_flag   1   2977.2 3043.2
- chf_flag          1   2977.2 3043.2
- respfail_flag     1   2977.4 3043.4
- hgb_first         1   2977.7 3043.7
- bun_first         1   2977.7 3043.7
- potassium_first   1   2977.9 3043.9
<none>                  2976.6 3044.6
- platelet_first    1   2979.5 3045.5
- weight_first      1   2979.8 3045.8
- renal_flag        1   2982.3 3048.3
- tco2_first        1   2982.6 3048.6
- liver_flag        1   2982.8 3048.8
- copd_flag         1   2985.8 3051.8
- map_first         1   2989.9 3055.9
- sodium_first      1   2998.7 3064.7
- sofa_first        1   3002.4 3068.4
- wbc_first         1   3005.7 3071.7
- stroke_flag       1   3014.7 3080.7
- chloride_first    1   3017.9 3083.9
- service_surg      1   3032.2 3098.2

Step:  AIC=3038.9
aline_flag ~ age + gender + weight_first + sofa_first + service_surg + 
    chf_flag + afib_flag + renal_flag + liver_flag + copd_flag + 
    cad_flag + stroke_flag + malignancy_flag + respfail_flag + 
    map_first + hr_first + temp_first + spo2_first + bun_first + 
    chloride_first + creatinine_first + hgb_first + platelet_first + 
    potassium_first + sodium_first + tco2_first + wbc_first

                   Df Deviance    AIC
- creatinine_first  1   2982.9 3036.9
- hr_first          1   2983.0 3037.0
- afib_flag         1   2983.1 3037.1
- age               1   2983.1 3037.1
- spo2_first        1   2983.2 3037.2
- temp_first        1   2983.3 3037.3
- gender            1   2983.4 3037.4
- cad_flag          1   2983.5 3037.5
- chf_flag          1   2983.5 3037.5
- malignancy_flag   1   2983.6 3037.6
- respfail_flag     1   2983.7 3037.7
- hgb_first         1   2983.8 3037.8
- bun_first         1   2984.2 3038.2
- potassium_first   1   2984.4 3038.4
<none>                  2982.9 3038.9
- platelet_first    1   2985.6 3039.6
- weight_first      1   2985.9 3039.9
- renal_flag        1   2988.6 3042.6
- tco2_first        1   2988.7 3042.7
- liver_flag        1   2989.0 3043.0
- copd_flag         1   2992.1 3046.1
- map_first         1   2995.9 3049.9
- sodium_first      1   3005.6 3059.6
- sofa_first        1   3009.5 3063.5
- wbc_first         1   3012.2 3066.2
- stroke_flag       1   3020.8 3074.8
- chloride_first    1   3024.8 3078.8
- service_surg      1   3038.9 3092.9

Step:  AIC=3036.9
aline_flag ~ age + gender + weight_first + sofa_first + service_surg + 
    chf_flag + afib_flag + renal_flag + liver_flag + copd_flag + 
    cad_flag + stroke_flag + malignancy_flag + respfail_flag + 
    map_first + hr_first + temp_first + spo2_first + bun_first + 
    chloride_first + hgb_first + platelet_first + potassium_first + 
    sodium_first + tco2_first + wbc_first

                  Df Deviance    AIC
- hr_first         1   2983.0 3035.0
- afib_flag        1   2983.1 3035.1
- age              1   2983.1 3035.1
- spo2_first       1   2983.2 3035.2
- temp_first       1   2983.3 3035.3
- gender           1   2983.4 3035.4
- cad_flag         1   2983.5 3035.5
- chf_flag         1   2983.5 3035.5
- malignancy_flag  1   2983.6 3035.6
- respfail_flag    1   2983.7 3035.7
- hgb_first        1   2983.8 3035.8
- potassium_first  1   2984.4 3036.4
- bun_first        1   2984.6 3036.6
<none>                 2982.9 3036.9
- platelet_first   1   2985.6 3037.6
- weight_first     1   2985.9 3037.9
- tco2_first       1   2988.8 3040.8
- liver_flag       1   2989.1 3041.1
- renal_flag       1   2989.1 3041.1
- copd_flag        1   2992.1 3044.1
- map_first        1   2996.0 3048.0
- sodium_first     1   3005.8 3057.8
- sofa_first       1   3010.7 3062.7
- wbc_first        1   3012.2 3064.2
- stroke_flag      1   3020.8 3072.8
- chloride_first   1   3025.9 3077.9
- service_surg     1   3038.9 3090.9

Step:  AIC=3035
aline_flag ~ age + gender + weight_first + sofa_first + service_surg + 
    chf_flag + afib_flag + renal_flag + liver_flag + copd_flag + 
    cad_flag + stroke_flag + malignancy_flag + respfail_flag + 
    map_first + temp_first + spo2_first + bun_first + chloride_first + 
    hgb_first + platelet_first + potassium_first + sodium_first + 
    tco2_first + wbc_first

                  Df Deviance    AIC
- age              1   2983.2 3033.2
- afib_flag        1   2983.2 3033.2
- temp_first       1   2983.3 3033.3
- spo2_first       1   2983.3 3033.3
- gender           1   2983.5 3033.5
- cad_flag         1   2983.6 3033.6
- chf_flag         1   2983.7 3033.7
- malignancy_flag  1   2983.7 3033.7
- respfail_flag    1   2983.9 3033.9
- hgb_first        1   2983.9 3033.9
- potassium_first  1   2984.5 3034.5
- bun_first        1   2984.7 3034.7
<none>                 2983.0 3035.0
- platelet_first   1   2985.7 3035.7
- weight_first     1   2986.0 3036.0
- tco2_first       1   2989.1 3039.1
- renal_flag       1   2989.2 3039.2
- liver_flag       1   2989.4 3039.4
- copd_flag        1   2992.4 3042.4
- map_first        1   2996.2 3046.2
- sodium_first     1   3006.2 3056.2
- sofa_first       1   3010.7 3060.7
- wbc_first        1   3012.3 3062.3
- stroke_flag      1   3021.6 3071.6
- chloride_first   1   3026.3 3076.3
- service_surg     1   3038.9 3088.9

Step:  AIC=3033.15
aline_flag ~ gender + weight_first + sofa_first + service_surg + 
    chf_flag + afib_flag + renal_flag + liver_flag + copd_flag + 
    cad_flag + stroke_flag + malignancy_flag + respfail_flag + 
    map_first + temp_first + spo2_first + bun_first + chloride_first + 
    hgb_first + platelet_first + potassium_first + sodium_first + 
    tco2_first + wbc_first

                  Df Deviance    AIC
- afib_flag        1   2983.2 3031.2
- temp_first       1   2983.5 3031.5
- spo2_first       1   2983.5 3031.5
- gender           1   2983.8 3031.8
- chf_flag         1   2983.8 3031.8
- cad_flag         1   2983.9 3031.9
- malignancy_flag  1   2983.9 3031.9
- hgb_first        1   2984.0 3032.0
- respfail_flag    1   2984.1 3032.1
- potassium_first  1   2984.7 3032.7
- bun_first        1   2984.8 3032.8
<none>                 2983.2 3033.2
- platelet_first   1   2985.8 3033.8
- weight_first     1   2986.4 3034.4
- tco2_first       1   2989.2 3037.2
- renal_flag       1   2989.3 3037.3
- liver_flag       1   2989.5 3037.5
- copd_flag        1   2992.8 3040.8
- map_first        1   2996.3 3044.3
- sodium_first     1   3006.3 3054.3
- sofa_first       1   3010.8 3058.8
- wbc_first        1   3013.4 3061.4
- stroke_flag      1   3023.3 3071.3
- chloride_first   1   3027.1 3075.1
- service_surg     1   3038.9 3086.9

Step:  AIC=3031.24
aline_flag ~ gender + weight_first + sofa_first + service_surg + 
    chf_flag + renal_flag + liver_flag + copd_flag + cad_flag + 
    stroke_flag + malignancy_flag + respfail_flag + map_first + 
    temp_first + spo2_first + bun_first + chloride_first + hgb_first + 
    platelet_first + potassium_first + sodium_first + tco2_first + 
    wbc_first

                  Df Deviance    AIC
- temp_first       1   2983.5 3029.5
- spo2_first       1   2983.6 3029.6
- gender           1   2983.8 3029.8
- cad_flag         1   2983.9 3029.9
- chf_flag         1   2984.0 3030.0
- malignancy_flag  1   2984.0 3030.0
- hgb_first        1   2984.1 3030.1
- respfail_flag    1   2984.1 3030.1
- potassium_first  1   2984.8 3030.8
- bun_first        1   2984.9 3030.9
<none>                 2983.2 3031.2
- platelet_first   1   2986.0 3032.0
- weight_first     1   2986.5 3032.5
- renal_flag       1   2989.3 3035.3
- tco2_first       1   2989.3 3035.3
- liver_flag       1   2989.7 3035.7
- copd_flag        1   2992.8 3038.8
- map_first        1   2996.4 3042.4
- sodium_first     1   3006.4 3052.4
- sofa_first       1   3010.8 3056.8
- wbc_first        1   3013.4 3059.4
- stroke_flag      1   3025.3 3071.3
- chloride_first   1   3027.1 3073.1
- service_surg     1   3039.0 3085.0

Step:  AIC=3029.54
aline_flag ~ gender + weight_first + sofa_first + service_surg + 
    chf_flag + renal_flag + liver_flag + copd_flag + cad_flag + 
    stroke_flag + malignancy_flag + respfail_flag + map_first + 
    spo2_first + bun_first + chloride_first + hgb_first + platelet_first + 
    potassium_first + sodium_first + tco2_first + wbc_first

                  Df Deviance    AIC
- spo2_first       1   2983.9 3027.9
- gender           1   2984.2 3028.2
- chf_flag         1   2984.2 3028.2
- malignancy_flag  1   2984.3 3028.3
- cad_flag         1   2984.3 3028.3
- hgb_first        1   2984.4 3028.4
- respfail_flag    1   2984.4 3028.4
- bun_first        1   2985.2 3029.2
- potassium_first  1   2985.2 3029.2
<none>                 2983.5 3029.5
- platelet_first   1   2986.2 3030.2
- weight_first     1   2986.9 3030.9
- renal_flag       1   2989.6 3033.6
- tco2_first       1   2989.7 3033.7
- liver_flag       1   2989.9 3033.9
- copd_flag        1   2993.2 3037.2
- map_first        1   2996.5 3040.5
- sodium_first     1   3006.6 3050.6
- sofa_first       1   3011.1 3055.1
- wbc_first        1   3014.3 3058.3
- stroke_flag      1   3025.9 3069.9
- chloride_first   1   3027.2 3071.2
- service_surg     1   3039.6 3083.6

Step:  AIC=3027.89
aline_flag ~ gender + weight_first + sofa_first + service_surg + 
    chf_flag + renal_flag + liver_flag + copd_flag + cad_flag + 
    stroke_flag + malignancy_flag + respfail_flag + map_first + 
    bun_first + chloride_first + hgb_first + platelet_first + 
    potassium_first + sodium_first + tco2_first + wbc_first

                  Df Deviance    AIC
- gender           1   2984.5 3026.5
- chf_flag         1   2984.6 3026.6
- cad_flag         1   2984.7 3026.7
- malignancy_flag  1   2984.7 3026.7
- hgb_first        1   2984.8 3026.8
- respfail_flag    1   2984.9 3026.9
- bun_first        1   2985.4 3027.4
- potassium_first  1   2985.5 3027.5
<none>                 2983.9 3027.9
- platelet_first   1   2986.6 3028.6
- weight_first     1   2987.1 3029.1
- tco2_first       1   2989.8 3031.8
- renal_flag       1   2989.9 3031.9
- liver_flag       1   2990.4 3032.4
- copd_flag        1   2994.0 3036.0
- map_first        1   2996.8 3038.8
- sodium_first     1   3006.8 3048.8
- sofa_first       1   3011.8 3053.8
- wbc_first        1   3014.3 3056.3
- stroke_flag      1   3026.3 3068.3
- chloride_first   1   3027.4 3069.4
- service_surg     1   3039.7 3081.7

Step:  AIC=3026.53
aline_flag ~ weight_first + sofa_first + service_surg + chf_flag + 
    renal_flag + liver_flag + copd_flag + cad_flag + stroke_flag + 
    malignancy_flag + respfail_flag + map_first + bun_first + 
    chloride_first + hgb_first + platelet_first + potassium_first + 
    sodium_first + tco2_first + wbc_first

                  Df Deviance    AIC
- chf_flag         1   2985.1 3025.1
- hgb_first        1   2985.1 3025.1
- cad_flag         1   2985.2 3025.2
- malignancy_flag  1   2985.3 3025.3
- respfail_flag    1   2985.6 3025.6
- potassium_first  1   2986.1 3026.1
- bun_first        1   2986.1 3026.1
<none>                 2984.5 3026.5
- platelet_first   1   2987.5 3027.5
- weight_first     1   2988.7 3028.7
- tco2_first       1   2990.5 3030.5
- renal_flag       1   2990.6 3030.6
- liver_flag       1   2990.9 3030.9
- copd_flag        1   2994.6 3034.6
- map_first        1   2997.3 3037.3
- sodium_first     1   3007.4 3047.4
- sofa_first       1   3013.8 3053.8
- wbc_first        1   3015.3 3055.3
- stroke_flag      1   3026.3 3066.3
- chloride_first   1   3028.4 3068.4
- service_surg     1   3040.0 3080.0

Step:  AIC=3025.09
aline_flag ~ weight_first + sofa_first + service_surg + renal_flag + 
    liver_flag + copd_flag + cad_flag + stroke_flag + malignancy_flag + 
    respfail_flag + map_first + bun_first + chloride_first + 
    hgb_first + platelet_first + potassium_first + sodium_first + 
    tco2_first + wbc_first

                  Df Deviance    AIC
- cad_flag         1   2985.6 3023.6
- hgb_first        1   2985.7 3023.7
- malignancy_flag  1   2985.9 3023.9
- respfail_flag    1   2986.1 3024.1
- potassium_first  1   2986.6 3024.6
- bun_first        1   2986.9 3024.9
<none>                 2985.1 3025.1
- platelet_first   1   2988.1 3026.1
- weight_first     1   2989.3 3027.3
- renal_flag       1   2990.8 3028.8
- tco2_first       1   2991.5 3029.5
- liver_flag       1   2991.5 3029.5
- copd_flag        1   2994.7 3032.7
- map_first        1   2997.8 3035.8
- sodium_first     1   3007.7 3045.7
- sofa_first       1   3014.1 3052.1
- wbc_first        1   3015.8 3053.8
- stroke_flag      1   3026.4 3064.4
- chloride_first   1   3028.4 3066.4
- service_surg     1   3040.3 3078.3

Step:  AIC=3023.61
aline_flag ~ weight_first + sofa_first + service_surg + renal_flag + 
    liver_flag + copd_flag + stroke_flag + malignancy_flag + 
    respfail_flag + map_first + bun_first + chloride_first + 
    hgb_first + platelet_first + potassium_first + sodium_first + 
    tco2_first + wbc_first

                  Df Deviance    AIC
- hgb_first        1   2986.2 3022.2
- malignancy_flag  1   2986.4 3022.4
- respfail_flag    1   2986.6 3022.6
- potassium_first  1   2987.1 3023.1
- bun_first        1   2987.3 3023.3
<none>                 2985.6 3023.6
- platelet_first   1   2988.6 3024.6
- weight_first     1   2989.8 3025.8
- liver_flag       1   2991.9 3027.9
- tco2_first       1   2992.0 3028.0
- renal_flag       1   2992.2 3028.2
- copd_flag        1   2995.3 3031.3
- map_first        1   2998.4 3034.4
- sodium_first     1   3007.9 3043.9
- sofa_first       1   3015.1 3051.1
- wbc_first        1   3016.5 3052.5
- stroke_flag      1   3026.4 3062.4
- chloride_first   1   3028.9 3064.9
- service_surg     1   3040.7 3076.7

Step:  AIC=3022.25
aline_flag ~ weight_first + sofa_first + service_surg + renal_flag + 
    liver_flag + copd_flag + stroke_flag + malignancy_flag + 
    respfail_flag + map_first + bun_first + chloride_first + 
    platelet_first + potassium_first + sodium_first + tco2_first + 
    wbc_first

                  Df Deviance    AIC
- malignancy_flag  1   2986.8 3020.8
- respfail_flag    1   2987.1 3021.1
- potassium_first  1   2987.9 3021.9
<none>                 2986.2 3022.2
- bun_first        1   2988.6 3022.6
- platelet_first   1   2989.1 3023.1
- weight_first     1   2990.1 3024.1
- liver_flag       1   2992.2 3026.2
- renal_flag       1   2992.6 3026.6
- tco2_first       1   2994.2 3028.2
- copd_flag        1   2995.8 3029.8
- map_first        1   2998.8 3032.8
- sodium_first     1   3015.8 3049.8
- sofa_first       1   3016.0 3050.0
- wbc_first        1   3016.5 3050.5
- stroke_flag      1   3026.5 3060.5
- service_surg     1   3042.1 3076.1
- chloride_first   1   3042.7 3076.7

Step:  AIC=3020.83
aline_flag ~ weight_first + sofa_first + service_surg + renal_flag + 
    liver_flag + copd_flag + stroke_flag + respfail_flag + map_first + 
    bun_first + chloride_first + platelet_first + potassium_first + 
    sodium_first + tco2_first + wbc_first

                  Df Deviance    AIC
- respfail_flag    1   2987.7 3019.7
- potassium_first  1   2988.5 3020.5
<none>                 2986.8 3020.8
- bun_first        1   2989.0 3021.0
- platelet_first   1   2989.9 3021.9
- weight_first     1   2990.8 3022.8
- liver_flag       1   2992.9 3024.9
- renal_flag       1   2993.1 3025.1
- tco2_first       1   2994.5 3026.5
- copd_flag        1   2996.4 3028.4
- map_first        1   2999.5 3031.5
- sodium_first     1   3015.8 3047.8
- sofa_first       1   3016.2 3048.2
- wbc_first        1   3017.8 3049.8
- stroke_flag      1   3027.8 3059.8
- service_surg     1   3042.2 3074.2
- chloride_first   1   3042.9 3074.9

Step:  AIC=3019.69
aline_flag ~ weight_first + sofa_first + service_surg + renal_flag + 
    liver_flag + copd_flag + stroke_flag + map_first + bun_first + 
    chloride_first + platelet_first + potassium_first + sodium_first + 
    tco2_first + wbc_first

                  Df Deviance    AIC
- potassium_first  1   2989.4 3019.4
- bun_first        1   2989.6 3019.6
<none>                 2987.7 3019.7
- platelet_first   1   2990.8 3020.8
- weight_first     1   2991.7 3021.7
- liver_flag       1   2993.8 3023.8
- renal_flag       1   2994.0 3024.0
- tco2_first       1   2994.8 3024.8
- copd_flag        1   2997.5 3027.5
- map_first        1   3000.2 3030.2
- sofa_first       1   3016.5 3046.5
- sodium_first     1   3016.7 3046.7
- wbc_first        1   3018.4 3048.4
- stroke_flag      1   3030.1 3060.1
- chloride_first   1   3043.9 3073.9
- service_surg     1   3044.3 3074.3

Step:  AIC=3019.39
aline_flag ~ weight_first + sofa_first + service_surg + renal_flag + 
    liver_flag + copd_flag + stroke_flag + map_first + bun_first + 
    chloride_first + platelet_first + sodium_first + tco2_first + 
    wbc_first

                 Df Deviance    AIC
- bun_first       1   2990.7 3018.7
<none>                2989.4 3019.4
- weight_first    1   2992.9 3020.9
- platelet_first  1   2992.9 3020.9
- liver_flag      1   2995.6 3023.6
- tco2_first      1   2996.3 3024.3
- renal_flag      1   2996.5 3024.5
- copd_flag       1   2999.6 3027.6
- map_first       1   3001.7 3029.7
- sodium_first    1   3017.1 3045.1
- sofa_first      1   3017.5 3045.5
- wbc_first       1   3019.7 3047.7
- stroke_flag     1   3032.5 3060.5
- chloride_first  1   3044.4 3072.4
- service_surg    1   3047.3 3075.3

Step:  AIC=3018.65
aline_flag ~ weight_first + sofa_first + service_surg + renal_flag + 
    liver_flag + copd_flag + stroke_flag + map_first + chloride_first + 
    platelet_first + sodium_first + tco2_first + wbc_first

                 Df Deviance    AIC
<none>                2990.7 3018.7
- weight_first    1   2994.3 3020.3
- platelet_first  1   2994.4 3020.4
- renal_flag      1   2996.5 3022.5
- liver_flag      1   2996.9 3022.9
- tco2_first      1   2997.5 3023.5
- copd_flag       1   3000.7 3026.7
- map_first       1   3003.0 3029.0
- sodium_first    1   3018.2 3044.2
- wbc_first       1   3021.8 3047.8
- sofa_first      1   3024.9 3050.9
- stroke_flag     1   3034.0 3060.0
- chloride_first  1   3045.1 3071.1
- service_surg    1   3048.2 3074.2
Type 'citation("pROC")' for a citation.

Attaching package: ‘pROC’

The following objects are masked from ‘package:stats’:

    cov, smooth, var

Setting levels: control = 0, case = 1
Setting direction: controls < cases
0.695052969260227

In [7]:
# plot stacked histogram of the predictions
xrange = seq(0,1,0.01)
# 3) subset your vectors to be inside xrange
g1 = subset(X,Tr==0)
g2 = subset(X,Tr==1)

# 4) Now, use hist to compute the counts per interval
h1 = hist(g1,breaks=xrange,plot=F)$counts
h2 = hist(g2,breaks=xrange,plot=F)$counts

barplot(rbind(h1,h2),col=3:2,names.arg=xrange[-1],
        legend.text=c("No aline","Aline"),space=0,las=1,main="Stacked histogram of X")



In [8]:
library(Matching)

set.seed(43770)

ps <- Match(Y=NULL, Tr=Tr, X=X, M=1, estimand='ATT', caliper=0.1, exact=FALSE, replace=FALSE);

# get pairs with treatment/outcome as cols
outcome <- data.frame(aline_pt=y[ps$index.treated], match_pt=y[ps$index.control])
head(outcome)

# mcnemar's test to see if iac related to mort (test should use matched pairs)
tab.match1 <- table(outcome$aline_pt,outcome$match_pt,dnn=c("Aline","Matched Control"))
tab.match1
tab.match1[1,2]/tab.match1[2,1]
paste("95% Confint", round(exp(c(log(tab.match1[2,1]/tab.match1[1,2]) - qnorm(0.975)*sqrt(1/tab.match1[1,2] +1/tab.match1[2,1]),log(tab.match1[2,1]/tab.match1[1,2]) + qnorm(0.975)*sqrt(1/tab.match1[1,2] +1/tab.match1[2,1])) ),2))
mcnemar.test(tab.match1) # for 1-1 pairs


## 
##  Matching (Version 4.9-6, Build Date: 2019-04-07)
##  See http://sekhon.berkeley.edu/matching for additional documentation.
##  Please cite software as:
##   Jasjeet S. Sekhon. 2011. ``Multivariate and Propensity Score Matching
##   Software with Automated Balance Optimization: The Matching package for R.''
##   Journal of Statistical Software, 42(7): 1-52. 
##

Warning message in Match(Y = NULL, Tr = Tr, X = X, M = 1, estimand = "ATT", caliper = 0.1, :
“replace==FALSE, but there are more (weighted) treated obs than control obs.  Some treated obs will not be matched.  You may want to estimate ATC instead.”
aline_ptmatch_pt
00
00
01
00
10
00
     Matched Control
Aline   0   1
    0 576 123
    1 104  19
1.18269230769231
  1. '95% Confint 0.65'
  2. '95% Confint 1.1'
	McNemar's Chi-squared test with continuity correction

data:  tab.match1
McNemar's chi-squared = 1.4273, df = 1, p-value = 0.2322