library(ggplot2)  # plotting
library(highcharter) # plotting
library(dplyr)    # data pliers
library(tidyr)    # 'tidy' up data
library(gmodels)  # contingency tables
library(mice)     # imputation
library(corrplot) # correlation plot
library(lme4)     # linear models
library(ztable)   # cross-table display
options(ztable.type="html")
library(magrittr) # pipes
library(janitor)  # clean names
library(huxtable)

Read the data

81 entries

and ‘clean up’ the names

d <- read.csv("SerumUricAcid.csv",
              skip = 3, # a few rows to skip at the beginning
              check.names = TRUE, # avoid duplicate names
              stringsAsFactors = FALSE
)
d <- d[seq(from = 1, to = 81),] # 81 entries

Clean names

‘Clean up the names’ - e.g. spaces changed to underscores ’_’

names(d) <- make_clean_names(names(d))
names(d)

[1] “number”
[2] “age”
[3] “gender”
[4] “ethnicity”
[5] “hospital_campus”
[6] “hopc”
[7] “primary_care_team”
[8] “unit_of_admission”
[9] “grouped_units_of_admission”
[10] “rheum_input”
[11] “admission_date”
[12] “discharge_date”
[13] “duration_of_stay”
[14] “number_of_active_joints_involved”
[15] “joint_s_involved”
[16] “mtp”
[17] “ankle”
[18] “knee”
[19] “elbow”
[20] “wrist”
[21] “mcp”
[22] “tophi”
[23] “therapeutic_agents”
[24] “nsaid”
[25] “nsaid_type”
[26] “nsaid_dose”
[27] “duration”
[28] “colchicine”
[29] “total_col”
[30] “duration_col”
[31] “mean_daily_col”
[32] “d1_col”
[33] “d2_col”
[34] “total_daily_dose_mg”
[35] “course”
[36] “prednisolone”
[37] “total_pred”
[38] “duration_pred”
[39] “mean_daily_pred”
[40] “d1_pred”
[41] “d2_pred”
[42] “course_1”
[43] “course_2”
[44] “wean”
[45] “ia_steroid_injections”
[46] “dose”
[47] “comments”
[48] “x_diuretics_used”
[49] “thiazide_diuretics”
[50] “dose_1”
[51] “loop_diuretics”
[52] “k_sparing_diuretics”
[53] “other_diuretics”
[54] “dose_2”
[55] “anti_hypertensives”
[56] “x_anti_htn”
[57] “b_blocker”
[58] “ac_ei”
[59] “arb”
[60] “ccb”
[61] “a_blocker”
[62] “a_b_blocker”
[63] “moxonidine”
[64] “dose_3”
[65] “x_anti_chol_used”
[66] “statins”
[67] “fibrates”
[68] “ezetimibe”
[69] “other”
[70] “cholesterol_lowering_therapy”
[71] “dose_4”
[72] “x_anti_platelet_therapy”
[73] “aspirin”
[74] “clopidogrel”
[75] “total_number”
[76] “dose_5”
[77] “htn”
[78] “t2dm”
[79] “cvd”
[80] “chol”
[81] “ckd”
[82] “ckd_stage”
[83] “concurrent_infections”
[84] “weight”
[85] “height”
[86] “bmi”
[87] “obesity”
[88] “x_total_comorbidities”
[89] “x0”
[90] “x1”
[91] “x2”
[92] “x3”
[93] “x4”
[94] “x5”
[95] “x6”
[96] “total_3_or_more”
[97] “duration_of_therapy”
[98] “clinical_asssesed_improvement”
[99] “patient_reported_improvemnet”
[100] “ult_on_admission_y_n”
[101] “dose_2_2”
[102] “commenced_during”
[103] “dose_1_2”
[104] “after_discharge”
[105] “dose_2_2_2”
[106] “change_dose”
[107] “old_dose”
[108] “new_dose”
[109] “ceased_withheld”
[110] “dose_3_2”
[111] “serum_urate_range”
[112] “serum_urate_level_mmol_l”
[113] “interval_to_next_flare”
[114] “d_c_instructions_present”
[115] “discharge_instructions”
[116] “factors_complicating_gout_treatment” [117] “none”
[118] “infections”
[119] “diuresis”
[120] “aki”
[121] “trauma”
[122] “cognitive_impairment”
[123] “acidosis”
[124] “other_rheum”
[125] “chemo”
[126] “surgery”
[127] “comments_2”

Some variables are ‘categorical’

…rather than ordered.

categorical_cols <- c("gender", "primary_care_team", "ethnicity", "grouped_units_of_admission", "hospital_campus", "hopc",
                      "rheum_input", "mtp", "ankle", "knee", "elbow", "wrist", "mcp", "tophi",
                      "nsaid", "colchicine", "prednisolone", "wean", "ia_steroid_injections",
                      "thiazide_diuretics", "loop_diuretics", "k_sparing_diuretics",
                      "b_blocker", "ac_ei", "arb", "ccb", "a_blocker", "a_b_blocker", "moxonidine",
                      "statins", "fibrates", "ezetimibe",
                      "aspirin", "clopidogrel", "htn", "t2dm", "cvd", "chol", "ckd",
                      "obesity", "clinical_asssesed_improvement", "patient_reported_improvemnet",
                      "ult_on_admission_y_n", "commenced_during", "after_discharge", "change_dose",
                      "ceased_withheld", "d_c_instructions_present",
                      "none", "infections", "diuresis", "aki", "trauma", "cognitive_impairment",
                      "acidosis", "other_rheum", "chemo", "surgery")

d[categorical_cols] <- lapply(d[categorical_cols], factor) # apply 'factor' to those columns
summary(d)
##      number        age        gender ethnicity hospital_campus hopc  
##  Min.   : 1   Min.   :24.00   0:53   0:81      0:29            1:35  
##  1st Qu.:21   1st Qu.:60.00   1:28             1:50            2:46  
##  Median :41   Median :77.00                    2: 2                  
##  Mean   :41   Mean   :70.98                                          
##  3rd Qu.:61   3rd Qu.:83.00                                          
##  Max.   :81   Max.   :95.00                                          
##                                                                      
##  primary_care_team unit_of_admission  grouped_units_of_admission rheum_input
##  0:79              Length:81          0: 2                       0:64       
##  1: 2              Class :character   1:15                       1:17       
##                    Mode  :character   2:46                                  
##                                       3:15                                  
##                                       4: 2                                  
##                                       5: 1                                  
##                                                                             
##  admission_date     discharge_date     duration_of_stay
##  Length:81          Length:81          Min.   : 0.050  
##  Class :character   Class :character   1st Qu.: 1.600  
##  Mode  :character   Mode  :character   Median : 5.680  
##                                        Mean   : 8.896  
##                                        3rd Qu.:11.090  
##                                        Max.   :53.780  
##                                                        
##  number_of_active_joints_involved joint_s_involved     mtp      ankle   
##  Min.   :1.000                    Length:81          0   :45   0   :56  
##  1st Qu.:1.000                    Class :character   1   :33   1   :22  
##  Median :1.000                    Mode  :character   NA's: 3   NA's: 3  
##  Mean   :1.716                                                          
##  3rd Qu.:2.000                                                          
##  Max.   :5.000                                                          
##                                                                         
##    knee     elbow     wrist      mcp      tophi    therapeutic_agents nsaid 
##  0   :57   0   :70   0   :62   0   :62   0   :68   Min.   :0.000      0:71  
##  1   :21   1   : 8   1   :16   1   :16   1   :12   1st Qu.:1.000      1:10  
##  NA's: 3   NA's: 3   NA's: 3   NA's: 3   NA's: 1   Median :1.000            
##                                                    Mean   :1.395            
##                                                    3rd Qu.:2.000            
##                                                    Max.   :3.000            
##                                                                             
##   nsaid_type          nsaid_dose     duration     colchicine   total_col     
##  Length:81          Min.   : 50   Min.   :1.000   0:30       Min.   : 0.500  
##  Class :character   1st Qu.:400   1st Qu.:1.000   1:51       1st Qu.: 1.500  
##  Mode  :character   Median :400   Median :2.000              Median : 3.000  
##                     Mean   :365   Mean   :2.222              Mean   : 4.019  
##                     3rd Qu.:400   3rd Qu.:3.000              3rd Qu.: 5.000  
##                     Max.   :400   Max.   :4.000              Max.   :14.000  
##                     NA's   :71    NA's   :72                 NA's   :42      
##   duration_col    mean_daily_col       d1_col           d2_col      
##  Min.   : 1.000   Min.   :0.2500   Min.   :0.2500   Min.   :0.0000  
##  1st Qu.: 2.000   1st Qu.:0.5000   1st Qu.:0.5000   1st Qu.:0.5000  
##  Median : 5.000   Median :0.6000   Median :1.0000   Median :0.5000  
##  Mean   : 5.615   Mean   :0.7702   Mean   :0.9559   Mean   :0.5343  
##  3rd Qu.: 8.000   3rd Qu.:1.0000   3rd Qu.:1.5000   3rd Qu.:0.7500  
##  Max.   :21.000   Max.   :1.5000   Max.   :2.0000   Max.   :1.0000  
##  NA's   :42       NA's   :37       NA's   :30       NA's   :30      
##  total_daily_dose_mg    course          prednisolone   total_pred   
##  Length:81           Length:81          0:29         Min.   : 25.0  
##  Class :character    Class :character   1:52         1st Qu.: 50.0  
##  Mode  :character    Mode  :character                Median :101.2  
##                                                      Mean   :126.4  
##                                                      3rd Qu.:150.0  
##                                                      Max.   :420.0  
##                                                      NA's   :29     
##  duration_pred    mean_daily_pred     d1_pred         d2_pred     
##  Min.   : 1.000   Min.   : 6.548   Min.   : 5.00   Min.   : 0.00  
##  1st Qu.: 3.000   1st Qu.:14.125   1st Qu.:15.00   1st Qu.:15.00  
##  Median : 5.000   Median :16.201   Median :25.00   Median :20.00  
##  Mean   : 7.885   Mean   :19.706   Mean   :23.32   Mean   :18.61  
##  3rd Qu.: 9.250   3rd Qu.:25.000   3rd Qu.:25.00   3rd Qu.:25.00  
##  Max.   :30.000   Max.   :50.000   Max.   :50.00   Max.   :50.00  
##  NA's   :29       NA's   :29       NA's   :29      NA's   :29     
##    course_1           course_2           wean    ia_steroid_injections
##  Length:81          Length:81          0   :33   0:79                 
##  Class :character   Class :character   1   :19   1: 2                 
##  Mode  :character   Mode  :character   NA's:29                        
##                                                                       
##                                                                       
##                                                                       
##                                                                       
##       dose      comments         x_diuretics_used thiazide_diuretics
##  Min.   :40   Length:81          Min.   :0.0000   0:64              
##  1st Qu.:40   Class :character   1st Qu.:0.0000   1:17              
##  Median :40   Mode  :character   Median :1.0000                     
##  Mean   :40                      Mean   :0.8148                     
##  3rd Qu.:40                      3rd Qu.:1.0000                     
##  Max.   :40                      Max.   :3.0000                     
##  NA's   :79                                                         
##     dose_1          loop_diuretics k_sparing_diuretics other_diuretics
##  Length:81          0:40           0:73                Min.   :0      
##  Class :character   1:41           1: 8                1st Qu.:0      
##  Mode  :character                                      Median :0      
##                                                        Mean   :0      
##                                                        3rd Qu.:0      
##                                                        Max.   :0      
##                                                                       
##     dose_2          anti_hypertensives   x_anti_htn    b_blocker ac_ei  arb   
##  Length:81          Length:81          Min.   :0.000   0:39      0:71   0:68  
##  Class :character   Class :character   1st Qu.:1.000   1:42      1:10   1:13  
##  Mode  :character   Mode  :character   Median :1.000                          
##                                        Mean   :1.309                          
##                                        3rd Qu.:2.000                          
##                                        Max.   :4.000                          
##                                                                               
##  ccb    a_blocker a_b_blocker moxonidine    dose_3          x_anti_chol_used
##  0:51   0   :77   0:79        0:75       Length:81          Min.   :0.0000  
##  1:30   1   : 3   1: 2        1: 6       Class :character   1st Qu.:0.0000  
##         NA's: 1                          Mode  :character   Median :0.0000  
##                                                             Mean   :0.5062  
##                                                             3rd Qu.:1.0000  
##                                                             Max.   :3.0000  
##                                                                             
##  statins fibrates ezetimibe     other   cholesterol_lowering_therapy
##  0:43    0:80     0:79      Min.   :0   Length:81                   
##  1:38    1: 1     1: 2      1st Qu.:0   Class :character            
##                             Median :0   Mode  :character            
##                             Mean   :0                               
##                             3rd Qu.:0                               
##                             Max.   :0                               
##                                                                     
##     dose_4          x_anti_platelet_therapy aspirin clopidogrel  total_number  
##  Length:81          Min.   :0.000           0:60    0:72        Min.   :0.000  
##  Class :character   1st Qu.:2.000           1:21    1: 9        1st Qu.:1.000  
##  Mode  :character   Median :3.000                               Median :3.000  
##                     Mean   :2.901                               Mean   :2.642  
##                     3rd Qu.:4.000                               3rd Qu.:4.000  
##                     Max.   :7.000                               Max.   :7.000  
##                                                                                
##     dose_5          htn    t2dm   cvd    chol   ckd      ckd_stage    
##  Length:81          0:23   0:49   0:27   0:45   0:20   Min.   :0.000  
##  Class :character   1:58   1:32   1:54   1:36   1:61   1st Qu.:1.000  
##  Mode  :character                                      Median :2.000  
##                                                        Mean   :2.049  
##                                                        3rd Qu.:3.000  
##                                                        Max.   :5.000  
##                                                                       
##  concurrent_infections     weight           height           bmi       
##  Min.   :0.0000        Min.   : 43.70   Min.   : 78.0   Min.   :26.25  
##  1st Qu.:0.0000        1st Qu.: 72.70   1st Qu.:154.8   1st Qu.:30.39  
##  Median :0.0000        Median : 81.40   Median :158.0   Median :34.17  
##  Mean   :0.3247        Mean   : 82.48   Mean   :154.4   Mean   :33.78  
##  3rd Qu.:1.0000        3rd Qu.: 92.90   3rd Qu.:164.5   3rd Qu.:37.03  
##  Max.   :1.0000        Max.   :131.40   Max.   :173.0   Max.   :42.67  
##  NA's   :4             NA's   :22       NA's   :67      NA's   :67     
##  obesity   x_total_comorbidities       x0           x1           x2    
##  0   : 3   Min.   :0.00          Min.   :1    Min.   :1    Min.   :1   
##  1   :15   1st Qu.:2.00          1st Qu.:1    1st Qu.:1    1st Qu.:1   
##  NA's:63   Median :4.00          Median :1    Median :1    Median :1   
##            Mean   :3.16          Mean   :1    Mean   :1    Mean   :1   
##            3rd Qu.:4.00          3rd Qu.:1    3rd Qu.:1    3rd Qu.:1   
##            Max.   :6.00          Max.   :1    Max.   :1    Max.   :1   
##                                  NA's   :72   NA's   :73   NA's   :71  
##        x3           x4           x5           x6     total_3_or_more 
##  Min.   :1    Min.   :1    Min.   :1    Min.   :1    Min.   :0.0000  
##  1st Qu.:1    1st Qu.:1    1st Qu.:1    1st Qu.:1    1st Qu.:0.0000  
##  Median :1    Median :1    Median :1    Median :1    Median :1.0000  
##  Mean   :1    Mean   :1    Mean   :1    Mean   :1    Mean   :0.6667  
##  3rd Qu.:1    3rd Qu.:1    3rd Qu.:1    3rd Qu.:1    3rd Qu.:1.0000  
##  Max.   :1    Max.   :1    Max.   :1    Max.   :1    Max.   :1.0000  
##  NA's   :70   NA's   :55   NA's   :70   NA's   :75                   
##  duration_of_therapy clinical_asssesed_improvement patient_reported_improvemnet
##  Min.   : 0.0        0   : 6                       0   : 3                     
##  1st Qu.: 3.0        1   :55                       1   :52                     
##  Median : 6.0        NA's:20                       2   : 1                     
##  Mean   : 7.5                                      NA's:25                     
##  3rd Qu.:10.0                                                                  
##  Max.   :30.0                                                                  
##  NA's   :3                                                                     
##  ult_on_admission_y_n    dose_2_2     commenced_during    dose_1_2    
##  0:55                 Min.   : 10.0   0   :43          Min.   : 50.0  
##  1:26                 1st Qu.: 50.0   1   :12          1st Qu.: 50.0  
##                       Median :100.0   NA's:26          Median :100.0  
##                       Mean   :128.5                    Mean   :112.5  
##                       3rd Qu.:175.0                    3rd Qu.:100.0  
##                       Max.   :400.0                    Max.   :300.0  
##                       NA's   :55                       NA's   :69     
##  after_discharge   dose_2_2_2     change_dose    old_dose         new_dose    
##  0   :40         Min.   : 40.00   0   :23     Min.   : 50.00   Min.   :150.0  
##  1   :15         1st Qu.: 50.00   1   : 3     1st Qu.: 75.00   1st Qu.:175.0  
##  NA's:26         Median : 50.00   NA's:55     Median :100.00   Median :200.0  
##                  Mean   : 67.27               Mean   : 83.33   Mean   :183.3  
##                  3rd Qu.:100.00               3rd Qu.:100.00   3rd Qu.:200.0  
##                  Max.   :100.00               Max.   :100.00   Max.   :200.0  
##                  NA's   :70                   NA's   :78       NA's   :78     
##  ceased_withheld    dose_3_2   serum_urate_range serum_urate_level_mmol_l
##  0   :24         Min.   :100   Min.   :0.000     Min.   :0.1300          
##  1   : 2         1st Qu.:150   1st Qu.:1.000     1st Qu.:0.4500          
##  NA's:55         Median :200   Median :2.000     Median :0.5600          
##                  Mean   :200   Mean   :1.444     Mean   :0.5556          
##                  3rd Qu.:250   3rd Qu.:2.000     3rd Qu.:0.6700          
##                  Max.   :300   Max.   :2.000     Max.   :0.8700          
##                  NA's   :79                      NA's   :20              
##  interval_to_next_flare d_c_instructions_present discharge_instructions
##  Min.   :0              0:38                     Length:81             
##  1st Qu.:0              1:43                     Class :character      
##  Median :0                                       Mode  :character      
##  Mean   :0                                                             
##  3rd Qu.:0                                                             
##  Max.   :0                                                             
##  NA's   :68                                                            
##  factors_complicating_gout_treatment none   infections diuresis aki    trauma
##  Length:81                           0:48   0:49       0:73     0:62   0:79  
##  Class :character                    1:33   1:32       1: 8     1:19   1: 2  
##  Mode  :character                                                            
##                                                                              
##                                                                              
##                                                                              
##                                                                              
##  cognitive_impairment acidosis other_rheum chemo  surgery  comments_2       
##  0:68                 0:80     0:80        0:80   0:79    Length:81         
##  1:13                 1: 1     1: 1        1: 1   1: 2    Class :character  
##                                                           Mode  :character  
##                                                                             
##                                                                             
##                                                                             
## 

Serum urate vs Already on Urate Lowering Therapy

serum_urate_level_mmol_l vs ult_on_admission_y_n

Boxplot

p <- ggplot(
  data = d,
  aes(
    group = ult_on_admission_y_n,
    x = ult_on_admission_y_n,
    y = serum_urate_level_mmol_l
  )
) + geom_boxplot()

p + stat_summary(fun = mean, geom = "point", shape = 23, size = 4)
## Warning: Removed 20 rows containing non-finite values (stat_boxplot).
## Warning: Removed 20 rows containing non-finite values (stat_summary).

same plot with highcharter

highchart() %>%
  hc_xAxis(type = "category") %>%
  hc_add_series_list(
    data_to_boxplot(
      data = d,
      variable = serum_urate_level_mmol_l,
      group_var = ult_on_admission_y_n
    )
  ) %>%
  hc_exporting(enabled = TRUE) # allow 'save'

Wilcox unpaired

(same as Mann-Whitney U)

wilcox.test(
  serum_urate_level_mmol_l ~ ult_on_admission_y_n,
  data = d,
  exact = FALSE, paired = FALSE
)
## 
##  Wilcoxon rank sum test with continuity correction
## 
## data:  serum_urate_level_mmol_l by ult_on_admission_y_n
## W = 445, p-value = 0.09536
## alternative hypothesis: true location shift is not equal to 0

Rheumatology input

Age

d_notRheumPt <- d %>%
  filter(grouped_units_of_admission != 0)

p <- ggplot(
  data = d_notRheumPt,
  aes(
    group = rheum_input,
    x = rheum_input,
    y = age
  )
) + geom_boxplot()

p + stat_summary(fun = mean, geom = "point", shape = 23, size = 4)

Unit of admission

ztable(table(d_notRheumPt$rheum_input, d_notRheumPt$grouped_units_of_admission)) %>%
  makeHeatmap(palette="Blues")
  0 1 2 3 4 5
0 0 14 36 13 1 0
1 0 1 10 2 1 1
CrossTable(d_notRheumPt$rheum_input, d_notRheumPt$grouped_units_of_admission,
           fisher = TRUE)
## 
##  
##    Cell Contents
## |-------------------------|
## |                       N |
## | Chi-square contribution |
## |           N / Row Total |
## |           N / Col Total |
## |         N / Table Total |
## |-------------------------|
## 
##  
## Total Observations in Table:  79 
## 
##  
##                          | d_notRheumPt$grouped_units_of_admission 
## d_notRheumPt$rheum_input |         1 |         2 |         3 |         4 |         5 | Row Total | 
## -------------------------|-----------|-----------|-----------|-----------|-----------|-----------|
##                        0 |        14 |        36 |        13 |         1 |         0 |        64 | 
##                          |     0.281 |     0.043 |     0.059 |     0.237 |     0.810 |           | 
##                          |     0.219 |     0.562 |     0.203 |     0.016 |     0.000 |     0.810 | 
##                          |     0.933 |     0.783 |     0.867 |     0.500 |     0.000 |           | 
##                          |     0.177 |     0.456 |     0.165 |     0.013 |     0.000 |           | 
## -------------------------|-----------|-----------|-----------|-----------|-----------|-----------|
##                        1 |         1 |        10 |         2 |         1 |         1 |        15 | 
##                          |     1.199 |     0.183 |     0.253 |     1.013 |     3.457 |           | 
##                          |     0.067 |     0.667 |     0.133 |     0.067 |     0.067 |     0.190 | 
##                          |     0.067 |     0.217 |     0.133 |     0.500 |     1.000 |           | 
##                          |     0.013 |     0.127 |     0.025 |     0.013 |     0.013 |           | 
## -------------------------|-----------|-----------|-----------|-----------|-----------|-----------|
##             Column Total |        15 |        46 |        15 |         2 |         1 |        79 | 
##                          |     0.190 |     0.582 |     0.190 |     0.025 |     0.013 |           | 
## -------------------------|-----------|-----------|-----------|-----------|-----------|-----------|
## 
##  
## Fisher's Exact Test for Count Data
## ------------------------------------------------------------
## Alternative hypothesis: two.sided
## p =  0.1492576 
## 
## 
p <- ggplot(
  data = d_notRheumPt,
  aes(
    group = grouped_units_of_admission,
    x = grouped_units_of_admission,
    y = rheum_input
  )
) + geom_boxplot()

p + stat_summary(fun = mean, geom = "point", shape = 23, size = 4)

Gender

p <- ggplot(
  data = d_notRheumPt,
  aes(
    group = rheum_input,
    x = rheum_input,
    y = gender
  )
) + geom_boxplot()

p + stat_summary(fun = mean, geom = "point", shape = 23, size = 4)

ztable(table(d_notRheumPt$rheum_input, d_notRheumPt$gender)) %>%
  makeHeatmap(palette="Blues")
  0 1
0 40 24
1 12 3
CrossTable(d_notRheumPt$rheum_input, d_notRheumPt$gender,
           fisher = TRUE)
## 
##  
##    Cell Contents
## |-------------------------|
## |                       N |
## | Chi-square contribution |
## |           N / Row Total |
## |           N / Col Total |
## |         N / Table Total |
## |-------------------------|
## 
##  
## Total Observations in Table:  79 
## 
##  
##                          | d_notRheumPt$gender 
## d_notRheumPt$rheum_input |         0 |         1 | Row Total | 
## -------------------------|-----------|-----------|-----------|
##                        0 |        40 |        24 |        64 | 
##                          |     0.107 |     0.207 |           | 
##                          |     0.625 |     0.375 |     0.810 | 
##                          |     0.769 |     0.889 |           | 
##                          |     0.506 |     0.304 |           | 
## -------------------------|-----------|-----------|-----------|
##                        1 |        12 |         3 |        15 | 
##                          |     0.458 |     0.882 |           | 
##                          |     0.800 |     0.200 |     0.190 | 
##                          |     0.231 |     0.111 |           | 
##                          |     0.152 |     0.038 |           | 
## -------------------------|-----------|-----------|-----------|
##             Column Total |        52 |        27 |        79 | 
##                          |     0.658 |     0.342 |           | 
## -------------------------|-----------|-----------|-----------|
## 
##  
## Fisher's Exact Test for Count Data
## ------------------------------------------------------------
## Sample estimate odds ratio:  0.420881 
## 
## Alternative hypothesis: true odds ratio is not equal to 1
## p =  0.2405739 
## 95% confidence interval:  0.06926226 1.78356 
## 
## Alternative hypothesis: true odds ratio is less than 1
## p =  0.1629917 
## 95% confidence interval:  0 1.483282 
## 
## Alternative hypothesis: true odds ratio is greater than 1
## p =  0.9489704 
## 95% confidence interval:  0.09274648 Inf 
## 
## 
## 

Campus

ztable(table(d_notRheumPt$rheum_input, d_notRheumPt$hospital_campus)) %>%
  makeHeatmap(palette="Blues")
  0 1 2
0 16 46 2
1 11 4 0
CrossTable(d_notRheumPt$rheum_input, d_notRheumPt$hospital_campus,
           fisher = TRUE)
## 
##  
##    Cell Contents
## |-------------------------|
## |                       N |
## | Chi-square contribution |
## |           N / Row Total |
## |           N / Col Total |
## |         N / Table Total |
## |-------------------------|
## 
##  
## Total Observations in Table:  79 
## 
##  
##                          | d_notRheumPt$hospital_campus 
## d_notRheumPt$rheum_input |         0 |         1 |         2 | Row Total | 
## -------------------------|-----------|-----------|-----------|-----------|
##                        0 |        16 |        46 |         2 |        64 | 
##                          |     1.577 |     0.745 |     0.089 |           | 
##                          |     0.250 |     0.719 |     0.031 |     0.810 | 
##                          |     0.593 |     0.920 |     1.000 |           | 
##                          |     0.203 |     0.582 |     0.025 |           | 
## -------------------------|-----------|-----------|-----------|-----------|
##                        1 |        11 |         4 |         0 |        15 | 
##                          |     6.729 |     3.179 |     0.380 |           | 
##                          |     0.733 |     0.267 |     0.000 |     0.190 | 
##                          |     0.407 |     0.080 |     0.000 |           | 
##                          |     0.139 |     0.051 |     0.000 |           | 
## -------------------------|-----------|-----------|-----------|-----------|
##             Column Total |        27 |        50 |         2 |        79 | 
##                          |     0.342 |     0.633 |     0.025 |           | 
## -------------------------|-----------|-----------|-----------|-----------|
## 
##  
## Fisher's Exact Test for Count Data
## ------------------------------------------------------------
## Alternative hypothesis: two.sided
## p =  0.001793077 
## 
## 

Generalized Linear Model

rheum_consulted <- glm(
  rheum_input ~ gender + age + hopc + 
    grouped_units_of_admission + duration_of_stay +
    number_of_active_joints_involved +
    mtp + knee + ankle + elbow + wrist + mcp + tophi + hospital_campus,
  data = d_notRheumPt,
  family = "binomial"
)

summary(rheum_consulted)
## 
## Call:
## glm(formula = rheum_input ~ gender + age + hopc + grouped_units_of_admission + 
##     duration_of_stay + number_of_active_joints_involved + mtp + 
##     knee + ankle + elbow + wrist + mcp + tophi + hospital_campus, 
##     family = "binomial", data = d_notRheumPt)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -1.7833  -0.3433  -0.1003  -0.0021   2.5494  
## 
## Coefficients:
##                                    Estimate Std. Error z value Pr(>|z|)   
## (Intercept)                        -0.28625    4.17324  -0.069  0.94531   
## gender1                            -0.66057    1.33779  -0.494  0.62147   
## age                                -0.11567    0.06245  -1.852  0.06400 . 
## hopc2                              -2.45800    1.47677  -1.664  0.09602 . 
## grouped_units_of_admission2         8.81032    5.13955   1.714  0.08649 . 
## grouped_units_of_admission3         7.59034    4.73530   1.603  0.10895   
## grouped_units_of_admission4         5.47775    4.41705   1.240  0.21492   
## grouped_units_of_admission5        29.36716 3956.18437   0.007  0.99408   
## duration_of_stay                    0.06196    0.05161   1.200  0.22995   
## number_of_active_joints_involved   -0.10115    1.04492  -0.097  0.92289   
## mtp1                                2.46534    2.09531   1.177  0.23936   
## knee1                               2.34039    1.74589   1.341  0.18008   
## ankle1                             -0.31765    1.20794  -0.263  0.79257   
## elbow1                              1.32866    1.76821   0.751  0.45240   
## wrist1                             -0.98977    2.78596  -0.355  0.72239   
## mcp1                                1.40558    2.18495   0.643  0.52003   
## tophi1                              0.57479    1.98761   0.289  0.77244   
## hospital_campus1                   -3.84722    1.40344  -2.741  0.00612 **
## hospital_campus2                  -17.21744 2738.76798  -0.006  0.99498   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 75.503  on 75  degrees of freedom
## Residual deviance: 37.096  on 57  degrees of freedom
##   (3 observations deleted due to missingness)
## AIC: 75.096
## 
## Number of Fisher Scoring iterations: 16
predictors <- d_notRheumPt[, 
                           c("gender", "hopc", "grouped_units_of_admission", "duration_of_stay",
                             "number_of_active_joints_involved", "mtp", "knee", "ankle",
                             "elbow", "wrist", "mcp", "tophi")
] %>%
  mutate_all(function(x) as.numeric(as.character(x))) %>%
  rename(c("admission_unit" = "grouped_units_of_admission", "number_of_joints" = "number_of_active_joints_involved"))

rheum_consult_predictor_cor <- cor(predictors, use = "complete.obs") %>% round(3)
corrplot(rheum_consult_predictor_cor,
         type = "upper", order = "hclust", 
         tl.col = "black", tl.srt = 45)

number_of_active_joints_involved heavily correlated with other variables (e.g. specific active joints), and little role in the model so far. Remove from model

rheum_consulted2 <- glm(
  rheum_input ~ gender + age + hopc + 
    grouped_units_of_admission + duration_of_stay +
    mtp + knee + ankle + elbow + wrist + mcp + tophi + hospital_campus,
  data = d_notRheumPt,
  family = "binomial"
)

summary(rheum_consulted2)
## 
## Call:
## glm(formula = rheum_input ~ gender + age + hopc + grouped_units_of_admission + 
##     duration_of_stay + mtp + knee + ankle + elbow + wrist + mcp + 
##     tophi + hospital_campus, family = "binomial", data = d_notRheumPt)
## 
## Deviance Residuals: 
##      Min        1Q    Median        3Q       Max  
## -1.78574  -0.33979  -0.10061  -0.00203   2.53697  
## 
## Coefficients:
##                               Estimate Std. Error z value Pr(>|z|)   
## (Intercept)                   -0.32087    4.17283  -0.077  0.93871   
## gender1                       -0.65035    1.33132  -0.488  0.62520   
## age                           -0.11545    0.06242  -1.850  0.06436 . 
## hopc2                         -2.48505    1.45719  -1.705  0.08813 . 
## grouped_units_of_admission2    8.80777    5.13768   1.714  0.08646 . 
## grouped_units_of_admission3    7.64779    4.70608   1.625  0.10414   
## grouped_units_of_admission4    5.46766    4.40872   1.240  0.21490   
## grouped_units_of_admission5   29.43561 3956.18433   0.007  0.99406   
## duration_of_stay               0.06258    0.05120   1.222  0.22161   
## mtp1                           2.33793    1.61774   1.445  0.14841   
## knee1                          2.23359    1.34621   1.659  0.09708 . 
## ankle1                        -0.38842    0.96136  -0.404  0.68619   
## elbow1                         1.25526    1.60128   0.784  0.43309   
## wrist1                        -1.18133    2.00109  -0.590  0.55496   
## mcp1                           1.28271    1.78640   0.718  0.47273   
## tophi1                         0.52529    1.94328   0.270  0.78692   
## hospital_campus1              -3.82934    1.39009  -2.755  0.00587 **
## hospital_campus2             -17.18216 2726.17009  -0.006  0.99497   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 75.503  on 75  degrees of freedom
## Residual deviance: 37.105  on 58  degrees of freedom
##   (3 observations deleted due to missingness)
## AIC: 73.105
## 
## Number of Fisher Scoring iterations: 16

MTP, MCP, wrist and knee heavily correlated. Wrist has highest p-value, remove.

rheum_consulted3 <- glm(
  rheum_input ~ gender + age + hopc + 
    grouped_units_of_admission + duration_of_stay +
    mtp + knee + ankle + elbow + mcp + tophi + hospital_campus,
  data = d_notRheumPt,
  family = "binomial"
)

summary(rheum_consulted3)
## 
## Call:
## glm(formula = rheum_input ~ gender + age + hopc + grouped_units_of_admission + 
##     duration_of_stay + mtp + knee + ankle + elbow + mcp + tophi + 
##     hospital_campus, family = "binomial", data = d_notRheumPt)
## 
## Deviance Residuals: 
##      Min        1Q    Median        3Q       Max  
## -1.77035  -0.41455  -0.08472  -0.00324   2.66260  
## 
## Coefficients:
##                               Estimate Std. Error z value Pr(>|z|)   
## (Intercept)                    0.27945    3.91236   0.071  0.94306   
## gender1                       -0.63887    1.32724  -0.481  0.63027   
## age                           -0.11671    0.06286  -1.857  0.06336 . 
## hopc2                         -2.67012    1.44774  -1.844  0.06513 . 
## grouped_units_of_admission2    8.42781    4.96895   1.696  0.08987 . 
## grouped_units_of_admission3    7.48614    4.60485   1.626  0.10401   
## grouped_units_of_admission4    5.18832    4.27806   1.213  0.22522   
## grouped_units_of_admission5   29.48513 3956.18410   0.007  0.99405   
## duration_of_stay               0.06305    0.05092   1.238  0.21561   
## mtp1                           2.38834    1.53796   1.553  0.12044   
## knee1                          2.00904    1.23129   1.632  0.10275   
## ankle1                        -0.39640    0.95221  -0.416  0.67719   
## elbow1                         1.04387    1.45840   0.716  0.47414   
## mcp1                           0.76786    1.49519   0.514  0.60757   
## tophi1                         0.80929    1.74321   0.464  0.64247   
## hospital_campus1              -4.14402    1.36583  -3.034  0.00241 **
## hospital_campus2             -17.48335 2774.45440  -0.006  0.99497   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 75.503  on 75  degrees of freedom
## Residual deviance: 37.508  on 59  degrees of freedom
##   (3 observations deleted due to missingness)
## AIC: 71.508
## 
## Number of Fisher Scoring iterations: 16

Remove tophi

rheum_consulted4 <- glm(
  rheum_input ~ gender + age + hopc + 
    grouped_units_of_admission + duration_of_stay +
    mtp + knee + ankle + elbow + mcp + hospital_campus,
  data = d_notRheumPt,
  family = "binomial"
)

summary(rheum_consulted4)
## 
## Call:
## glm(formula = rheum_input ~ gender + age + hopc + grouped_units_of_admission + 
##     duration_of_stay + mtp + knee + ankle + elbow + mcp + hospital_campus, 
##     family = "binomial", data = d_notRheumPt)
## 
## Deviance Residuals: 
##      Min        1Q    Median        3Q       Max  
## -1.69306  -0.33141  -0.09629  -0.00420   2.73713  
## 
## Coefficients:
##                               Estimate Std. Error z value Pr(>|z|)   
## (Intercept)                    0.24670    3.66209   0.067  0.94629   
## gender1                       -0.81242    1.27201  -0.639  0.52303   
## age                           -0.10922    0.05896  -1.852  0.06397 . 
## hopc2                         -2.66329    1.44707  -1.840  0.06570 . 
## grouped_units_of_admission2    7.98936    4.61115   1.733  0.08316 . 
## grouped_units_of_admission3    7.08557    4.25130   1.667  0.09558 . 
## grouped_units_of_admission4    4.94464    3.99790   1.237  0.21616   
## grouped_units_of_admission5   29.60474 3956.18388   0.007  0.99403   
## duration_of_stay               0.05698    0.04842   1.177  0.23926   
## mtp1                           2.47558    1.56524   1.582  0.11374   
## knee1                          1.90612    1.21347   1.571  0.11623   
## ankle1                        -0.38933    0.94592  -0.412  0.68064   
## elbow1                         1.32982    1.32276   1.005  0.31473   
## mcp1                           0.74476    1.48427   0.502  0.61583   
## hospital_campus1              -4.01107    1.28938  -3.111  0.00187 **
## hospital_campus2             -17.35513 2755.82841  -0.006  0.99498   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 75.503  on 75  degrees of freedom
## Residual deviance: 37.719  on 60  degrees of freedom
##   (3 observations deleted due to missingness)
## AIC: 69.719
## 
## Number of Fisher Scoring iterations: 16

Remove ankle

rheum_consulted5 <- glm(
  rheum_input ~ gender + age + hopc + 
    grouped_units_of_admission + duration_of_stay +
    mtp + knee + elbow + mcp + hospital_campus,
  data = d_notRheumPt,
  family = "binomial"
)

summary(rheum_consulted5)
## 
## Call:
## glm(formula = rheum_input ~ gender + age + hopc + grouped_units_of_admission + 
##     duration_of_stay + mtp + knee + elbow + mcp + hospital_campus, 
##     family = "binomial", data = d_notRheumPt)
## 
## Deviance Residuals: 
##      Min        1Q    Median        3Q       Max  
## -1.66930  -0.32910  -0.09162  -0.00376   2.73932  
## 
## Coefficients:
##                               Estimate Std. Error z value Pr(>|z|)   
## (Intercept)                    0.10480    3.50344   0.030  0.97614   
## gender1                       -0.75566    1.26347  -0.598  0.54979   
## age                           -0.11025    0.05882  -1.874  0.06090 . 
## hopc2                         -2.68787    1.44305  -1.863  0.06251 . 
## grouped_units_of_admission2    8.09503    4.55939   1.775  0.07582 . 
## grouped_units_of_admission3    7.22488    4.17178   1.732  0.08330 . 
## grouped_units_of_admission4    4.72190    3.85917   1.224  0.22112   
## grouped_units_of_admission5   29.88186 3956.18382   0.008  0.99397   
## duration_of_stay               0.05570    0.04920   1.132  0.25755   
## mtp1                           2.46803    1.56690   1.575  0.11523   
## knee1                          1.94319    1.20620   1.611  0.10718   
## elbow1                         1.33800    1.29972   1.029  0.30327   
## mcp1                           0.71053    1.45453   0.488  0.62520   
## hospital_campus1              -4.02251    1.29698  -3.101  0.00193 **
## hospital_campus2             -17.22134 2750.95865  -0.006  0.99501   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 75.503  on 75  degrees of freedom
## Residual deviance: 37.892  on 61  degrees of freedom
##   (3 observations deleted due to missingness)
## AIC: 67.892
## 
## Number of Fisher Scoring iterations: 16

Remove mcp

rheum_consulted6 <- glm(
  rheum_input ~ gender + age + hopc + 
    grouped_units_of_admission + duration_of_stay +
    mtp + knee + elbow + hospital_campus,
  data = d_notRheumPt,
  family = "binomial"
)

summary(rheum_consulted6)
## 
## Call:
## glm(formula = rheum_input ~ gender + age + hopc + grouped_units_of_admission + 
##     duration_of_stay + mtp + knee + elbow + hospital_campus, 
##     family = "binomial", data = d_notRheumPt)
## 
## Deviance Residuals: 
##      Min        1Q    Median        3Q       Max  
## -1.74568  -0.34874  -0.10401  -0.00616   2.59590  
## 
## Coefficients:
##                               Estimate Std. Error z value Pr(>|z|)   
## (Intercept)                    0.37799    3.28264   0.115  0.90833   
## gender1                       -0.67582    1.23210  -0.549  0.58334   
## age                           -0.10085    0.05379  -1.875  0.06082 . 
## hopc2                         -2.58757    1.41001  -1.835  0.06648 . 
## grouped_units_of_admission2    7.22730    3.87316   1.866  0.06204 . 
## grouped_units_of_admission3    6.57193    3.66833   1.792  0.07321 . 
## grouped_units_of_admission4    4.06899    3.37426   1.206  0.22786   
## grouped_units_of_admission5   29.39374 3956.18329   0.007  0.99407   
## duration_of_stay               0.05361    0.04785   1.120  0.26261   
## mtp1                           2.15235    1.37762   1.562  0.11820   
## knee1                          1.90839    1.19544   1.596  0.11040   
## elbow1                         1.41440    1.27651   1.108  0.26785   
## hospital_campus1              -3.88066    1.22519  -3.167  0.00154 **
## hospital_campus2             -17.43573 2761.94026  -0.006  0.99496   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 75.503  on 75  degrees of freedom
## Residual deviance: 38.128  on 62  degrees of freedom
##   (3 observations deleted due to missingness)
## AIC: 66.128
## 
## Number of Fisher Scoring iterations: 16

Remove duration of stay

rheum_consulted7 <- glm(
  rheum_input ~ gender + age + hopc + 
    grouped_units_of_admission +
    mtp + knee + elbow + hospital_campus,
  data = d_notRheumPt,
  family = "binomial"
)

summary(rheum_consulted7)
## 
## Call:
## glm(formula = rheum_input ~ gender + age + hopc + grouped_units_of_admission + 
##     mtp + knee + elbow + hospital_campus, family = "binomial", 
##     data = d_notRheumPt)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -1.5969  -0.3925  -0.1047  -0.0082   2.7805  
## 
## Coefficients:
##                               Estimate Std. Error z value Pr(>|z|)   
## (Intercept)                   -0.23106    3.15990  -0.073  0.94171   
## gender1                       -1.12352    1.19045  -0.944  0.34528   
## age                           -0.08749    0.04969  -1.761  0.07830 . 
## hopc2                         -1.87108    1.18388  -1.580  0.11400   
## grouped_units_of_admission2    6.98348    3.70982   1.882  0.05978 . 
## grouped_units_of_admission3    5.87455    3.37290   1.742  0.08156 . 
## grouped_units_of_admission4    4.22140    3.31672   1.273  0.20310   
## grouped_units_of_admission5   28.81446 3956.18298   0.007  0.99419   
## mtp1                           2.43201    1.35822   1.791  0.07336 . 
## knee1                          1.81182    1.15403   1.570  0.11642   
## elbow1                         1.24849    1.24201   1.005  0.31479   
## hospital_campus1              -3.66839    1.17593  -3.120  0.00181 **
## hospital_campus2             -16.60371 2639.30167  -0.006  0.99498   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 75.503  on 75  degrees of freedom
## Residual deviance: 39.485  on 63  degrees of freedom
##   (3 observations deleted due to missingness)
## AIC: 65.485
## 
## Number of Fisher Scoring iterations: 16

remove age

rheum_consulted8 <- glm(
  rheum_input ~ gender + hopc + 
    grouped_units_of_admission +
    mtp + knee + elbow + hospital_campus,
  data = d_notRheumPt,
  family = "binomial"
)

summary(rheum_consulted8)
## 
## Call:
## glm(formula = rheum_input ~ gender + hopc + grouped_units_of_admission + 
##     mtp + knee + elbow + hospital_campus, family = "binomial", 
##     data = d_notRheumPt)
## 
## Deviance Residuals: 
##      Min        1Q    Median        3Q       Max  
## -1.51242  -0.39440  -0.15725  -0.05777   2.83855  
## 
## Coefficients:
##                              Estimate Std. Error z value Pr(>|z|)   
## (Intercept)                   -3.5390     2.3644  -1.497  0.13445   
## gender1                       -1.2200     1.1067  -1.102  0.27029   
## hopc2                         -0.8651     0.9921  -0.872  0.38322   
## grouped_units_of_admission2    2.7863     2.0730   1.344  0.17892   
## grouped_units_of_admission3    2.9564     2.3556   1.255  0.20947   
## grouped_units_of_admission4    4.2105     3.2180   1.308  0.19074   
## grouped_units_of_admission5   23.9609  3956.1811   0.006  0.99517   
## mtp1                           1.7887     1.1239   1.592  0.11148   
## knee1                          1.5128     1.0118   1.495  0.13488   
## elbow1                         1.8809     1.1539   1.630  0.10309   
## hospital_campus1              -2.8558     0.9540  -2.993  0.00276 **
## hospital_campus2             -16.5539  2778.3657  -0.006  0.99525   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 75.503  on 75  degrees of freedom
## Residual deviance: 43.120  on 64  degrees of freedom
##   (3 observations deleted due to missingness)
## AIC: 67.12
## 
## Number of Fisher Scoring iterations: 16

remove admission group

rheum_consulted9 <- glm(
  rheum_input ~ gender + hopc + 
    mtp + knee + elbow + hospital_campus,
  data = d_notRheumPt,
  family = "binomial"
)

summary(rheum_consulted9)
## 
## Call:
## glm(formula = rheum_input ~ gender + hopc + mtp + knee + elbow + 
##     hospital_campus, family = "binomial", data = d_notRheumPt)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -1.4369  -0.5732  -0.3192  -0.1197   2.8192  
## 
## Coefficients:
##                   Estimate Std. Error z value Pr(>|z|)   
## (Intercept)        -0.3887     0.9682  -0.402  0.68803   
## gender1            -1.3344     0.9641  -1.384  0.16633   
## hopc2              -0.6497     0.7606  -0.854  0.39294   
## mtp1                1.0968     0.8454   1.297  0.19454   
## knee1               0.9808     0.8192   1.197  0.23119   
## elbow1              1.4818     0.9799   1.512  0.13047   
## hospital_campus1   -2.5629     0.8347  -3.070  0.00214 **
## hospital_campus2  -15.7524  1659.7199  -0.009  0.99243   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 75.503  on 75  degrees of freedom
## Residual deviance: 53.501  on 68  degrees of freedom
##   (3 observations deleted due to missingness)
## AIC: 69.501
## 
## Number of Fisher Scoring iterations: 15

just some joints and campus

rheum_consulted10 <- glm(
  rheum_input ~  mtp + knee + elbow + hospital_campus,
  data = d_notRheumPt,
  family = "binomial"
)

summary(rheum_consulted10)
## 
## Call:
## glm(formula = rheum_input ~ mtp + knee + elbow + hospital_campus, 
##     family = "binomial", data = d_notRheumPt)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -1.4504  -0.6155  -0.3526  -0.2531   2.6294  
## 
## Coefficients:
##                   Estimate Std. Error z value Pr(>|z|)   
## (Intercept)        -1.2335     0.7119  -1.733  0.08318 . 
## mtp1                0.6779     0.7786   0.871  0.38395   
## knee1               1.1778     0.8083   1.457  0.14508   
## elbow1              1.8609     0.9621   1.934  0.05308 . 
## hospital_campus1   -2.1913     0.7327  -2.991  0.00278 **
## hospital_campus2  -16.0281  1648.5621  -0.010  0.99224   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 75.503  on 75  degrees of freedom
## Residual deviance: 55.936  on 70  degrees of freedom
##   (3 observations deleted due to missingness)
## AIC: 67.936
## 
## Number of Fisher Scoring iterations: 15

just grouped units of admission and campus

rheum_consulted11 <- glm(
  rheum_input ~ grouped_units_of_admission + hospital_campus,
  data = d_notRheumPt,
  family = "binomial"
)

summary(rheum_consulted11)
## 
## Call:
## glm(formula = rheum_input ~ grouped_units_of_admission + hospital_campus, 
##     family = "binomial", data = d_notRheumPt)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -1.1185  -0.4018  -0.4018  -0.2113   2.5127  
## 
## Coefficients:
##                              Estimate Std. Error z value Pr(>|z|)   
## (Intercept)                   -1.4548     1.1027  -1.319  0.18708   
## grouped_units_of_admission2    1.3147     1.1565   1.137  0.25564   
## grouped_units_of_admission3    0.6773     1.3592   0.498  0.61826   
## grouped_units_of_admission4    2.6227     1.9909   1.317  0.18773   
## grouped_units_of_admission5   21.3567  3956.1805   0.005  0.99569   
## hospital_campus1              -2.3359     0.7286  -3.206  0.00135 **
## hospital_campus2             -17.4260  2797.4420  -0.006  0.99503   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 76.794  on 78  degrees of freedom
## Residual deviance: 56.369  on 72  degrees of freedom
## AIC: 70.369
## 
## Number of Fisher Scoring iterations: 16
CrossTable(d_notRheumPt$number_of_active_joints_involved, d_notRheumPt$rheum_input, fisher = TRUE)
## 
##  
##    Cell Contents
## |-------------------------|
## |                       N |
## | Chi-square contribution |
## |           N / Row Total |
## |           N / Col Total |
## |         N / Table Total |
## |-------------------------|
## 
##  
## Total Observations in Table:  79 
## 
##  
##                                               | d_notRheumPt$rheum_input 
## d_notRheumPt$number_of_active_joints_involved |         0 |         1 | Row Total | 
## ----------------------------------------------|-----------|-----------|-----------|
##                                             1 |        38 |         7 |        45 | 
##                                               |     0.065 |     0.279 |           | 
##                                               |     0.844 |     0.156 |     0.570 | 
##                                               |     0.594 |     0.467 |           | 
##                                               |     0.481 |     0.089 |           | 
## ----------------------------------------------|-----------|-----------|-----------|
##                                             2 |        19 |         5 |        24 | 
##                                               |     0.010 |     0.043 |           | 
##                                               |     0.792 |     0.208 |     0.304 | 
##                                               |     0.297 |     0.333 |           | 
##                                               |     0.241 |     0.063 |           | 
## ----------------------------------------------|-----------|-----------|-----------|
##                                             3 |         3 |         1 |         4 | 
##                                               |     0.018 |     0.076 |           | 
##                                               |     0.750 |     0.250 |     0.051 | 
##                                               |     0.047 |     0.067 |           | 
##                                               |     0.038 |     0.013 |           | 
## ----------------------------------------------|-----------|-----------|-----------|
##                                             4 |         2 |         0 |         2 | 
##                                               |     0.089 |     0.380 |           | 
##                                               |     1.000 |     0.000 |     0.025 | 
##                                               |     0.031 |     0.000 |           | 
##                                               |     0.025 |     0.000 |           | 
## ----------------------------------------------|-----------|-----------|-----------|
##                                             5 |         2 |         2 |         4 | 
##                                               |     0.475 |     2.026 |           | 
##                                               |     0.500 |     0.500 |     0.051 | 
##                                               |     0.031 |     0.133 |           | 
##                                               |     0.025 |     0.025 |           | 
## ----------------------------------------------|-----------|-----------|-----------|
##                                  Column Total |        64 |        15 |        79 | 
##                                               |     0.810 |     0.190 |           | 
## ----------------------------------------------|-----------|-----------|-----------|
## 
##  
## Fisher's Exact Test for Count Data
## ------------------------------------------------------------
## Alternative hypothesis: two.sided
## p =  0.3854947 
## 
## 
rheum_consulted12 <- glm(
  rheum_input ~ number_of_active_joints_involved + hospital_campus,
  data = d_notRheumPt,
  family = "binomial"
)

summary(rheum_consulted12)
## 
## Call:
## glm(formula = rheum_input ~ number_of_active_joints_involved + 
##     hospital_campus, family = "binomial", data = d_notRheumPt)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -1.1944  -0.5314  -0.3565  -0.3565   2.3611  
## 
## Coefficients:
##                                   Estimate Std. Error z value Pr(>|z|)   
## (Intercept)                        -0.9586     0.6286  -1.525  0.12731   
## number_of_active_joints_involved    0.3328     0.2787   1.194  0.23241   
## hospital_campus1                   -2.0980     0.6633  -3.163  0.00156 **
## hospital_campus2                  -15.9403  1696.7344  -0.009  0.99250   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 76.794  on 78  degrees of freedom
## Residual deviance: 62.973  on 75  degrees of freedom
## AIC: 70.973
## 
## Number of Fisher Scoring iterations: 15

Gout therapy

CrossTable(d$prednisolone, d$rheum_input, fisher = TRUE)
## 
##  
##    Cell Contents
## |-------------------------|
## |                       N |
## | Chi-square contribution |
## |           N / Row Total |
## |           N / Col Total |
## |         N / Table Total |
## |-------------------------|
## 
##  
## Total Observations in Table:  81 
## 
##  
##                | d$rheum_input 
## d$prednisolone |         0 |         1 | Row Total | 
## ---------------|-----------|-----------|-----------|
##              0 |        23 |         6 |        29 | 
##                |     0.000 |     0.001 |           | 
##                |     0.793 |     0.207 |     0.358 | 
##                |     0.359 |     0.353 |           | 
##                |     0.284 |     0.074 |           | 
## ---------------|-----------|-----------|-----------|
##              1 |        41 |        11 |        52 | 
##                |     0.000 |     0.001 |           | 
##                |     0.788 |     0.212 |     0.642 | 
##                |     0.641 |     0.647 |           | 
##                |     0.506 |     0.136 |           | 
## ---------------|-----------|-----------|-----------|
##   Column Total |        64 |        17 |        81 | 
##                |     0.790 |     0.210 |           | 
## ---------------|-----------|-----------|-----------|
## 
##  
## Fisher's Exact Test for Count Data
## ------------------------------------------------------------
## Sample estimate odds ratio:  1.028103 
## 
## Alternative hypothesis: true odds ratio is not equal to 1
## p =  1 
## 95% confidence interval:  0.2996486 3.852664 
## 
## Alternative hypothesis: true odds ratio is less than 1
## p =  0.624778 
## 95% confidence interval:  0 3.158698 
## 
## Alternative hypothesis: true odds ratio is greater than 1
## p =  0.5986041 
## 95% confidence interval:  0.3556597 Inf 
## 
## 
## 
CrossTable(d$ia_steroid_injections, d$rheum_input, fisher = TRUE)
## 
##  
##    Cell Contents
## |-------------------------|
## |                       N |
## | Chi-square contribution |
## |           N / Row Total |
## |           N / Col Total |
## |         N / Table Total |
## |-------------------------|
## 
##  
## Total Observations in Table:  81 
## 
##  
##                         | d$rheum_input 
## d$ia_steroid_injections |         0 |         1 | Row Total | 
## ------------------------|-----------|-----------|-----------|
##                       0 |        64 |        15 |        79 | 
##                         |     0.040 |     0.151 |           | 
##                         |     0.810 |     0.190 |     0.975 | 
##                         |     1.000 |     0.882 |           | 
##                         |     0.790 |     0.185 |           | 
## ------------------------|-----------|-----------|-----------|
##                       1 |         0 |         2 |         2 | 
##                         |     1.580 |     5.949 |           | 
##                         |     0.000 |     1.000 |     0.025 | 
##                         |     0.000 |     0.118 |           | 
##                         |     0.000 |     0.025 |           | 
## ------------------------|-----------|-----------|-----------|
##            Column Total |        64 |        17 |        81 | 
##                         |     0.790 |     0.210 |           | 
## ------------------------|-----------|-----------|-----------|
## 
##  
## Fisher's Exact Test for Count Data
## ------------------------------------------------------------
## Sample estimate odds ratio:  Inf 
## 
## Alternative hypothesis: true odds ratio is not equal to 1
## p =  0.04197531 
## 95% confidence interval:  0.7275513 Inf 
## 
## Alternative hypothesis: true odds ratio is less than 1
## p =  1 
## 95% confidence interval:  0 Inf 
## 
## Alternative hypothesis: true odds ratio is greater than 1
## p =  0.04197531 
## 95% confidence interval:  1.118547 Inf 
## 
## 
## 
hopc <- glm(
  ia_steroid_injections ~ rheum_input,
  data = d,
  family = "binomial"
)

summary(hopc)
## 
## Call:
## glm(formula = ia_steroid_injections ~ rheum_input, family = "binomial", 
##     data = d)
## 
## Deviance Residuals: 
##      Min        1Q    Median        3Q       Max  
## -0.50033  -0.00003  -0.00003  -0.00003   2.06885  
## 
## Coefficients:
##              Estimate Std. Error z value Pr(>|z|)
## (Intercept)    -21.57    3654.05  -0.006    0.995
## rheum_input1    19.55    3654.05   0.005    0.996
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 18.755  on 80  degrees of freedom
## Residual deviance: 12.315  on 79  degrees of freedom
## AIC: 16.315
## 
## Number of Fisher Scoring iterations: 20
CrossTable(d$ia_steroid_injections, d$rheum_input, fisher = TRUE)
## 
##  
##    Cell Contents
## |-------------------------|
## |                       N |
## | Chi-square contribution |
## |           N / Row Total |
## |           N / Col Total |
## |         N / Table Total |
## |-------------------------|
## 
##  
## Total Observations in Table:  81 
## 
##  
##                         | d$rheum_input 
## d$ia_steroid_injections |         0 |         1 | Row Total | 
## ------------------------|-----------|-----------|-----------|
##                       0 |        64 |        15 |        79 | 
##                         |     0.040 |     0.151 |           | 
##                         |     0.810 |     0.190 |     0.975 | 
##                         |     1.000 |     0.882 |           | 
##                         |     0.790 |     0.185 |           | 
## ------------------------|-----------|-----------|-----------|
##                       1 |         0 |         2 |         2 | 
##                         |     1.580 |     5.949 |           | 
##                         |     0.000 |     1.000 |     0.025 | 
##                         |     0.000 |     0.118 |           | 
##                         |     0.000 |     0.025 |           | 
## ------------------------|-----------|-----------|-----------|
##            Column Total |        64 |        17 |        81 | 
##                         |     0.790 |     0.210 |           | 
## ------------------------|-----------|-----------|-----------|
## 
##  
## Fisher's Exact Test for Count Data
## ------------------------------------------------------------
## Sample estimate odds ratio:  Inf 
## 
## Alternative hypothesis: true odds ratio is not equal to 1
## p =  0.04197531 
## 95% confidence interval:  0.7275513 Inf 
## 
## Alternative hypothesis: true odds ratio is less than 1
## p =  1 
## 95% confidence interval:  0 Inf 
## 
## Alternative hypothesis: true odds ratio is greater than 1
## p =  0.04197531 
## 95% confidence interval:  1.118547 Inf 
## 
## 
## 

Secondary gout

medications - sub-groups

hopc <- glm(
  hopc ~  thiazide_diuretics + loop_diuretics + k_sparing_diuretics + other_diuretics + b_blocker + ac_ei + arb + ccb + a_blocker + a_b_blocker + moxonidine + statins + fibrates + ezetimibe + aspirin + clopidogrel,
  data = d,
  family = "binomial"
)

summary(hopc)
## 
## Call:
## glm(formula = hopc ~ thiazide_diuretics + loop_diuretics + k_sparing_diuretics + 
##     other_diuretics + b_blocker + ac_ei + arb + ccb + a_blocker + 
##     a_b_blocker + moxonidine + statins + fibrates + ezetimibe + 
##     aspirin + clopidogrel, family = "binomial", data = d)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -2.0637  -0.8569   0.4377   0.9571   1.7163  
## 
## Coefficients: (1 not defined because of singularities)
##                        Estimate Std. Error z value Pr(>|z|)  
## (Intercept)            -0.81275    0.47640  -1.706    0.088 .
## thiazide_diuretics1    -0.04582    0.76115  -0.060    0.952  
## loop_diuretics1         0.86983    0.73998   1.175    0.240  
## k_sparing_diuretics1    0.50609    1.02291   0.495    0.621  
## other_diuretics              NA         NA      NA       NA  
## b_blocker1              1.06880    0.74852   1.428    0.153  
## ac_ei1                 -0.81184    0.86521  -0.938    0.348  
## arb1                    0.05892    0.75315   0.078    0.938  
## ccb1                    0.47112    0.60193   0.783    0.434  
## a_blocker1             17.08547 2703.61784   0.006    0.995  
## a_b_blocker1           -0.30652    2.07750  -0.148    0.883  
## moxonidine1            -0.17586    1.17114  -0.150    0.881  
## statins1               -0.58266    0.67757  -0.860    0.390  
## fibrates1              18.18195 6213.87804   0.003    0.998  
## ezetimibe1             -1.30688 4791.75481   0.000    1.000  
## aspirin1                0.74546    0.75919   0.982    0.326  
## clopidogrel1            0.71422    1.28213   0.557    0.577  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 109.650  on 79  degrees of freedom
## Residual deviance:  87.632  on 64  degrees of freedom
##   (1 observation deleted due to missingness)
## AIC: 119.63
## 
## Number of Fisher Scoring iterations: 16

medication - major groups

hopc2 <- glm(
  hopc ~  (x_diuretics_used > 0) + (x_anti_htn > 0) + (x_anti_chol_used > 0) + (x_anti_platelet_therapy > 0),
  data = d,
  family = "binomial"
)

summary(hopc2)
## 
## Call:
## glm(formula = hopc ~ (x_diuretics_used > 0) + (x_anti_htn > 0) + 
##     (x_anti_chol_used > 0) + (x_anti_platelet_therapy > 0), family = "binomial", 
##     data = d)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -1.7660  -1.1241   0.6871   0.9319   1.9728  
## 
## Coefficients:
##                                 Estimate Std. Error z value Pr(>|z|)  
## (Intercept)                      -1.7918     0.7638  -2.346    0.019 *
## x_diuretics_used > 0TRUE          0.7359     0.5876   1.252    0.210  
## x_anti_htn > 0TRUE                1.3233     1.5018   0.881    0.378  
## x_anti_chol_used > 0TRUE         -0.7141     0.5649  -1.264    0.206  
## x_anti_platelet_therapy > 0TRUE   1.0558     1.7113   0.617    0.537  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 110.791  on 80  degrees of freedom
## Residual deviance:  94.576  on 76  degrees of freedom
## AIC: 104.58
## 
## Number of Fisher Scoring iterations: 4

conditions

hopc3 <- glm(
  hopc ~  htn + t2dm + cvd + chol + ckd,
  data = d,
  family = "binomial"
)
# not including obesity
summary(hopc3)
## 
## Call:
## glm(formula = hopc ~ htn + t2dm + cvd + chol + ckd, family = "binomial", 
##     data = d)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -1.7925  -0.9102   0.7158   0.9316   1.7590  
## 
## Coefficients:
##             Estimate Std. Error z value Pr(>|z|)   
## (Intercept) -0.88609    0.59028  -1.501  0.13332   
## htn1         0.35097    0.57476   0.611  0.54144   
## t2dm1        0.62101    0.57099   1.088  0.27677   
## cvd1         1.89829    0.64642   2.937  0.00332 **
## chol1        0.01944    0.56125   0.035  0.97237   
## ckd1        -0.77248    0.76730  -1.007  0.31405   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 110.791  on 80  degrees of freedom
## Residual deviance:  96.053  on 75  degrees of freedom
## AIC: 108.05
## 
## Number of Fisher Scoring iterations: 4
hopc_ckd <- glm(
  hopc ~  ckd,
  data = d,
  family = "binomial"
)
# not including obesity
summary(hopc_ckd)
## 
## Call:
## glm(formula = hopc ~ ckd, family = "binomial", data = d)
## 
## Deviance Residuals: 
##    Min      1Q  Median      3Q     Max  
## -1.366  -1.366   1.000   1.000   1.264  
## 
## Coefficients:
##             Estimate Std. Error z value Pr(>|z|)
## (Intercept)  -0.2007     0.4495  -0.446    0.655
## ckd1          0.6335     0.5203   1.218    0.223
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 110.79  on 80  degrees of freedom
## Residual deviance: 109.30  on 79  degrees of freedom
## AIC: 113.3
## 
## Number of Fisher Scoring iterations: 4

co-morbidities

n_comorbidities_hopc <- table(d$x_total_comorbidities, d$hopc)

ztable(n_comorbidities_hopc) %>%
  makeHeatmap(palette="Blues")
  1 2
0 8 1
1 4 4
2 2 8
3 7 4
4 10 16
5 4 7
6 0 6
CrossTable(d$x_total_comorbidities, d$hopc,
           fisher = TRUE)
## 
##  
##    Cell Contents
## |-------------------------|
## |                       N |
## | Chi-square contribution |
## |           N / Row Total |
## |           N / Col Total |
## |         N / Table Total |
## |-------------------------|
## 
##  
## Total Observations in Table:  81 
## 
##  
##                         | d$hopc 
## d$x_total_comorbidities |         1 |         2 | Row Total | 
## ------------------------|-----------|-----------|-----------|
##                       0 |         8 |         1 |         9 | 
##                         |     4.346 |     3.307 |           | 
##                         |     0.889 |     0.111 |     0.111 | 
##                         |     0.229 |     0.022 |           | 
##                         |     0.099 |     0.012 |           | 
## ------------------------|-----------|-----------|-----------|
##                       1 |         4 |         4 |         8 | 
##                         |     0.085 |     0.065 |           | 
##                         |     0.500 |     0.500 |     0.099 | 
##                         |     0.114 |     0.087 |           | 
##                         |     0.049 |     0.049 |           | 
## ------------------------|-----------|-----------|-----------|
##                       2 |         2 |         8 |        10 | 
##                         |     1.247 |     0.949 |           | 
##                         |     0.200 |     0.800 |     0.123 | 
##                         |     0.057 |     0.174 |           | 
##                         |     0.025 |     0.099 |           | 
## ------------------------|-----------|-----------|-----------|
##                       3 |         7 |         4 |        11 | 
##                         |     1.062 |     0.808 |           | 
##                         |     0.636 |     0.364 |     0.136 | 
##                         |     0.200 |     0.087 |           | 
##                         |     0.086 |     0.049 |           | 
## ------------------------|-----------|-----------|-----------|
##                       4 |        10 |        16 |        26 | 
##                         |     0.136 |     0.103 |           | 
##                         |     0.385 |     0.615 |     0.321 | 
##                         |     0.286 |     0.348 |           | 
##                         |     0.123 |     0.198 |           | 
## ------------------------|-----------|-----------|-----------|
##                       5 |         4 |         7 |        11 | 
##                         |     0.119 |     0.091 |           | 
##                         |     0.364 |     0.636 |     0.136 | 
##                         |     0.114 |     0.152 |           | 
##                         |     0.049 |     0.086 |           | 
## ------------------------|-----------|-----------|-----------|
##                       6 |         0 |         6 |         6 | 
##                         |     2.593 |     1.973 |           | 
##                         |     0.000 |     1.000 |     0.074 | 
##                         |     0.000 |     0.130 |           | 
##                         |     0.000 |     0.074 |           | 
## ------------------------|-----------|-----------|-----------|
##            Column Total |        35 |        46 |        81 | 
##                         |     0.432 |     0.568 |           | 
## ------------------------|-----------|-----------|-----------|
## 
##  
## Fisher's Exact Test for Count Data
## ------------------------------------------------------------
## Alternative hypothesis: two.sided
## p =  0.007648878 
## 
## 
comorbidities_hopc_df <- as.data.frame(n_comorbidities_hopc) %>%
  rename(n_comorbidities = Var1, hopc = 2)
comorbidities_hopc_df
n_comorbiditieshopcFreq
018
114
212
317
4110
514
610
021
124
228
324
4216
527
626
comorbidities_hopc_df_wide <- pivot_wider(
  data = comorbidities_hopc_df,
  names_from = hopc,
  values_from = Freq
) %>% 
  rename(c("Primary" = "1", "Secondary" = "2")) %>%
  mutate(Proportion_Secondary = Secondary / (Primary + Secondary))
comorbidities_hopc_df_wide
n_comorbiditiesPrimarySecondaryProportion_Secondary
0810.111
1440.5  
2280.8  
3740.364
410160.615
5470.636
6061    
highchart() %>% 
  hc_chart(type = "column") %>% 
  hc_title(text = "Co-morbidities and Secondary Gout") %>%
  hc_xAxis(title = list(text = "Number of co-morbidities")) %>%
  hc_yAxis(title = list(text = "n")) %>%
  hc_plotOptions(column = list(
    dataLabels = list(enabled = FALSE),
    stacking = "normal",
    enableMouseTracking = FALSE)
  ) %>% 
  hc_series(list(name = "Primary",
                 data = comorbidities_hopc_df_wide$Primary),
            list(name = "Secondary",
                 data = comorbidities_hopc_df_wide$Secondary)
  ) %>%
  hc_exporting(enabled = TRUE) # allow 'save'
highchart() %>% 
  hc_chart(type = "column") %>% 
  hc_title(text = "Co-morbidities and Secondary Gout") %>%
  hc_xAxis(title = list(text = "Number of co-morbidities")) %>%
  hc_yAxis_multiples(list(title = list(text = "n")),
                     list(title = list(text = "Proportion secondary"),
                          opposite = TRUE, min = 0, max = 1)
  ) %>%
  hc_plotOptions(column = list(
    dataLabels = list(enabled = FALSE),
    stacking = "normal",
    enableMouseTracking = FALSE)
  ) %>% 
  hc_series(list(name = "Primary",
                 data = comorbidities_hopc_df_wide$Primary,
                 yAxis = 0),
            list(name = "Secondary",
                 data = comorbidities_hopc_df_wide$Secondary,
                 yAxis = 0)
  ) %>%
  hc_add_series(name = "Secondary proportion",
                data = comorbidities_hopc_df_wide$Proportion_Secondary,
                type = "line", color = "red",
                yAxis = 1
  ) %>%
  hc_exporting(enabled = TRUE) # allow 'save'
hopc4 <- glm(
  hopc ~  x_total_comorbidities,
  data = d,
  family = "binomial"
)
summary(hopc4)
## 
## Call:
## glm(formula = hopc ~ x_total_comorbidities, family = "binomial", 
##     data = d)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -1.6184  -1.2776   0.6711   0.9302   1.5805  
## 
## Coefficients:
##                       Estimate Std. Error z value Pr(>|z|)   
## (Intercept)            -0.9111     0.4964  -1.835   0.0664 . 
## x_total_comorbidities   0.3812     0.1419   2.687   0.0072 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 110.79  on 80  degrees of freedom
## Residual deviance: 102.81  on 79  degrees of freedom
## AIC: 106.81
## 
## Number of Fisher Scoring iterations: 4

Change in ULT therapy vs. rheum_input

ULT_category_rheum <- d %>%
  mutate(ULT_change_category =
           case_when(
             ult_on_admission_y_n == 1 & change_dose == 0 & ceased_withheld == 0 ~ "On, no change",
             ult_on_admission_y_n == 1 & change_dose == 1 ~ "On and changed",
             ult_on_admission_y_n == 1 & ceased_withheld == 1 ~ "On and ceased",
             ult_on_admission_y_n == 0 & commenced_during == 0 & after_discharge == 0 ~ "None, not started",
             ult_on_admission_y_n == 0 & commenced_during == 1 ~ "None, started during admission",
             ult_on_admission_y_n == 0 & after_discharge == 1 ~ "None, started on discharge",
             TRUE ~ "Everything else"
           )) %>%
  mutate(ULT_change_category = factor(ULT_change_category)) %>%
  select(ULT_change_category, rheum_input)
summary(ULT_category_rheum)
##                      ULT_change_category rheum_input
##  None, not started             :28       0:64       
##  None, started during admission:12       1:17       
##  None, started on discharge    :15                  
##  On and ceased                 : 2                  
##  On and changed                : 3                  
##  On, no change                 :21
CrossTable(ULT_category_rheum$ULT_change_category, ULT_category_rheum$rheum_input, fisher = TRUE)
## 
##  
##    Cell Contents
## |-------------------------|
## |                       N |
## | Chi-square contribution |
## |           N / Row Total |
## |           N / Col Total |
## |         N / Table Total |
## |-------------------------|
## 
##  
## Total Observations in Table:  81 
## 
##  
##                                        | ULT_category_rheum$rheum_input 
## ULT_category_rheum$ULT_change_category |         0 |         1 | Row Total | 
## ---------------------------------------|-----------|-----------|-----------|
##                      None, not started |        21 |         7 |        28 | 
##                                        |     0.057 |     0.215 |           | 
##                                        |     0.750 |     0.250 |     0.346 | 
##                                        |     0.328 |     0.412 |           | 
##                                        |     0.259 |     0.086 |           | 
## ---------------------------------------|-----------|-----------|-----------|
##         None, started during admission |        10 |         2 |        12 | 
##                                        |     0.028 |     0.107 |           | 
##                                        |     0.833 |     0.167 |     0.148 | 
##                                        |     0.156 |     0.118 |           | 
##                                        |     0.123 |     0.025 |           | 
## ---------------------------------------|-----------|-----------|-----------|
##             None, started on discharge |        12 |         3 |        15 | 
##                                        |     0.002 |     0.007 |           | 
##                                        |     0.800 |     0.200 |     0.185 | 
##                                        |     0.188 |     0.176 |           | 
##                                        |     0.148 |     0.037 |           | 
## ---------------------------------------|-----------|-----------|-----------|
##                          On and ceased |         2 |         0 |         2 | 
##                                        |     0.111 |     0.420 |           | 
##                                        |     1.000 |     0.000 |     0.025 | 
##                                        |     0.031 |     0.000 |           | 
##                                        |     0.025 |     0.000 |           | 
## ---------------------------------------|-----------|-----------|-----------|
##                         On and changed |         0 |         3 |         3 | 
##                                        |     2.370 |     8.924 |           | 
##                                        |     0.000 |     1.000 |     0.037 | 
##                                        |     0.000 |     0.176 |           | 
##                                        |     0.000 |     0.037 |           | 
## ---------------------------------------|-----------|-----------|-----------|
##                          On, no change |        19 |         2 |        21 | 
##                                        |     0.349 |     1.315 |           | 
##                                        |     0.905 |     0.095 |     0.259 | 
##                                        |     0.297 |     0.118 |           | 
##                                        |     0.235 |     0.025 |           | 
## ---------------------------------------|-----------|-----------|-----------|
##                           Column Total |        64 |        17 |        81 | 
##                                        |     0.790 |     0.210 |           | 
## ---------------------------------------|-----------|-----------|-----------|
## 
##  
## Fisher's Exact Test for Count Data
## ------------------------------------------------------------
## Alternative hypothesis: two.sided
## p =  0.0435109 
## 
## 
ULT_category_rheum2 <- d %>%
  mutate(ULT_change_category =
           case_when(
             ult_on_admission_y_n == 1 & change_dose == 0 & ceased_withheld == 0 ~ "Indifferent",
             ult_on_admission_y_n == 1 & change_dose == 1 ~ "Good",
             ult_on_admission_y_n == 1 & ceased_withheld == 1 ~ "Bad",
             ult_on_admission_y_n == 0 & commenced_during == 0 & after_discharge == 0 ~ "Bad",
             ult_on_admission_y_n == 0 & commenced_during == 1 ~ "Good",
             ult_on_admission_y_n == 0 & after_discharge == 1 ~ "Good",
             TRUE ~ "Everything else"
           )) %>%
  mutate(ULT_change_category = factor(ULT_change_category)) %>%
  select(ULT_change_category, rheum_input)
summary(ULT_category_rheum2)
##   ULT_change_category rheum_input
##  Bad        :30       0:64       
##  Good       :30       1:17       
##  Indifferent:21
ULT_category_rheum2b <- ULT_category_rheum2 %>% filter(ULT_change_category != "Indifferent")
CrossTable(ULT_category_rheum2b$ULT_change_category, ULT_category_rheum2b$rheum_input, fisher = TRUE)
## 
##  
##    Cell Contents
## |-------------------------|
## |                       N |
## | Chi-square contribution |
## |           N / Row Total |
## |           N / Col Total |
## |         N / Table Total |
## |-------------------------|
## 
##  
## Total Observations in Table:  60 
## 
##  
##                                          | ULT_category_rheum2b$rheum_input 
## ULT_category_rheum2b$ULT_change_category |         0 |         1 | Row Total | 
## -----------------------------------------|-----------|-----------|-----------|
##                                      Bad |        23 |         7 |        30 | 
##                                          |     0.011 |     0.033 |           | 
##                                          |     0.767 |     0.233 |     0.500 | 
##                                          |     0.511 |     0.467 |           | 
##                                          |     0.383 |     0.117 |           | 
## -----------------------------------------|-----------|-----------|-----------|
##                                     Good |        22 |         8 |        30 | 
##                                          |     0.011 |     0.033 |           | 
##                                          |     0.733 |     0.267 |     0.500 | 
##                                          |     0.489 |     0.533 |           | 
##                                          |     0.367 |     0.133 |           | 
## -----------------------------------------|-----------|-----------|-----------|
##                             Column Total |        45 |        15 |        60 | 
##                                          |     0.750 |     0.250 |           | 
## -----------------------------------------|-----------|-----------|-----------|
## 
##  
## Fisher's Exact Test for Count Data
## ------------------------------------------------------------
## Sample estimate odds ratio:  1.191262 
## 
## Alternative hypothesis: true odds ratio is not equal to 1
## p =  1 
## 95% confidence interval:  0.3159736 4.590214 
## 
## Alternative hypothesis: true odds ratio is less than 1
## p =  0.7239983 
## 95% confidence interval:  0 3.775563 
## 
## Alternative hypothesis: true odds ratio is greater than 1
## p =  0.5 
## 95% confidence interval:  0.3815898 Inf 
## 
## 
##