Package: blorr 0.3.1
blorr: Tools for Developing Binary Logistic Regression Models
Tools designed to make it easier for beginner and intermediate users to build and validate binary logistic regression models. Includes bivariate analysis, comprehensive regression output, model fit statistics, variable selection procedures, model validation techniques and a 'shiny' app for interactive model building.
Authors:
blorr_0.3.1.tar.gz
blorr_0.3.1.tar.gz(r-4.5-noble)blorr_0.3.1.tar.gz(r-4.4-noble)
blorr_0.3.1.tgz(r-4.4-emscripten)blorr_0.3.1.tgz(r-4.3-emscripten)
blorr.pdf |blorr.html✨
blorr/json (API)
NEWS
# Install 'blorr' in R: |
install.packages('blorr', repos = 'https://cloud.r-project.org') |
Bug tracker:https://github.com/rsquaredacademy/blorr/issues7 issues
Pkgdown site:https://blorr.rsquaredacademy.com
- bank_marketing - Bank marketing data set
- hsb2 - High School and Beyond Data Set
- stepwise - Dummy Data Set
Last updated 5 months agofrom:dc207793f4. Checks:3 OK. Indexed: no.
Target | Result | Latest binary |
---|---|---|
Doc / Vignettes | OK | Mar 13 2025 |
R-4.5-linux-x86_64 | OK | Mar 13 2025 |
R-4.4-linux-x86_64 | OK | Mar 13 2025 |
Exports:blr_bivariate_analysisblr_coll_diagblr_confusion_matrixblr_decile_capture_rateblr_decile_lift_chartblr_eigen_cindexblr_gains_tableblr_gini_indexblr_ks_chartblr_launch_appblr_linktestblr_lorenz_curveblr_model_fit_statsblr_multi_model_fit_statsblr_pairsblr_plot_c_fittedblr_plot_c_leverageblr_plot_deviance_fittedblr_plot_deviance_residualblr_plot_dfbetas_panelblr_plot_diag_cblr_plot_diag_cbarblr_plot_diag_difchisqblr_plot_diag_difdevblr_plot_diag_fitblr_plot_diag_influenceblr_plot_diag_leverageblr_plot_difchisq_fittedblr_plot_difchisq_leverageblr_plot_difdev_fittedblr_plot_difdev_leverageblr_plot_fitted_leverageblr_plot_leverageblr_plot_leverage_fittedblr_plot_pearson_residualblr_plot_residual_fittedblr_prep_dcrate_datablr_prep_ksannotate_xblr_prep_ksannotate_yblr_prep_kschart_datablr_prep_kschart_lineblr_prep_kschart_statblr_prep_lchart_datablr_prep_lchart_gmeanblr_prep_lorenz_datablr_prep_roc_datablr_regressblr_residual_diagnosticsblr_roc_curveblr_rsq_adj_countblr_rsq_countblr_rsq_cox_snellblr_rsq_effronblr_rsq_mcfaddenblr_rsq_mcfadden_adjblr_rsq_mckelvey_zavoinablr_rsq_nagelkerkeblr_segmentblr_segment_distblr_segment_twowayblr_step_aic_backwardblr_step_aic_bothblr_step_aic_forwardblr_step_p_backwardblr_step_p_bothblr_step_p_forwardblr_test_hosmer_lemeshowblr_test_lrblr_vif_tolblr_woe_ivblr_woe_iv_stats
Dependencies:abindbackportsbootbroomcarcarDataclicolorspacecowplotcpp11data.tableDerivdoBydplyrfansifarverFormulagenericsggplot2gluegridExtragtableisobandlabelinglatticelifecyclelme4magrittrMASSMatrixMatrixModelsmgcvmicrobenchmarkminqamodelrmunsellnlmenloptrnnetnumDerivpbkrtestpillarpkgconfigpurrrquantregR6rbibutilsRColorBrewerRcppRcppEigenRdpackreformulasrlangscalesSparseMstringistringrsurvivaltibbletidyrtidyselectutf8vctrsviridisLitewithr
Citation
To cite package ‘blorr’ in publications use:
Hebbali A (2024). blorr: Tools for Developing Binary Logistic Regression Models. R package version 0.3.1, https://CRAN.R-project.org/package=blorr.
Corresponding BibTeX entry:
@Manual{, title = {blorr: Tools for Developing Binary Logistic Regression Models}, author = {Aravind Hebbali}, year = {2024}, note = {R package version 0.3.1}, url = {https://CRAN.R-project.org/package=blorr}, }
Readme and manuals
blorr
Tools for building binary logistic regression models
Overview
Tools designed to make it easier for users, particularly beginner/intermediate R users to build logistic regression models. Includes comprehensive regression output, variable selection procedures, model validation techniques and a ‘shiny’ app for interactive model building.
Installation
# Install blorr from CRAN
install.packages("blorr")
# Install development version from GitHub
# install.packages("devtools")
devtools::install_github("rsquaredacademy/blorr")
# Install the development version from `rsquaredacademy` universe
install.packages("blorr", repos = "https://rsquaredacademy.r-universe.dev")
Articles
Usage
blorr uses consistent prefix blr_*
for easy tab completion.
library(blorr)
library(magrittr)
Bivariate Analysis
blr_bivariate_analysis(hsb2, honcomp, female, prog, race, schtyp)
#> Bivariate Analysis
#> ---------------------------------------------------------------------
#> Variable Information Value LR Chi Square LR DF LR p-value
#> ---------------------------------------------------------------------
#> female 0.10 3.9350 1 0.0473
#> prog 0.43 16.1450 2 3e-04
#> race 0.33 11.3694 3 0.0099
#> schtyp 0.00 0.0445 1 0.8330
#> ---------------------------------------------------------------------
Weight of Evidence & Information Value
blr_woe_iv(hsb2, prog, honcomp)
#> Weight of Evidence
#> -------------------------------------------------------------------------
#> levels count_0s count_1s dist_0s dist_1s woe iv
#> -------------------------------------------------------------------------
#> 1 38 7 0.26 0.13 0.67 0.08
#> 2 65 40 0.44 0.75 -0.53 0.17
#> 3 44 6 0.30 0.11 0.97 0.18
#> -------------------------------------------------------------------------
#>
#> Information Value
#> -----------------------------
#> Variable Information Value
#> -----------------------------
#> prog 0.4329
#> -----------------------------
Model
# create model using glm
model <- glm(honcomp ~ female + read + science, data = hsb2,
family = binomial(link = 'logit'))
Regression Output
blr_regress(model)
#> Model Overview
#> ------------------------------------------------------------------------
#> Data Set Resp Var Obs. Df. Model Df. Residual Convergence
#> ------------------------------------------------------------------------
#> data honcomp 200 199 196 TRUE
#> ------------------------------------------------------------------------
#>
#> Response Summary
#> --------------------------------------------------------
#> Outcome Frequency Outcome Frequency
#> --------------------------------------------------------
#> 0 147 1 53
#> --------------------------------------------------------
#>
#> Maximum Likelihood Estimates
#> -----------------------------------------------------------------
#> Parameter DF Estimate Std. Error z value Pr(>|z|)
#> -----------------------------------------------------------------
#> (Intercept) 1 -12.7772 1.9755 -6.4677 0.0000
#> female1 1 1.4825 0.4474 3.3139 9e-04
#> read 1 0.1035 0.0258 4.0186 1e-04
#> science 1 0.0948 0.0305 3.1129 0.0019
#> -----------------------------------------------------------------
#>
#> Association of Predicted Probabilities and Observed Responses
#> ---------------------------------------------------------------
#> % Concordant 0.8561 Somers' D 0.7147
#> % Discordant 0.1425 Gamma 0.7136
#> % Tied 0.0014 Tau-a 0.2794
#> Pairs 7791 c 0.8568
#> ---------------------------------------------------------------
Model Fit Statistics
blr_model_fit_stats(model)
#> Model Fit Statistics
#> ---------------------------------------------------------------------------------
#> Log-Lik Intercept Only: -115.644 Log-Lik Full Model: -80.118
#> Deviance(196): 160.236 LR(3): 71.052
#> Prob > LR: 0.000
#> MCFadden's R2 0.307 McFadden's Adj R2: 0.273
#> ML (Cox-Snell) R2: 0.299 Cragg-Uhler(Nagelkerke) R2: 0.436
#> McKelvey & Zavoina's R2: 0.518 Efron's R2: 0.330
#> Count R2: 0.810 Adj Count R2: 0.283
#> BIC: 181.430 AIC: 168.236
#> ---------------------------------------------------------------------------------
Confusion Matrix
blr_confusion_matrix(model)
#> Confusion Matrix and Statistics
#>
#> Reference
#> Prediction 0 1
#> 0 135 26
#> 1 12 27
#>
#>
#> Accuracy : 0.8100
#> No Information Rate : 0.7350
#>
#> Kappa : 0.4673
#>
#> McNemars's Test P-Value : 0.0350
#>
#> Sensitivity : 0.5094
#> Specificity : 0.9184
#> Pos Pred Value : 0.6923
#> Neg Pred Value : 0.8385
#> Prevalence : 0.2650
#> Detection Rate : 0.1350
#> Detection Prevalence : 0.1950
#> Balanced Accuracy : 0.7139
#> Precision : 0.6923
#> Recall : 0.5094
#>
#> 'Positive' Class : 1
Hosmer Lemeshow Test
blr_test_hosmer_lemeshow(model)
#> Partition for the Hosmer & Lemeshow Test
#> --------------------------------------------------------------
#> def = 1 def = 0
#> Group Total Observed Expected Observed Expected
#> --------------------------------------------------------------
#> 1 20 0 0.16 20 19.84
#> 2 20 0 0.53 20 19.47
#> 3 20 2 0.99 18 19.01
#> 4 20 1 1.64 19 18.36
#> 5 21 3 2.72 18 18.28
#> 6 19 3 4.05 16 14.95
#> 7 20 7 6.50 13 13.50
#> 8 20 10 8.90 10 11.10
#> 9 20 13 11.49 7 8.51
#> 10 20 14 16.02 6 3.98
#> --------------------------------------------------------------
#>
#> Goodness of Fit Test
#> ------------------------------
#> Chi-Square DF Pr > ChiSq
#> ------------------------------
#> 4.4998 8 0.8095
#> ------------------------------
Gains Table
blr_gains_table(model)
#> decile total 1 0 ks tp tn fp fn sensitivity specificity accuracy
#> 1 1 20 14 6 22.33346 14 141 6 39 26.41509 95.91837 77.5
#> 2 2 20 13 7 42.09986 27 134 13 26 50.94340 91.15646 80.5
#> 3 3 20 10 10 54.16506 37 124 23 16 69.81132 84.35374 80.5
#> 4 4 20 7 13 58.52907 44 111 36 9 83.01887 75.51020 77.5
#> 5 5 20 3 17 52.62482 47 94 53 6 88.67925 63.94558 70.5
#> 6 6 20 3 17 46.72058 50 77 70 3 94.33962 52.38095 63.5
#> 7 7 20 1 19 35.68220 51 58 89 2 96.22642 39.45578 54.5
#> 8 8 20 2 18 27.21088 53 40 107 0 100.00000 27.21088 46.5
#> 9 9 20 0 20 13.60544 53 20 127 0 100.00000 13.60544 36.5
#> 10 10 20 0 20 0.00000 53 0 147 0 100.00000 0.00000 26.5
Lift Chart
model %>%
blr_gains_table() %>%
plot()
ROC Curve
model %>%
blr_gains_table() %>%
blr_roc_curve()
KS Chart
model %>%
blr_gains_table() %>%
blr_ks_chart()
Lorenz Curve
blr_lorenz_curve(model)
Getting Help
If you encounter a bug, please file a minimal reproducible example using reprex on github. For questions and clarifications, use StackOverflow.
Help Manual
Help page | Topics |
---|---|
Bank marketing data set | bank_marketing |
Bivariate analysis | blr_bivariate_analysis blr_bivariate_analysis.default |
Collinearity diagnostics | blr_coll_diag blr_eigen_cindex blr_vif_tol |
Confusion matrix | blr_confusion_matrix blr_confusion_matrix.default |
Event rate by decile | blr_decile_capture_rate |
Decile lift chart | blr_decile_lift_chart |
Gains table & lift chart | blr_gains_table plot.blr_gains_table |
Gini index | blr_gini_index |
KS chart | blr_ks_chart |
Launch shiny app | blr_launch_app |
Model specification error | blr_linktest |
Lorenz curve | blr_lorenz_curve |
Model fit statistics | blr_model_fit_stats |
Multi model fit statistics | blr_multi_model_fit_stats blr_multi_model_fit_stats.default |
Concordant & discordant pairs | blr_pairs |
CI Displacement C vs fitted values plot | blr_plot_c_fitted |
CI Displacement C vs leverage plot | blr_plot_c_leverage |
Deviance vs fitted values plot | blr_plot_deviance_fitted |
Deviance residual values | blr_plot_deviance_residual |
DFBETAs panel | blr_plot_dfbetas_panel |
CI Displacement C plot | blr_plot_diag_c |
CI Displacement CBAR plot | blr_plot_diag_cbar |
Delta chisquare plot | blr_plot_diag_difchisq |
Delta deviance plot | blr_plot_diag_difdev |
Fitted values diagnostics plot | blr_plot_diag_fit |
Influence diagnostics plot | blr_plot_diag_influence |
Leverage diagnostics plot | blr_plot_diag_leverage |
Delta chi square vs fitted values plot | blr_plot_difchisq_fitted |
Delta chi square vs leverage plot | blr_plot_difchisq_leverage |
Delta deviance vs fitted values plot | blr_plot_difdev_fitted |
Delta deviance vs leverage plot | blr_plot_difdev_leverage |
Fitted values vs leverage plot | blr_plot_fitted_leverage |
Leverage plot | blr_plot_leverage |
Leverage vs fitted values plot | blr_plot_leverage_fitted |
Residual values plot | blr_plot_pearson_residual |
Residual vs fitted values plot | blr_plot_residual_fitted |
Decile capture rate data | blr_prep_dcrate_data |
KS Chart data | blr_prep_ksannotate_x blr_prep_ksannotate_y blr_prep_kschart_data blr_prep_kschart_line blr_prep_kschart_stat |
Lift Chart data | blr_prep_lchart_data blr_prep_lchart_gmean |
Lorenz curve data | blr_prep_lorenz_data |
ROC curve data | blr_prep_roc_data |
Binary logistic regression | blr_regress blr_regress.glm |
Residual diagnostics | blr_residual_diagnostics |
ROC curve | blr_roc_curve |
Adjusted count R2 | blr_rsq_adj_count |
Count R2 | blr_rsq_count |
Cox Snell R2 | blr_rsq_cox_snell |
Effron R2 | blr_rsq_effron |
McFadden's R2 | blr_rsq_mcfadden |
McFadden's adjusted R2 | blr_rsq_mcfadden_adj |
McKelvey Zavoina R2 | blr_rsq_mckelvey_zavoina |
Cragg-Uhler (Nagelkerke) R2 | blr_rsq_nagelkerke |
Event rate | blr_segment blr_segment.default |
Response distribution | blr_segment_dist plot.blr_segment_dist |
Two way event rate | blr_segment_twoway blr_segment_twoway.default |
Stepwise AIC backward elimination | blr_step_aic_backward blr_step_aic_backward.default plot.blr_step_aic_backward |
Stepwise AIC selection | blr_step_aic_both plot.blr_step_aic_both |
Stepwise AIC forward selection | blr_step_aic_forward blr_step_aic_forward.default plot.blr_step_aic_forward |
Stepwise backward regression | blr_step_p_backward blr_step_p_backward.default plot.blr_step_p_backward |
Stepwise regression | blr_step_p_both blr_step_p_both.default plot.blr_step_p_both |
Stepwise forward regression | blr_step_p_forward blr_step_p_forward.default plot.blr_step_p_forward |
Hosmer lemeshow test | blr_test_hosmer_lemeshow |
Likelihood ratio test | blr_test_lr blr_test_lr.default |
WoE & IV | blr_woe_iv plot.blr_woe_iv |
Multi variable WOE & IV | blr_woe_iv_stats |
High School and Beyond Data Set | hsb2 |
Dummy Data Set | stepwise |