Bayesian Model

brms Package

  • The function to report brms model needs to be modified to reflect the logistic model
library(brms)
library(bayestestR)
library(sjstats)

m <- brm(formula = outcome ~ var1 + var2 + var3 + var4 + var5 + var6 + var7,  
                   data = dt, 
                   family = bernoulli(link = "logit"),
                   warmup = 500, 
                   iter = 2000, 
                   chains = 2, 
                   inits = "0", 
                   cores = 2,
                   seed = 123)



report_brms <- function(obj, digits=2, equiv=0.1){
    pe <- unique(point_estimate(obj))
    colnames(pe) <- tolower(colnames(pe))
    pe <- pe[, -1]
    he <- unique(hdi(obj, ci=0.89))
    colnames(he) <- paste0("hdi_", tolower(colnames(he)))
    et <- unique(eti(obj, ci=0.95))
    colnames(et) <- paste0("eti_", tolower(colnames(et)))
    pd <- unique(pd(obj))
    colnames(pd) <- tolower(colnames(pd))
    pd <- pd[, 1:2]
    rtn <- cbind(pe, he, et, pd)
    rtn <- as.data.table(rtn)
    rtn$equivalence_l <- -equiv
    rtn$equivalence_r <- equiv
    rtn <- as.data.table(rtn)
    rtn <- rtn[, hdi := paste0(
                     as.character(round(median, digits))
                   , " ["
                   , as.character(round(hdi_ci_low, digits))
                   , ", "
                   , as.character(round(hdi_ci_high, digits))
                   , "]"
                 )]
    rtn <- rtn[, eti := paste0(
                     as.character(round(mean, digits))
                   , "["
                   , as.character(round(eti_ci_low, digits))
                   , ", "
                   , as.character(round(eti_ci_high, digits))
                   , "]"
                 )]
    rtn <- rtn[, pd_n := pd][, pd := Wu::percent(pd, digits=digits)]
    for(i in 1:nrow(rtn)){
        rp <- equivalence_test(
            obj
          , range = as.numeric(rtn[i, list(equivalence_l, equivalence_r)])
          , ci=0.89
          , parameters=rtn$parameter[i])
        rtn$rope_n[i] <- rp$ROPE_Percentage
        rtn$rope[i] <- Wu::percent(rp$ROPE_Percentage, digits=digits)
    }
    label(rtn$parameter) <- "Parameter"
    label(rtn$hdi) <- "Median [89% HDI]"
    label(rtn$eti) <- "Mean [95% ETI]"
    label(rtn$pd) <- "Probability of Direction"
    label(rtn$rope) <- "ROPE"
    invisible(rtn)
}

t <- report_brms(m, digits=2, equiv = 0.06)
t2 <- t[-1, ]


t2[, list(parameter, hdi, eti, pd, rope)] %>%
    prt(col.names=c("Parameter", "Median [89% HDI]", "Mean [95% ETI]", "Probability of Direction", "ROPE")) %>%
    footnote(symbol=c("HDI: High Density Credible Interval"
                      , "ETI: Equal-Tailed Credible Interval")
        , number=c(
                 "Probability of Direction (pd) describes effect existence. It represents the certainty associated with the most probable direction (positive or negative) of the effect."
                 , "pd <= 95%: uncertain"
                 , "pd > 95%: possibly existing"
                 , "pd > 97%: likely existing"
                 , "pd > 99%: probably existing"
                 , "pd > 99.9%: certainly existing"
          )
        , alphabet=c("ROPE: Region of Practical Equivalence with range $[-0.1*SD_{Y},0.1*SD_Y]$"
              , "> 99%: negligible (we can accept the null hypothesis)"
              , "> 97.5%: probably negligible"
              , "<= 97.5% & >= 2.5%: undecided significance"
              , "< 2.5%: probably significant"
              , "< 1%: significant (we can reject the null hypothesis)"
          )
             )
Parameter Median [89% HDI] Mean [95% ETI] Probability of Direction ROPE
b_var1 0.04 [-0.22, 0.35] 0.04[-0.32, 0.4] 59.73% 30.22%
b_var2 0.43 [0.18, 0.69] 0.42[0.11, 0.74] 99.57% 0.00%
b_var3 0.41 [0.13, 0.72] 0.41[0.05, 0.78] 98.47% 0.00%
b_var4 0.52 [0.23, 0.75] 0.52[0.19, 0.84] 99.87% 0.00%
b_var5 0.44 [0.18, 0.71] 0.44[0.12, 0.77] 99.63% 0.00%
b_var6 0.66 [0.42, 0.92] 0.67[0.36, 0.98] 100.00% 0.00%
b_var7 1.63 [1.21, 2.01] 1.63[1.15, 2.12] 100.00% 0.00%
1 Probability of Direction (pd) describes effect existence. It represents the certainty associated with the most probable direction (positive or negative) of the effect.
2 pd <= 95%: uncertain
3 pd > 95%: possibly existing
4 pd > 97%: likely existing
5 pd > 99%: probably existing
6 pd > 99.9%: certainly existing
a ROPE: Region of Practical Equivalence with range \([-0.1*SD_{Y},0.1*SD_Y]\)
b > 99%: negligible (we can accept the null hypothesis)
c > 97.5%: probably negligible
d <= 97.5% & >= 2.5%: undecided significance
e < 2.5%: probably significant
f < 1%: significant (we can reject the null hypothesis)
* HDI: High Density Credible Interval
ETI: Equal-Tailed Credible Interval

rmsb Package

  • Multiple imputation
Multivariable Model
Variable Odds Ratio (HDI) Probability > 1
var1 1.04 (0.74, 1.47) 0.5840
var2 1.52 (1.12, 2.09) 0.9956
var3 1.50 (1.01, 2.27) 0.9737
var4 1.67 (1.21, 2.33) 0.9988
var5 1.55 (1.13, 2.14) 0.9967
var6 1.95 (1.44, 2.68) 1.0000
var7 5.09 (3.20, 8.11) 1.0000

R sessionInfo

R version 4.2.0 (2022-04-22) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 20.04.3 LTS

Matrix products: default BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0 LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.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

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] rmsb_0.1.0 rms_6.3-0 SparseM_1.81
[4] Hmisc_4.7-0 Formula_1.2-4 survival_3.2-13
[7] lattice_0.20-45 sjstats_0.18.1 bayestestR_0.12.1
[10] brms_2.17.0 Rcpp_1.0.9 Wu_0.0.0.9000
[13] flexdashboard_0.5.2 lme4_1.1-29 Matrix_1.4-0
[16] mgcv_1.8-38 nlme_3.1-152 png_0.1-7
[19] scales_1.2.0 nnet_7.3-16 labelled_2.9.1
[22] kableExtra_1.3.4 plotly_4.10.0 gridExtra_2.3
[25] ggplot2_3.3.6 DT_0.23 tableone_0.13.2
[28] magrittr_2.0.3 lubridate_1.8.0 dplyr_1.0.9
[31] plyr_1.8.7 data.table_1.14.2 rmdformats_1.0.4
[34] knitr_1.39

loaded via a namespace (and not attached): [1] backports_1.4.1 systemfonts_1.0.4 igraph_1.3.4
[4] lazyeval_0.2.2 splines_4.2.0 crosstalk_1.2.0
[7] TH.data_1.1-1 rstantools_2.2.0 inline_0.3.19
[10] digest_0.6.29 htmltools_0.5.3 fansi_1.0.3
[13] checkmate_2.1.0 cluster_2.1.2 modelr_0.1.8
[16] RcppParallel_5.1.5 matrixStats_0.62.0 sandwich_3.0-2
[19] xts_0.12.1 svglite_2.1.0 prettyunits_1.1.1
[22] jpeg_0.1-9 colorspace_2.0-3 rvest_1.0.2
[25] mitools_2.4 haven_2.5.0 xfun_0.31
[28] callr_3.7.0 crayon_1.5.1 jsonlite_1.8.0
[31] zoo_1.8-10 glue_1.6.2 gtable_0.3.0
[34] emmeans_1.7.5 MatrixModels_0.5-0 webshot_0.5.3
[37] sjmisc_2.8.9 distributional_0.3.0 pkgbuild_1.3.0
[40] rstan_2.21.5 abind_1.4-5 mvtnorm_1.1-3
[43] DBI_1.1.2 miniUI_0.1.1.1 htmlTable_2.4.0
[46] performance_0.9.1 viridisLite_0.4.0 xtable_1.8-4
[49] klippy_0.0.0.9500 foreign_0.8-81 stats4_4.2.0
[52] StanHeaders_2.21.0-7 survey_4.1-1 datawizard_0.4.1
[55] htmlwidgets_1.5.4 httr_1.4.3 threejs_0.3.3
[58] RColorBrewer_1.1-3 posterior_1.2.2 ellipsis_0.3.2
[61] pkgconfig_2.0.3 loo_2.5.1 farver_2.1.1
[64] sass_0.4.1 utf8_1.2.2 effectsize_0.7.0
[67] tidyselect_1.1.2 rlang_1.0.4 reshape2_1.4.4
[70] later_1.3.0 munsell_0.5.0 tools_4.2.0
[73] cli_3.3.0 generics_0.1.3 sjlabelled_1.2.0
[76] broom_0.8.0 ggridges_0.5.3 evaluate_0.15
[79] stringr_1.4.0 fastmap_1.1.0 yaml_2.3.5
[82] processx_3.6.0 purrr_0.3.4 quantreg_5.93
[85] mime_0.12 xml2_1.3.3 compiler_4.2.0
[88] bayesplot_1.9.0 shinythemes_1.2.0 rstudioapi_0.13
[91] tibble_3.1.8 bslib_0.3.1 stringi_1.7.8
[94] highr_0.9 parameters_0.18.1 ps_1.7.0
[97] Brobdingnag_1.2-7 forcats_0.5.1 nloptr_2.0.3
[100] markdown_1.1 shinyjs_2.1.0 tensorA_0.36.2
[103] vctrs_0.4.1 pillar_1.8.0 lifecycle_1.0.1
[106] jquerylib_0.1.4 bridgesampling_1.1-2 estimability_1.4
[109] insight_0.18.0 httpuv_1.6.5 latticeExtra_0.6-29 [112] R6_2.5.1 bookdown_0.27 promises_1.2.0.1
[115] codetools_0.2-18 polspline_1.1.20 boot_1.3-28
[118] colourpicker_1.1.1 MASS_7.3-54 gtools_3.9.2.2
[121] assertthat_0.2.1 withr_2.5.0 shinystan_2.6.0
[124] multcomp_1.4-19 parallel_4.2.0 hms_1.1.1
[127] rpart_4.1-15 grid_4.2.0 tidyr_1.2.0
[130] coda_0.19-4 minqa_1.2.4 rmarkdown_2.14
[133] shiny_1.7.1 base64enc_0.1-3 dygraphs_1.1.1.6