hospital_mortality univariate logistic regression model

first_enc_table %>%
  select("na_grp_mayo","age","Gender","White","na_first","Cirrhosis","chf","mi","pvd","Bipolar","Seizure","cancer","Schizophrenia","hospital_mortality"
  ) %>%
  tbl_uvregression(
    method = glm,
    y = hospital_mortality,
    method.args = list(family = binomial),
    exponentiate = TRUE,
    show_single_row=c(
   "Gender","White","Cirrhosis","chf","mi","pvd","Bipolar","Seizure","cancer","Schizophrenia"),
    pvalue_fun = ~style_pvalue(.x, digits = 3)
  ) %>%
  bold_p(0.01) %>%        # bold p-values under a given threshold (default 0.05)
  bold_labels() %>%
  modify_spanning_header(
    c(estimate, ci, p.value) ~
      "**hospital_mortality Univariate logistic regression  **") %>%
  add_n(location = "level")
Characteristic N **hospital_mortality Univariate logistic regression **
OR1 95% CI1 p-value
na_grp_mayo
    optimal correct (6-10) 952
    overcorrect (>10) 1,067 0.68 0.47, 0.97 0.034
    undercorrect (<6) 1,255 1.77 1.33, 2.39 <0.001
age 3,274 0.98 0.98, 0.99 <0.001
Gender 1.50 1.18, 1.91 0.001
White 0.89 0.67, 1.22 0.463
first sodium value 3,274 1.03 1.00, 1.07 0.102
Cirrhosis 2.04 1.45, 2.81 <0.001
chf 1.32 1.02, 1.69 0.031
mi 0.85 0.62, 1.16 0.321
pvd 0.62 0.44, 0.86 0.005
Bipolar 0.32 0.17, 0.55 <0.001
Seizure 0.26 0.08, 0.62 0.008
cancer 1.91 1.50, 2.44 <0.001
Schizophrenia 0.09 0.00, 0.39 0.015
1 OR = Odds Ratio, CI = Confidence Interval

hospital_mortality multivariate logistic regression model 1

m1 <- glm(hospital_mortality ~ na_grp_mayo+age+Gender+White+na_first, family = binomial(link = 'logit'),data=first_enc_table) 
m1 %>% tbl_regression(exponentiate = TRUE,
                       show_single_row=c("White","Gender"),
                       pvalue_fun = ~style_pvalue(.x, digits = 3)) %>% bold_p() %>% # bold p-values under a given threshold (default 0.05)
  bold_labels()%>% 
  modify_spanning_header(
    c(estimate, ci, p.value) ~  
      "**hospital mortality logistic regression model 1 **")%>%
  add_n(location = "level")
Characteristic N **hospital mortality logistic regression model 1 **
OR1 95% CI1 p-value
na_grp_mayo
    optimal correct (6-10) 952
    overcorrect (>10) 1,067 0.62 0.43, 0.89 0.010
    undercorrect (<6) 1,255 1.78 1.33, 2.41 <0.001
age 3,274 0.98 0.97, 0.99 <0.001
Gender 1.31 1.02, 1.68 0.036
White 0.89 0.66, 1.22 0.455
first sodium value 3,274 1.0 0.96, 1.03 0.780
1 OR = Odds Ratio, CI = Confidence Interval

hospital_mortality multivariate logistic regression model 2

m2 <- glm(hospital_mortality ~ na_grp_mayo+age+Gender+White+na_first+charlson, family = binomial(link = 'logit'),data=first_enc_table) 
m2 %>% tbl_regression(exponentiate = TRUE,
                      show_single_row=c("White","Gender"),
                      pvalue_fun = ~style_pvalue(.x, digits = 3)) %>% bold_p() %>% # bold p-values under a given threshold (default 0.05)
  bold_labels()%>% 
  modify_spanning_header(
    c(estimate, ci, p.value) ~  
      "**hospital mortality logistic regression model 2 **")%>%
  add_n(location = "level")
Characteristic N **hospital mortality logistic regression model 2 **
OR1 95% CI1 p-value
na_grp_mayo
    optimal correct (6-10) 952
    overcorrect (>10) 1,067 0.64 0.44, 0.93 0.020
    undercorrect (<6) 1,255 1.71 1.27, 2.31 <0.001
age 3,274 0.97 0.97, 0.98 <0.001
Gender 1.29 1.00, 1.66 0.046
White 0.90 0.66, 1.23 0.487
first sodium value 3,274 0.99 0.95, 1.03 0.574
Charlson Comorbidity Score 3,274 1.08 1.05, 1.12 <0.001
1 OR = Odds Ratio, CI = Confidence Interval

hospital_mortality multivariate logistic regression model 3

m3 <- glm(hospital_mortality ~ na_grp_mayo+age+Gender+White+na_first+Cirrhosis+chf+mi+pvd+Bipolar+Seizure+cancer+Schizophrenia, family = binomial(link = 'logit'),data=first_enc_table) 
m3 %>% tbl_regression(exponentiate = TRUE,show_single_row=c("White","Gender","cancer","Bipolar","Seizure","pvd","Cirrhosis","chf","mi","Schizophrenia"),
                      pvalue_fun = ~style_pvalue(.x, digits = 3)) %>% bold_p() %>% # bold p-values under a given threshold (default 0.05)
  bold_labels()%>% 
  modify_spanning_header(
    c(estimate, ci, p.value) ~  
      "**hospital mortality logistic regression model 3 **")%>%
  add_n(location = "level")
Characteristic N **hospital mortality logistic regression model 3 **
OR1 95% CI1 p-value
na_grp_mayo
    optimal correct (6-10) 952
    overcorrect (>10) 1,067 0.74 0.51, 1.07 0.114
    undercorrect (<6) 1,255 1.66 1.23, 2.25 <0.001
age 3,274 0.98 0.97, 0.99 <0.001
Gender 1.27 0.98, 1.64 0.067
White 0.89 0.66, 1.22 0.458
first sodium value 3,274 0.99 0.96, 1.03 0.618
Cirrhosis 1.46 1.02, 2.06 0.035
chf 1.76 1.31, 2.36 <0.001
mi 0.83 0.57, 1.18 0.307
pvd 0.68 0.47, 0.96 0.035
Bipolar 0.37 0.19, 0.64 0.001
Seizure 0.29 0.09, 0.69 0.015
cancer 1.84 1.43, 2.37 <0.001
Schizophrenia 0.13 0.01, 0.60 0.044
1 OR = Odds Ratio, CI = Confidence Interval

propensity score analysis

Hospital_mortality propensity score analysis

##### weighted analysis

test$w <- get.weights(mnps.enc, stop.method = "es.mean")
design.mnps <- svydesign(ids=~1, weights=~w, data=test)
svyglm(hospital_mortality ~ as.factor(na_grp_mayo), design = design.mnps, family = quasibinomial()) %>% 
  tbl_regression(exponentiate = TRUE,pvalue_fun = ~style_pvalue(.x, digits = 3)) %>% bold_p() %>% # bold p-values under a given threshold (default 0.05)
  bold_labels()%>% 
  modify_spanning_header(
    c(estimate, ci, p.value) ~  
      "**hospital mortality propensity analysis logistic regression  **")
Characteristic **hospital mortality propensity analysis logistic regression **
OR1 95% CI1 p-value
as.factor(na_grp_mayo)
    optimal correct (6-10)
    overcorrect (>10) 0.76 0.53, 1.11 0.152
    undercorrect (<6) 1.54 1.14, 2.08 0.005
1 OR = Odds Ratio, CI = Confidence Interval

30 day death univariate logistic regression model

first_enc_table %>%
  select("na_grp_mayo","age","Gender","White","na_first","Cirrhosis","chf","mi","pvd","Bipolar","Seizure","cancer","Schizophrenia","death_30d"
  ) %>%
  tbl_uvregression(
    method = glm,
    y = death_30d,
    method.args = list(family = binomial),
    exponentiate = TRUE,
    show_single_row=c(
   "Gender","White","Cirrhosis","chf","mi","pvd","Bipolar","Seizure","cancer","Schizophrenia"),
    pvalue_fun = ~style_pvalue(.x, digits = 3)
  ) %>%
  bold_p(0.01) %>%        # bold p-values under a given threshold (default 0.05)
  bold_labels() %>%
  modify_spanning_header(
    c(estimate, ci, p.value) ~
      "**30 day death Univariate logistic regression  **")%>%
  add_n(location = "level")
Characteristic N **30 day death Univariate logistic regression **
OR1 95% CI1 p-value
na_grp_mayo
    optimal correct (6-10) 885
    overcorrect (>10) 1,004 0.69 0.51, 0.95 0.021
    undercorrect (<6) 1,194 2.23 1.74, 2.89 <0.001
age 3,083 0.99 0.98, 1.0 <0.001
Gender 1.47 1.20, 1.81 <0.001
White 0.85 0.66, 1.11 0.222
first sodium value 3,083 1.04 1.01, 1.08 0.008
Cirrhosis 1.75 1.30, 2.33 <0.001
chf 1.09 0.87, 1.34 0.454
mi 0.81 0.62, 1.05 0.117
pvd 0.63 0.48, 0.82 <0.001
Bipolar 0.35 0.22, 0.54 <0.001
Seizure 0.25 0.10, 0.52 <0.001
cancer 3.08 2.49, 3.80 <0.001
Schizophrenia 0.17 0.04, 0.46 0.003
1 OR = Odds Ratio, CI = Confidence Interval

30 day mortality multivariate logistic regression model 1

m1_30d  <- glm(death_30d ~ na_grp_mayo+White+Gender+age+na_first, family = binomial(link = 'logit'),data=first_enc_table) 
m1_30d  %>% tbl_regression(exponentiate = TRUE,
                       show_single_row=c("White","Gender"),
                       pvalue_fun = ~style_pvalue(.x, digits = 3)) %>% bold_p() %>% # bold p-values under a given threshold (default 0.05)
  bold_labels()%>% 
  modify_spanning_header(
    c(estimate, ci, p.value) ~  
      "**30 day mortality logistic regression model 1 **")%>%
  add_n(location = "level")
Characteristic N **30 day mortality logistic regression model 1 **
OR1 95% CI1 p-value
na_grp_mayo
    optimal correct (6-10) 885
    overcorrect (>10) 1,004 0.65 0.47, 0.90 0.009
    undercorrect (<6) 1,194 2.24 1.74, 2.91 <0.001
White 0.84 0.65, 1.09 0.183
Gender 1.31 1.06, 1.62 0.012
age 3,083 0.99 0.98, 0.99 <0.001
first sodium value 3,083 1.00 0.97, 1.03 0.980
1 OR = Odds Ratio, CI = Confidence Interval

30 day mortality multivariate logistic regression model 2

m2_30d  <- glm(death_30d ~ na_grp_mayo+age+Gender+White+na_first+charlson, family = binomial(link = 'logit'),data=first_enc_table) 
m2_30d  %>% tbl_regression(exponentiate = TRUE,
                      show_single_row=c("White","Gender"),
                      pvalue_fun = ~style_pvalue(.x, digits = 3)) %>% bold_p() %>% # bold p-values under a given threshold (default 0.05)
  bold_labels()%>% 
  modify_spanning_header(
    c(estimate, ci, p.value) ~  
      "**30 day mortality logistic regression model 2 **")%>%
  add_n(location = "level")
Characteristic N **30 day mortality logistic regression model 2 **
OR1 95% CI1 p-value
na_grp_mayo
    optimal correct (6-10) 885
    overcorrect (>10) 1,004 0.69 0.50, 0.96 0.026
    undercorrect (<6) 1,194 2.13 1.64, 2.77 <0.001
age 3,083 0.97 0.97, 0.98 <0.001
Gender 1.29 1.04, 1.60 0.021
White 0.85 0.65, 1.11 0.221
first sodium value 3,083 0.99 0.96, 1.03 0.618
Charlson Comorbidity Score 3,083 1.14 1.11, 1.18 <0.001
1 OR = Odds Ratio, CI = Confidence Interval

30 day mortality multivariate logistic regression model 3

m3_30d  <- glm(death_30d ~ na_grp_mayo+age+Gender+White+na_first+Cirrhosis+chf+mi+pvd+Bipolar+Seizure+cancer+Schizophrenia, family = binomial(link = 'logit'),data=first_enc_table) 
m3_30d  %>% tbl_regression(exponentiate = TRUE,show_single_row=c("White","Gender","cancer","Bipolar","Seizure","pvd","Cirrhosis","chf","mi","Schizophrenia"),
                      pvalue_fun = ~style_pvalue(.x, digits = 3)) %>% bold_p() %>% # bold p-values under a given threshold (default 0.05)
  bold_labels()%>% 
  modify_spanning_header(
    c(estimate, ci, p.value) ~  
      "**30 day mortality logistic regression model 3 **")%>%
  add_n(location = "level")
Characteristic N **30 day mortality logistic regression model 3 **
OR1 95% CI1 p-value
na_grp_mayo
    optimal correct (6-10) 885
    overcorrect (>10) 1,004 0.80 0.57, 1.10 0.173
    undercorrect (<6) 1,194 2.11 1.63, 2.76 <0.001
age 3,083 0.99 0.98, 0.99 <0.001
Gender 1.32 1.06, 1.65 0.014
White 0.79 0.61, 1.04 0.090
first sodium value 3,083 1.00 0.97, 1.03 0.847
Cirrhosis 1.35 0.98, 1.86 0.065
chf 1.39 1.08, 1.80 0.011
mi 0.85 0.63, 1.16 0.315
pvd 0.68 0.50, 0.91 0.012
Bipolar 0.42 0.25, 0.66 <0.001
Seizure 0.28 0.11, 0.60 0.003
cancer 2.96 2.37, 3.70 <0.001
Schizophrenia 0.27 0.07, 0.75 0.030
1 OR = Odds Ratio, CI = Confidence Interval

30 day propensity score analysis

##### weighted analysis
svyglm(death_30d ~ as.factor(na_grp_mayo), design = design.mnps, family = quasibinomial()) %>% 
  tbl_regression(exponentiate = TRUE,pvalue_fun = ~style_pvalue(.x, digits = 3)) %>% bold_p() %>% # bold p-values under a given threshold (default 0.05)
  bold_labels()%>% 
  modify_spanning_header(
    c(estimate, ci, p.value) ~  
      "**30 day mortality propensity analysis logistic regression  **")
Characteristic **30 day mortality propensity analysis logistic regression **
OR1 95% CI1 p-value
as.factor(na_grp_mayo)
    optimal correct (6-10)
    overcorrect (>10) 0.80 0.58, 1.11 0.185
    undercorrect (<6) 1.91 1.47, 2.47 <0.001
1 OR = Odds Ratio, CI = Confidence Interval

Sensitivity analysis

sensitivity_master <- first_enc_table %>% mutate(correct_groups=ifelse(na_mayocorr<=8,"<=8",">8"))
sensitivity_master$correct_groups <- as.factor(sensitivity_master$correct_groups)

Sensitivity 30 day mortality logistic regression model 2

sensitivity_m2_30d  <- glm(death_30d ~ correct_groups+age+Gender+White+na_first+charlson, family = binomial(link = 'logit'),data=sensitivity_master) 
sensitivity_m2_30d  %>% tbl_regression(exponentiate = TRUE,
                      show_single_row=c("White","Gender"),
                      pvalue_fun = ~style_pvalue(.x, digits = 3)) %>% bold_p() %>% # bold p-values under a given threshold (default 0.05)
  bold_labels()%>% 
  modify_spanning_header(
    c(estimate, ci, p.value) ~  
      "**Sensitivity 30 day death mortality logistic regression model 2 **") %>%
    add_n(location = "level")
Characteristic N **Sensitivity 30 day death mortality logistic regression model 2 **
OR1 95% CI1 p-value
correct_groups
    <=8 1,699
    >8 1,384 0.42 0.32, 0.53 <0.001
age 3,083 0.97 0.97, 0.98 <0.001
Gender 1.32 1.06, 1.63 0.012
White 0.86 0.66, 1.12 0.252
first sodium value 3,083 1.00 0.97, 1.03 0.909
Charlson Comorbidity Score 3,083 1.14 1.11, 1.18 <0.001
1 OR = Odds Ratio, CI = Confidence Interval

Sensitivity 30 day mortality logistic regression model 3

sensitivity_m3_30d  <- glm(death_30d ~ correct_groups+age+Gender+White+na_first+Cirrhosis+chf+mi+pvd+Bipolar+Seizure+cancer+Schizophrenia, family = binomial(link = 'logit'),data=sensitivity_master) 
sensitivity_m3_30d  %>% tbl_regression(exponentiate = TRUE,show_single_row=c("White","Gender","cancer","Bipolar","Seizure","pvd","Cirrhosis","chf","mi","Schizophrenia"),
                      pvalue_fun = ~style_pvalue(.x, digits = 3)) %>% bold_p() %>% # bold p-values under a given threshold (default 0.05)
  bold_labels()%>% 
  modify_spanning_header(
    c(estimate, ci, p.value) ~  
      "**Sensitivity 30 day death mortality logistic regression model 3 **")%>%
    add_n(location = "level")
Characteristic N **Sensitivity 30 day death mortality logistic regression model 3 **
OR1 95% CI1 p-value
correct_groups
    <=8 1,699
    >8 1,384 0.46 0.36, 0.59 <0.001
age 3,083 0.99 0.98, 0.99 <0.001
Gender 1.35 1.08, 1.68 0.008
White 0.80 0.61, 1.05 0.104
first sodium value 3,083 1.00 0.97, 1.04 0.935
Cirrhosis 1.34 0.97, 1.84 0.071
chf 1.41 1.09, 1.81 0.009
mi 0.84 0.61, 1.13 0.252
pvd 0.69 0.50, 0.92 0.014
Bipolar 0.42 0.26, 0.66 <0.001
Seizure 0.29 0.11, 0.61 0.003
cancer 2.99 2.40, 3.73 <0.001
Schizophrenia 0.27 0.06, 0.73 0.027
1 OR = Odds Ratio, CI = Confidence Interval

Sensitivity hospital_mortality mortality logistic regression model 2

sensitivity_m2_hospital_mortality  <- glm(hospital_mortality ~ correct_groups+age+Gender+White+na_first+charlson, family = binomial(link = 'logit'),data=sensitivity_master) 
sensitivity_m2_hospital_mortality %>% tbl_regression(exponentiate = TRUE,
                      show_single_row=c("White","Gender"),
                      pvalue_fun = ~style_pvalue(.x, digits = 3)) %>% bold_p() %>% # bold p-values under a given threshold (default 0.05)
  bold_labels()%>% 
  modify_spanning_header(
    c(estimate, ci, p.value) ~  
      "**Sensitivity hospital_mortality mortality logistic regression model 2 **")%>%
    add_n(location = "level")
Characteristic N **Sensitivity hospital_mortality mortality logistic regression model 2 **
OR1 95% CI1 p-value
correct_groups
    <=8 1,798
    >8 1,476 0.47 0.35, 0.62 <0.001
age 3,274 0.97 0.97, 0.98 <0.001
Gender 1.31 1.02, 1.68 0.034
White 0.91 0.67, 1.24 0.531
first sodium value 3,274 0.99 0.96, 1.03 0.751
Charlson Comorbidity Score 3,274 1.08 1.05, 1.12 <0.001
1 OR = Odds Ratio, CI = Confidence Interval

Sensitivity hospital_mortality mortality logistic regression model 3

sensitivity_m3_hospital_mortality <- glm(hospital_mortality ~ correct_groups+age+Gender+White+na_first+Cirrhosis+chf+mi+pvd+Bipolar+Seizure+cancer+Schizophrenia, family = binomial(link = 'logit'),data=sensitivity_master) 
sensitivity_m3_hospital_mortality %>% tbl_regression(exponentiate = TRUE,show_single_row=c("White","Gender","cancer","Bipolar","Seizure","pvd","Cirrhosis","chf","mi","Schizophrenia"),
                      pvalue_fun = ~style_pvalue(.x, digits = 3)) %>% bold_p() %>% # bold p-values under a given threshold (default 0.05)
  bold_labels()%>% 
  modify_spanning_header(
    c(estimate, ci, p.value) ~  
      "**Sensitivity hospital_mortality mortality logistic regression model 3 **")%>%
    add_n(location = "level")
Characteristic N **Sensitivity hospital_mortality mortality logistic regression model 3 **
OR1 95% CI1 p-value
correct_groups
    <=8 1,798
    >8 1,476 0.54 0.40, 0.71 <0.001
age 3,274 0.98 0.97, 0.99 <0.001
Gender 1.29 1.00, 1.66 0.051
White 0.90 0.66, 1.23 0.498
first sodium value 3,274 0.99 0.96, 1.03 0.750
Cirrhosis 1.45 1.02, 2.05 0.036
chf 1.78 1.33, 2.38 <0.001
mi 0.82 0.57, 1.16 0.266
pvd 0.68 0.47, 0.97 0.037
Bipolar 0.37 0.19, 0.65 0.001
Seizure 0.28 0.09, 0.69 0.015
cancer 1.86 1.44, 2.40 <0.001
Schizophrenia 0.13 0.01, 0.59 0.042
1 OR = Odds Ratio, CI = Confidence Interval

Sensitivity length of stay linear regression model 2

sensitivity_m2_los <- glm(hospital_los~ na_grp_mayo+age+Gender+White+na_first+charlson,data=sensitivity_master) 
sensitivity_m2_los %>% tbl_regression(exponentiate = F,
                      show_single_row=c("White","Gender"),
                      pvalue_fun = ~style_pvalue(.x, digits = 3)) %>% bold_p() %>% # bold p-values under a given threshold (default 0.05)
  bold_labels()%>% 
  modify_spanning_header(
    c(estimate, ci, p.value) ~  
      "**Sensitivity hospital_los linear regression model 2 **") %>%
    add_n(location = "level")
Characteristic N **Sensitivity hospital_los linear regression model 2 **
Beta 95% CI1 p-value
na_grp_mayo
    optimal correct (6-10) 952
    overcorrect (>10) 1,067 -2.4 -3.6, -1.2 <0.001
    undercorrect (<6) 1,255 0.06 -1.1, 1.2 0.917
age 3,274 -0.09 -0.12, -0.05 <0.001
Gender 1.4 0.51, 2.4 0.003
White 0.95 -0.22, 2.1 0.112
first sodium value 3,274 -0.15 -0.28, -0.02 0.022
Charlson Comorbidity Score 3,274 -0.03 -0.16, 0.11 0.695
1 CI = Confidence Interval

30 days excluded patients

table(final1$death_30days,useNA = "always")
## 
## alive  dead  <NA> 
##  3342  1267  3476

Time to index time

                              pre_to_index_hours_median
## [1] 20.3
                              pre_to_index_hours_IQR25
##      25% 
## 16.47083
                              pre_to_index_hours_IQR75
##      75% 
## 22.33333
                              pre_to_index_hours24_median
## [1] 3.7
                              pre_to_index_hours24_IQR25
##      25% 
## 1.666667
                              pre_to_index_hours24_IQR75
##      75% 
## 7.529167
                              post_to_index_hours24_median
## [1] 3.975
                              post_to_index_hours24_IQR25
##      25% 
## 1.666667
                              post_to_index_hours24_IQR75
##      75% 
## 8.683333

Number of patients with serum sodium <=105 at index admission

t1 <- first_enc_table %>% mutate(cat_105=ifelse(na_first<=105,"<=105",">105"))
table(t1$cat_105,t1$na_grp_mayo)
##        
##         optimal correct (6-10) overcorrect (>10) undercorrect (<6)
##   <=105                     12                63                 5
##   >105                     940              1004              1250

Number of patients with serum sodium <=110 at index admission

t2 <- first_enc_table %>% mutate(cat_110=ifelse(na_first<=110,"<=110",">110"))
table(t2$cat_110,t2$na_grp_mayo)
##        
##         optimal correct (6-10) overcorrect (>10) undercorrect (<6)
##   <=110                     85               197                46
##   >110                     867               870              1209

Addmission sodium

first_enc_table <- first_enc_table %>% mutate(ad_sodium_cat=case_when(na_first<=105 ~ "<=105",
                                                                      na_first>105 & na_first <= 110 ~ "106-110",
                                                                      na_first>110 & na_first <= 115 ~"111-115",
                                                                       na_first>115 & na_first <= 120 ~"116-120"))

count <- table(first_enc_table$ad_sodium_cat,useNA = "always")
count
## 
##   <=105 106-110 111-115 116-120    <NA> 
##      80     248     784    2162       0

Addmission sodium percentage

round(count / sum(count) * 100, 2)                                                                      
## 
##   <=105 106-110 111-115 116-120    <NA> 
##    2.44    7.57   23.95   66.04    0.00

plot na_corrate

#### bar plot 
library(trend)

# Create a bar plot

mean_first_enc <- first_enc %>%
  group_by(admit_yr) %>%
  summarize(mean_na_corrate = mean(na_corrate))

cor(mean_first_enc$admit_yr, mean_first_enc$mean_na_corrate)
## [1] -0.5636314
mk.test(mean_first_enc$mean_na_corrate)
## 
##  Mann-Kendall trend test
## 
## data:  mean_first_enc$mean_na_corrate
## z = -2.6009, n = 26, p-value = 0.009298
## alternative hypothesis: true S is not equal to 0
## sample estimates:
##            S         varS          tau 
## -119.0000000 2058.3333333   -0.3661538
ggplot(mean_first_enc, aes(x = admit_yr, y = mean_na_corrate)) +
  geom_bar(stat = "identity",fill ="#0080FF") +
  xlab("Year") +
  ylab("Mean Na corrate") +
  ggtitle("Mean Na corrate by Year")+
  annotate("text", x = 2013, y = 7, 
           label = " Mann-Kendall trend test P-value: <0.05
                    Correlation coefficient: -0.56 
                     ")+
  annotate("text", x = mean_first_enc$admit_yr, y = mean_first_enc$mean_na_corrate, 
           label = round(mean_first_enc$mean_na_corrate,2), vjust = -0.5, size = 3.5)+
  theme(plot.title = element_text(hjust = 0.5),panel.background = element_blank(),axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))+
  scale_x_continuous(breaks = mean_first_enc$admit_yr, labels = mean_first_enc$admit_yr)

Subgroups models death_30d

Cirrhosis <- first_enc_table %>% filter(Cirrhosis==1)
Cirrhosis2 <- glm(death_30d ~ na_grp_mayo+age+Gender+White+na_first+charlson, family = binomial(link = 'logit'),data=Cirrhosis) 
Cirrhosis2 %>% tbl_regression(exponentiate = TRUE,
                              show_single_row=c("White","Gender"),
                              pvalue_fun = ~style_pvalue(.x, digits = 3)) %>% bold_p() %>% # bold p-values under a given threshold (default 0.05)
  bold_labels()%>% 
  modify_spanning_header(
    c(estimate, ci, p.value) ~  
      "**Cirrhosis 30 day death mortality logistic regression model 2 **")%>%
  add_n(location = "level")
Characteristic N **Cirrhosis 30 day death mortality logistic regression model 2 **
OR1 95% CI1 p-value
na_grp_mayo
    optimal correct (6-10) 95
    overcorrect (>10) 54 0.31 0.09, 0.85 0.033
    undercorrect (<6) 167 1.13 0.61, 2.14 0.698
age 316 1.00 0.97, 1.02 0.910
Gender 1.63 0.90, 3.05 0.115
White 0.67 0.33, 1.40 0.268
first sodium value 316 1.03 0.92, 1.17 0.615
Charlson Comorbidity Score 316 1.14 1.05, 1.24 0.003
1 OR = Odds Ratio, CI = Confidence Interval
Cancer <- first_enc_table %>% filter(cancer==1)
Cancer2 <- glm(death_30d ~ na_grp_mayo+age+Gender+White+na_first+charlson, family = binomial(link = 'logit'),data=Cancer) 
Cancer2 %>% tbl_regression(exponentiate = TRUE,
                           show_single_row=c("White","Gender"),
                           pvalue_fun = ~style_pvalue(.x, digits = 3)) %>% bold_p() %>% # bold p-values under a given threshold (default 0.05)
  bold_labels()%>% 
  modify_spanning_header(
    c(estimate, ci, p.value) ~  
      "**Cancer 30 day death mortality logistic regression model 2 **")%>%
  add_n(location = "level")
Characteristic N **Cancer 30 day death mortality logistic regression model 2 **
OR1 95% CI1 p-value
na_grp_mayo
    optimal correct (6-10) 342
    overcorrect (>10) 305 0.71 0.45, 1.11 0.138
    undercorrect (<6) 546 2.18 1.55, 3.10 <0.001
age 1,193 0.97 0.96, 0.98 <0.001
Gender 1.22 0.91, 1.63 0.176
White 0.68 0.47, 0.98 0.036
first sodium value 1,193 1.00 0.96, 1.05 0.934
Charlson Comorbidity Score 1,193 1.07 1.03, 1.13 0.003
1 OR = Odds Ratio, CI = Confidence Interval
chf <- first_enc_table %>% filter(chf==1)
chf2 <- glm(death_30d ~ na_grp_mayo+age+Gender+White+na_first+charlson, family = binomial(link = 'logit'),data=chf) 
chf2 %>% tbl_regression(exponentiate = TRUE,
                        show_single_row=c("White","Gender"),
                        pvalue_fun = ~style_pvalue(.x, digits = 3)) %>% bold_p() %>% # bold p-values under a given threshold (default 0.05)
  bold_labels()%>% 
  modify_spanning_header(
    c(estimate, ci, p.value) ~  
      "**chf 30 day death mortality logistic regression model 2 **")%>%
  add_n(location = "level")
Characteristic N **chf 30 day death mortality logistic regression model 2 **
OR1 95% CI1 p-value
na_grp_mayo
    optimal correct (6-10) 293
    overcorrect (>10) 258 0.71 0.40, 1.24 0.234
    undercorrect (<6) 464 1.77 1.17, 2.75 0.009
age 1,015 0.99 0.98, 1.00 0.103
Gender 1.31 0.92, 1.88 0.136
White 0.84 0.54, 1.32 0.434
first sodium value 1,015 0.98 0.93, 1.04 0.513
Charlson Comorbidity Score 1,015 1.03 0.98, 1.08 0.290
1 OR = Odds Ratio, CI = Confidence Interval

Subgroups models hospital_mortality

Cirrhosis <- first_enc_table %>% filter(Cirrhosis==1)
Cirrhosis2_in <- glm(hospital_mortality ~ na_grp_mayo+age+Gender+White+na_first+charlson, family = binomial(link = 'logit'),data=Cirrhosis) 
Cirrhosis2_in %>% tbl_regression(exponentiate = TRUE,
                                 show_single_row=c("White","Gender"),
                                 pvalue_fun = ~style_pvalue(.x, digits = 3)) %>% bold_p() %>% # bold p-values under a given threshold (default 0.05)
  bold_labels()%>% 
  modify_spanning_header(
    c(estimate, ci, p.value) ~  
      "**Cirrhosis hospital_mortality logistic regression model 2 **")%>%
  add_n(location = "level")
Characteristic N **Cirrhosis hospital_mortality logistic regression model 2 **
OR1 95% CI1 p-value
na_grp_mayo
    optimal correct (6-10) 101
    overcorrect (>10) 55 0.35 0.09, 1.02 0.074
    undercorrect (<6) 174 0.89 0.46, 1.75 0.726
age 330 0.99 0.96, 1.02 0.383
Gender 1.15 0.61, 2.22 0.662
White 0.98 0.46, 2.31 0.962
first sodium value 330 1.01 0.90, 1.15 0.874
Charlson Comorbidity Score 330 1.08 0.99, 1.19 0.093
1 OR = Odds Ratio, CI = Confidence Interval
Cancer <- first_enc_table %>% filter(cancer==1)
Cancer2_in <- glm(hospital_mortality ~ na_grp_mayo+age+Gender+White+na_first+charlson, family = binomial(link = 'logit'),data=Cancer) 
Cancer2_in %>% tbl_regression(exponentiate = TRUE,
                              show_single_row=c("White","Gender"),
                              pvalue_fun = ~style_pvalue(.x, digits = 3)) %>% bold_p() %>% # bold p-values under a given threshold (default 0.05)
  bold_labels()%>% 
  modify_spanning_header(
    c(estimate, ci, p.value) ~  
      "**Cancer hospital_mortality logistic regression model 2 **")%>%
  add_n(location = "level")
Characteristic N **Cancer hospital_mortality logistic regression model 2 **
OR1 95% CI1 p-value
na_grp_mayo
    optimal correct (6-10) 358
    overcorrect (>10) 311 0.69 0.38, 1.21 0.200
    undercorrect (<6) 558 1.96 1.29, 3.06 0.002
age 1,227 0.97 0.95, 0.98 <0.001
Gender 1.19 0.83, 1.70 0.333
White 0.67 0.44, 1.04 0.069
first sodium value 1,227 0.98 0.93, 1.04 0.547
Charlson Comorbidity Score 1,227 1.02 0.96, 1.08 0.587
1 OR = Odds Ratio, CI = Confidence Interval
chf <- first_enc_table %>% filter(chf==1)
chf2_in <- glm(hospital_mortality ~ na_grp_mayo+age+Gender+White+na_first+charlson, family = binomial(link = 'logit'),data=chf) 
chf2_in %>% tbl_regression(exponentiate = TRUE,
                           show_single_row=c("White","Gender"),
                           pvalue_fun = ~style_pvalue(.x, digits = 3)) %>% bold_p() %>% # bold p-values under a given threshold (default 0.05)
  bold_labels()%>% 
  modify_spanning_header(
    c(estimate, ci, p.value) ~  
      "**chf hospital_mortality logistic regression model 2 **") %>%
  add_n(location = "level")
Characteristic N **chf hospital_mortality logistic regression model 2 **
OR1 95% CI1 p-value
na_grp_mayo
    optimal correct (6-10) 307
    overcorrect (>10) 263 0.84 0.45, 1.58 0.595
    undercorrect (<6) 476 1.77 1.09, 2.94 0.024
age 1,046 0.99 0.98, 1.01 0.439
Gender 1.29 0.86, 1.95 0.218
White 0.99 0.60, 1.69 0.955
first sodium value 1,046 0.98 0.93, 1.05 0.591
Charlson Comorbidity Score 1,046 0.95 0.89, 1.01 0.095
1 OR = Odds Ratio, CI = Confidence Interval

Cirrhosis na_mayocorr

mean(Cirrhosis$na_mayocorr,na.rm = T)
## [1] 6.171678
sd(Cirrhosis$na_mayocorr,na.rm = T)
## [1] 5.132014

Cirrhosis na_mayocorr by groups

Cirrhosis_g <- first_enc_table %>% group_by(na_grp_mayo)  %>%
  summarise(count = n(),mean = mean(na_mayocorr, na.rm = TRUE),
            sd = sd(na_mayocorr, na.rm = TRUE))
Cirrhosis_g
## # A tibble: 3 × 4
##   na_grp_mayo            count  mean    sd
##   <fct>                  <int> <dbl> <dbl>
## 1 optimal correct (6-10)   952  7.82  1.20
## 2 overcorrect (>10)       1067 16.2   6.35
## 3 undercorrect (<6)       1255  3.00  2.20
summary(aov(na_mayocorr ~ na_grp_mayo, data = Cirrhosis))
##              Df Sum Sq Mean Sq F value Pr(>F)    
## na_grp_mayo   2   6412    3206   465.2 <2e-16 ***
## Residuals   327   2253       7                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

CHF na_mayocorr

mean(chf$na_mayocorr,na.rm = T)
## [1] 7.644498
sd(chf$na_mayocorr,na.rm = T)
## [1] 6.316357

CHF na_mayocorr by groups

chf_g <- first_enc_table %>% group_by(na_grp_mayo)  %>%
  summarise(count = n(),mean = mean(na_mayocorr, na.rm = TRUE),
            sd = sd(na_mayocorr, na.rm = TRUE))
chf_g
## # A tibble: 3 × 4
##   na_grp_mayo            count  mean    sd
##   <fct>                  <int> <dbl> <dbl>
## 1 optimal correct (6-10)   952  7.82  1.20
## 2 overcorrect (>10)       1067 16.2   6.35
## 3 undercorrect (<6)       1255  3.00  2.20
summary(aov(na_mayocorr ~ na_grp_mayo, data = chf))
##               Df Sum Sq Mean Sq F value Pr(>F)    
## na_grp_mayo    2  28717   14358    1154 <2e-16 ***
## Residuals   1043  12975      12                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Cancer na_mayocorr

mean(Cancer$na_mayocorr,na.rm = T)
## [1] 7.553166
sd(Cancer$na_mayocorr,na.rm = T)
## [1] 6.076614

Cancer na_mayocorr by groups

Cancer_g <- first_enc_table %>% group_by(na_grp_mayo)  %>%
  summarise(count = n(),mean = mean(na_mayocorr, na.rm = TRUE),
            sd = sd(na_mayocorr, na.rm = TRUE))
Cancer_g
## # A tibble: 3 × 4
##   na_grp_mayo            count  mean    sd
##   <fct>                  <int> <dbl> <dbl>
## 1 optimal correct (6-10)   952  7.82  1.20
## 2 overcorrect (>10)       1067 16.2   6.35
## 3 undercorrect (<6)       1255  3.00  2.20
summary(aov(na_mayocorr ~ na_grp_mayo, data = Cancer))
##               Df Sum Sq Mean Sq F value Pr(>F)    
## na_grp_mayo    2  30780   15390    1300 <2e-16 ***
## Residuals   1224  14490      12                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

mean na_mayocorr in days with SD for 3 categories of sodium correction

 first_enc_table %>% group_by(na_grp_mayo)  %>%
  summarise(count = n(),mean = mean(na_mayocorr, na.rm = TRUE),
            sd = sd(na_mayocorr, na.rm = TRUE))
## # A tibble: 3 × 4
##   na_grp_mayo            count  mean    sd
##   <fct>                  <int> <dbl> <dbl>
## 1 optimal correct (6-10)   952  7.82  1.20
## 2 overcorrect (>10)       1067 16.2   6.35
## 3 undercorrect (<6)       1255  3.00  2.20
summary(aov(na_mayocorr ~ na_grp_mayo, data = first_enc_table))
##               Df Sum Sq Mean Sq F value Pr(>F)    
## na_grp_mayo    2 100871   50435    3267 <2e-16 ***
## Residuals   3271  50503      15                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

mean hospital_mortality in days with SD for 3 categories of sodium correction

 first_enc_table %>% group_by(na_grp_mayo)  %>%
  summarise(count = n(),mean = mean(hospital_los, na.rm = TRUE),
            sd = sd(hospital_los, na.rm = TRUE))
## # A tibble: 3 × 4
##   na_grp_mayo            count  mean    sd
##   <fct>                  <int> <dbl> <dbl>
## 1 optimal correct (6-10)   952  9.84  17.5
## 2 overcorrect (>10)       1067  8.05  10.1
## 3 undercorrect (<6)       1255  9.77  12.4
summary(aov(hospital_los ~ na_grp_mayo, data = first_enc_table))
##               Df Sum Sq Mean Sq F value  Pr(>F)   
## na_grp_mayo    2   2210  1104.9   6.094 0.00228 **
## Residuals   3271 593074   181.3                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Hospital mortality % for <=8 and >8

table(sensitivity_master$hospital_mortality,sensitivity_master$correct_groups,useNA = "always" )
##       
##         <=8   >8 <NA>
##   0    1593 1394    0
##   1     205   82    0
##   <NA>    0    0    0

30 day mortality % for <=8 and >8

table(sensitivity_master$death_30d,sensitivity_master$correct_groups,useNA = "always" )
##       
##         <=8   >8 <NA>
##   0    1382 1272    0
##   1     317  112    0
##   <NA>   99   92    0

LOS

los_1 <- first_enc_table %>% group_by(hospital_mortality) %>%
  summarise(count = n(),mean = mean(hospital_los, na.rm = TRUE),
            sd = sd(hospital_los, na.rm = TRUE))
los_1
## # A tibble: 2 × 4
##   hospital_mortality count  mean    sd
##   <fct>              <int> <dbl> <dbl>
## 1 0                   2987  8.84  12.5
## 2 1                    287 13.3   20.6
summary(aov(hospital_los ~ hospital_mortality, data = first_enc_table))
##                      Df Sum Sq Mean Sq F value   Pr(>F)    
## hospital_mortality    1   5089    5089   28.21 1.16e-07 ***
## Residuals          3272 590195     180                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

LOS hospital mortality =1

los_2 <- first_enc_table %>% filter(hospital_mortality ==1)%>% group_by(hospital_mortality)  %>%
  summarise(count = n(),mean = mean(hospital_los, na.rm = TRUE),
            sd = sd(hospital_los, na.rm = TRUE))
los_2
## # A tibble: 1 × 4
##   hospital_mortality count  mean    sd
##   <fct>              <int> <dbl> <dbl>
## 1 1                    287  13.3  20.6

Cirrhosis univariate 30 day mortality

 glm(death_30d ~ na_grp_mayo, family = binomial(link = 'logit'),data=Cirrhosis) %>% tbl_regression(exponentiate = TRUE,
    
                              pvalue_fun = ~style_pvalue(.x, digits = 3)) %>% bold_p() %>% # bold p-values under a given threshold (default 0.05)
  bold_labels() %>% 
  modify_spanning_header(
    c(estimate, ci, p.value) ~  
      "**Cirrhosis 30 day mortality logistic regression**") %>%
  add_n(location = "level") %>%
  add_global_p()
Characteristic N Cirrhosis 30 day mortality logistic regression
OR1 95% CI1 p-value
na_grp_mayo 0.043
    optimal correct (6-10) 95
    overcorrect (>10) 54 0.36 0.11, 0.95
    undercorrect (<6) 167 1.11 0.61, 2.05
1 OR = Odds Ratio, CI = Confidence Interval

Cancer univariate 30 day mortality

 glm(death_30d ~ na_grp_mayo, family = binomial(link = 'logit'),data=Cancer) %>% tbl_regression(exponentiate = TRUE,

                              pvalue_fun = ~style_pvalue(.x, digits = 3)) %>% bold_p() %>% # bold p-values under a given threshold (default 0.05)
  bold_labels() %>% 
  modify_spanning_header(
    c(estimate, ci, p.value) ~  
      "**Cancer 30 day mortality logistic regression**") %>%
  add_n(location = "level") %>%
  add_global_p()
Characteristic N Cancer 30 day mortality logistic regression
OR1 95% CI1 p-value
na_grp_mayo <0.001
    optimal correct (6-10) 342
    overcorrect (>10) 305 0.74 0.48, 1.14
    undercorrect (<6) 546 2.20 1.58, 3.09
1 OR = Odds Ratio, CI = Confidence Interval

chf univariate 30 day mortality

 glm(death_30d ~ na_grp_mayo, family = binomial(link = 'logit'),data=chf) %>% tbl_regression(exponentiate = TRUE,

                              pvalue_fun = ~style_pvalue(.x, digits = 3)) %>% bold_p() %>% # bold p-values under a given threshold (default 0.05)
  bold_labels() %>% 
  modify_spanning_header(
    c(estimate, ci, p.value) ~  
      "**chf 30 day mortality logistic regression**") %>%
  add_n(location = "level") %>%
  add_global_p()
Characteristic N chf 30 day mortality logistic regression
OR1 95% CI1 p-value
na_grp_mayo <0.001
    optimal correct (6-10) 293
    overcorrect (>10) 258 0.76 0.43, 1.30
    undercorrect (<6) 464 1.75 1.16, 2.70
1 OR = Odds Ratio, CI = Confidence Interval

Cirrhosis univariate hospital_mortality

 glm(hospital_mortality ~ na_grp_mayo, family = binomial(link = 'logit'),data=Cirrhosis) %>% tbl_regression(exponentiate = TRUE,

                              pvalue_fun = ~style_pvalue(.x, digits = 3)) %>% bold_p() %>% # bold p-values under a given threshold (default 0.05)
  bold_labels() %>% 
  modify_spanning_header(
    c(estimate, ci, p.value) ~  
      "**Cirrhosis hospital_mortality logistic regression**") %>%
  add_n(location = "level") %>%
  add_global_p()
Characteristic N Cirrhosis hospital_mortality logistic regression
OR1 95% CI1 p-value
na_grp_mayo 0.147
    optimal correct (6-10) 101
    overcorrect (>10) 55 0.36 0.10, 1.03
    undercorrect (<6) 174 0.88 0.46, 1.72
1 OR = Odds Ratio, CI = Confidence Interval

Cancer univariate hospital_mortality

 glm(hospital_mortality  ~ na_grp_mayo, family = binomial(link = 'logit'),data=Cancer) %>% tbl_regression(exponentiate = TRUE,

                              pvalue_fun = ~style_pvalue(.x, digits = 3)) %>% bold_p() %>% # bold p-values under a given threshold (default 0.05)
  bold_labels() %>% 
  modify_spanning_header(
    c(estimate, ci, p.value) ~  
      "**Cancer hospital_mortality  logistic regression**") %>%
  add_n(location = "level") %>%
  add_global_p()
Characteristic N Cancer hospital_mortality logistic regression
OR1 95% CI1 p-value
na_grp_mayo <0.001
    optimal correct (6-10) 358
    overcorrect (>10) 311 0.73 0.41, 1.26
    undercorrect (<6) 558 1.91 1.27, 2.93
1 OR = Odds Ratio, CI = Confidence Interval

#chf univariate hospital_mortality

 glm(hospital_mortality ~ na_grp_mayo, family = binomial(link = 'logit'),data=chf) %>% tbl_regression(exponentiate = TRUE,

                              pvalue_fun = ~style_pvalue(.x, digits = 3)) %>% bold_p() %>% # bold p-values under a given threshold (default 0.05)
  bold_labels() %>% 
  modify_spanning_header(
    c(estimate, ci, p.value) ~  
      "**chf hospital_mortality  logistic regression**") %>%
  add_n(location = "level") %>%
  add_global_p()
Characteristic N chf hospital_mortality logistic regression
OR1 95% CI1 p-value
na_grp_mayo 0.018
    optimal correct (6-10) 307
    overcorrect (>10) 263 0.93 0.50, 1.71
    undercorrect (<6) 476 1.72 1.07, 2.85
1 OR = Odds Ratio, CI = Confidence Interval

Model 2 run a new model with reference group as <6 group and compare the reference group to >10 group

first_enc_table <- first_enc_table %>% mutate(group2=case_when(na_mayocorr<6 ~"<6",
                                                               na_mayocorr>10 ~">10"))
first_enc_table$group2 <- as.factor(first_enc_table$group2)
first_enc_table$group2 <- relevel(first_enc_table$group2, ref = "<6")

glm(hospital_mortality ~ group2+age+Gender+White+na_first+charlson, family = binomial(link = 'logit'),data=first_enc_table) %>% 
  tbl_regression(exponentiate = TRUE,
                      show_single_row=c("White","Gender"),
                      pvalue_fun = ~style_pvalue(.x, digits = 3)) %>% bold_p() %>% # bold p-values under a given threshold (default 0.05)
  bold_labels()%>% 
  modify_spanning_header(
    c(estimate, ci, p.value) ~  
      "**hospital mortality logistic regression model 2 **")
Characteristic **hospital mortality logistic regression model 2 **
OR1 95% CI1 p-value
group2
    <6
    >10 0.37 0.26, 0.52 <0.001
age 0.97 0.96, 0.98 <0.001
Gender 1.16 0.87, 1.55 0.322
White 0.90 0.64, 1.30 0.568
first sodium value 0.99 0.95, 1.04 0.760
Charlson Comorbidity Score 1.08 1.04, 1.13 <0.001
1 OR = Odds Ratio, CI = Confidence Interval