10 Logistic Regression

Learning objectives:

  • Gain a deeper understanding of logistic regression
  • Show existence and uniqueness of optimal solution
  • Motivate and perform robust logistic regression
  • Motivate and perform Bayesian logistic regression
  • Motivate and perform probit regression
library("bayesplot")
library("broom.mixed")
library("dplyr")
library("janitor")
library("ggplot2")
library("ggtext")
library("robust")
library("rstanarm")
library("palmerpenguins")
Session Info
sessionInfo()
## R version 4.4.0 (2024-04-24)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 22.04.4 LTS
## 
## Matrix products: default
## BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so;  LAPACK version 3.10.0
## 
## locale:
##  [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8       
##  [4] LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8   
##  [7] LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C          
## [10] LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   
## 
## time zone: UTC
## tzcode source: system (glibc)
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
##  [1] palmerpenguins_0.1.1 rstanarm_2.32.1      Rcpp_1.0.12         
##  [4] robust_0.7-4         fit.models_0.64      broom.mixed_0.2.9.5 
##  [7] bayesplot_1.11.1     tidyr_1.3.1          patchwork_1.2.0     
## [10] magrittr_2.0.3       janitor_2.2.0        gt_0.10.1           
## [13] ggtext_0.1.2         ggplot2_3.5.1        e1071_1.7-14        
## [16] dplyr_1.1.4          bayesrules_0.0.2    
## 
## loaded via a namespace (and not attached):
##   [1] tensorA_0.36.2.1     jsonlite_1.8.8       farver_2.1.2        
##   [4] nloptr_2.0.3         rmarkdown_2.27       vctrs_0.6.5         
##   [7] minqa_1.2.7          base64enc_0.1-3      htmltools_0.5.8.1   
##  [10] forcats_1.0.0        distributional_0.4.0 curl_5.2.1          
##  [13] broom_1.0.6          sass_0.4.9           parallelly_1.37.1   
##  [16] StanHeaders_2.32.9   bslib_0.7.0          htmlwidgets_1.6.4   
##  [19] plyr_1.8.9           zoo_1.8-12           lubridate_1.9.3     
##  [22] cachem_1.1.0         commonmark_1.9.1     igraph_2.0.3        
##  [25] mime_0.12            lifecycle_1.0.4      pkgconfig_2.0.3     
##  [28] colourpicker_1.3.0   Matrix_1.7-0         R6_2.5.1            
##  [31] fastmap_1.2.0        future_1.33.2        shiny_1.8.1.1       
##  [34] snakecase_0.11.1     digest_0.6.35        colorspace_2.1-0    
##  [37] furrr_0.3.1          crosstalk_1.2.1      labeling_0.4.3      
##  [40] fansi_1.0.6          timechange_0.3.0     abind_1.4-5         
##  [43] compiler_4.4.0       proxy_0.4-27         withr_3.0.0         
##  [46] backports_1.5.0      inline_0.3.19        shinystan_2.6.0     
##  [49] QuickJSR_1.2.0       pkgbuild_1.4.4       highr_0.11          
##  [52] MASS_7.3-60.2        gtools_3.9.5         loo_2.7.0           
##  [55] tools_4.4.0          rrcov_1.7-5          httpuv_1.6.15       
##  [58] threejs_0.3.3        glue_1.7.0           nlme_3.1-164        
##  [61] promises_1.3.0       gridtext_0.1.5       grid_4.4.0          
##  [64] checkmate_2.3.1      reshape2_1.4.4       generics_0.1.3      
##  [67] gtable_0.3.5         class_7.3-22         xml2_1.3.6          
##  [70] utf8_1.2.4           pillar_1.9.0         markdown_1.12       
##  [73] stringr_1.5.1        posterior_1.5.0      later_1.3.2         
##  [76] robustbase_0.99-2    splines_4.4.0        lattice_0.22-6      
##  [79] survival_3.5-8       tidyselect_1.2.1     miniUI_0.1.1.1      
##  [82] knitr_1.47           gridExtra_2.3        V8_4.4.2            
##  [85] bookdown_0.39        groupdata2_2.0.3     stats4_4.4.0        
##  [88] xfun_0.44            matrixStats_1.3.0    DEoptimR_1.1-3      
##  [91] DT_0.33              rstan_2.32.6         stringi_1.8.4       
##  [94] yaml_2.3.8           boot_1.3-30          evaluate_0.23       
##  [97] codetools_0.2-20     tibble_3.2.1         cli_3.6.2           
## [100] RcppParallel_5.1.7   shinythemes_1.2.0    xtable_1.8-4        
## [103] munsell_0.5.1        jquerylib_0.1.4      globals_0.16.3      
## [106] parallel_4.4.0       rstantools_2.4.0     dygraphs_1.1.1.6    
## [109] lme4_1.1-35.3        listenv_0.9.1        mvtnorm_1.2-5       
## [112] scales_1.3.0         xts_0.13.2           pcaPP_2.0-4         
## [115] purrr_1.0.2          rlang_1.1.3          shinyjs_2.1.0