| Title: | Odds Ratio Tools for Logistic Regression |
|---|---|
| Description: | Produces odds ratio analyses with comprehensive reporting tools. Generates plots, summary tables, and diagnostic checks for logistic regression models fitted with 'glm()' using binomial family. Provides visualisation methods, formatted reporting tables via 'gt', and tools to assess logistic regression model assumptions. |
| Authors: | Craig Parylo [aut, cre, cph] (ORCID: <https://orcid.org/0000-0003-4297-7808>) |
| Maintainer: | Craig Parylo <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.0.0 |
| Built: | 2026-05-21 09:21:58 UTC |
| Source: | https://github.com/craig-parylo/plotor |
Performs a series of tests to ensure that assumptions for logistic regression are met, with optional detailed feedback if any tests fail.
check_or(glm_model_results, confint_fast_estimate = FALSE, details = TRUE)check_or(glm_model_results, confint_fast_estimate = FALSE, details = TRUE)
glm_model_results |
Results from a binomial Generalised Linear Model (GLM), as produced by |
confint_fast_estimate |
Boolean (default = |
details |
Boolean (default = |
Logical, TRUE if all assumption tests pass, FALSE if one or more tests fail
# Load the Titanic dataset df <- datasets::Titanic |> dplyr::as_tibble() |> # convert aggregated counts to individual observations dplyr::filter(n > 0) |> tidyr::uncount(weights = n) |> # convert character variables to factors dplyr::mutate(dplyr::across(dplyr::where(is.character), as.factor)) # Perform logistic regression using `glm` lr <- stats::glm( data = df, family = binomial, formula = Survived ~ Class + Sex + Age ) # Check the model for logistic regression assumption violations check_or(lr)# Load the Titanic dataset df <- datasets::Titanic |> dplyr::as_tibble() |> # convert aggregated counts to individual observations dplyr::filter(n > 0) |> tidyr::uncount(weights = n) |> # convert character variables to factors dplyr::mutate(dplyr::across(dplyr::where(is.character), as.factor)) # Perform logistic regression using `glm` lr <- stats::glm( data = df, family = binomial, formula = Survived ~ Class + Sex + Age ) # Check the model for logistic regression assumption violations check_or(lr)
Produces an Odds Ratio plot to visualise the results of a logistic regression analysis.
plot_or( glm_model_results, conf_level = 0.95, confint_fast_estimate = FALSE, assumption_checks = TRUE )plot_or( glm_model_results, conf_level = 0.95, confint_fast_estimate = FALSE, assumption_checks = TRUE )
glm_model_results |
Results from a binomial Generalised Linear Model (GLM), as produced by |
conf_level |
Numeric value between 0.001 and 0.999 (default = 0.95) specifying the confidence level for the confidence interval. |
confint_fast_estimate |
Boolean (default = |
assumption_checks |
Boolean (default = |
The function returns an object of class gg and ggplot, which can be
customised and extended using various ggplot2 functions.
See vignette('using_plotor', package = 'plotor') for more details on usage.
More details and examples can be found on the website: https://craig-parylo.github.io/plotor/index.html
# Load required libraries library(plotor) library(datasets) library(dplyr) library(ggplot2) library(stats) library(forcats) library(tidyr) # Load the Titanic dataset df <- datasets::Titanic |> as_tibble() |> # convert aggregated counts to individual observations filter(n > 0) |> uncount(weights = n) |> # convert character variables to factors mutate(across(where(is.character), as.factor)) # Perform logistic regression using `glm` lr <- glm( data = df, family = 'binomial', formula = Survived ~ Class + Sex + Age ) # Produce the Odds Ratio plot plot_or(lr)# Load required libraries library(plotor) library(datasets) library(dplyr) library(ggplot2) library(stats) library(forcats) library(tidyr) # Load the Titanic dataset df <- datasets::Titanic |> as_tibble() |> # convert aggregated counts to individual observations filter(n > 0) |> uncount(weights = n) |> # convert character variables to factors mutate(across(where(is.character), as.factor)) # Perform logistic regression using `glm` lr <- glm( data = df, family = 'binomial', formula = Survived ~ Class + Sex + Age ) # Produce the Odds Ratio plot plot_or(lr)
Produces a formatted table displaying the outputs from the Odds Ratio analysis, including details on covariate characteristics and model results.
table_or( glm_model_results, conf_level = 0.95, output = c("tibble", "gt"), output_type = c("multivariable", "uni_and_multi"), confint_fast_estimate = FALSE, assumption_checks = TRUE, anonymise_counts = FALSE, use_model_data_only = TRUE )table_or( glm_model_results, conf_level = 0.95, output = c("tibble", "gt"), output_type = c("multivariable", "uni_and_multi"), confint_fast_estimate = FALSE, assumption_checks = TRUE, anonymise_counts = FALSE, use_model_data_only = TRUE )
glm_model_results |
Results from a binomial Generalised Linear Model (GLM), as produced by |
conf_level |
Numeric value between 0.001 and 0.999 (default = 0.95) specifying the confidence level for the confidence interval. |
output |
String describing the output type (default = "tibble"). Options include "tibble" and "gt". |
output_type |
String description of the output type (default = "multivariable"). Options include "multivariable" and "uni_and_multi". Selecting "multivariable" will produce a summary table of the supplied multivariable model. Selecting "uni_and_multi" will produce a summary table showing estimates of the Odds Ratio, Confidence Intervals and p-values produced using a univariable logistic regression model for each predctor along with the adjusted Odds Ratio, Confidence Intervals and p-values from the supplied multivariable model. |
confint_fast_estimate |
Boolean (default = |
assumption_checks |
Boolean (default = |
anonymise_counts |
Boolean (default = |
use_model_data_only |
Boolean (default = |
The table includes the following information:
Covariate Characteristics:
Number of observations for each characteristic
Number of observations resulting in the outcome of interest
Conversion rate of the outcome based on the number of observations
Model Results:
Estimated Odds Ratio, standard error, and p-value
Calculated confidence interval for the specified confidence level
A visualisation of the Odds Ratio plot is also provided for an at-a-glance view of the model results.
If anonymise_counts is set to TRUE, counts below 10 are suppressed as
<10, and other counts are rounded to the nearest multiple of 5. This
feature is helpful when working with sensitive data.
The returned object depends on the output parameter:
If output = 'tibble', the function returns an object of class "tbl_df", "tbl", and "data.frame".
If output = 'gt', the function returns an object of class "gt_tbl" and "list".
# Load the Titanic dataset df <- datasets::Titanic |> dplyr::as_tibble() |> # convert aggregated counts to individual observations dplyr::filter(n > 0) |> tidyr::uncount(weights = n) |> # convert character variables to factors dplyr::mutate(dplyr::across(dplyr::where(is.character), as.factor)) # Perform logistic regression using `glm` lr <- stats::glm( data = df, family = 'binomial', formula = Survived ~ Class + Sex + Age ) # Produce the Odds Ratio table as a tibble table_or(lr) # Produce the Odds Ratio table as a gt object table_or(lr, output = 'gt')# Load the Titanic dataset df <- datasets::Titanic |> dplyr::as_tibble() |> # convert aggregated counts to individual observations dplyr::filter(n > 0) |> tidyr::uncount(weights = n) |> # convert character variables to factors dplyr::mutate(dplyr::across(dplyr::where(is.character), as.factor)) # Perform logistic regression using `glm` lr <- stats::glm( data = df, family = 'binomial', formula = Survived ~ Class + Sex + Age ) # Produce the Odds Ratio table as a tibble table_or(lr) # Produce the Odds Ratio table as a gt object table_or(lr, output = 'gt')