Type: Package
Title: Odds Ratio Tools for Logistic Regression
Version: 0.8.0
Maintainer: Craig Parylo <craig.parylo2@nhs.net>
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.
License: MIT + file LICENSE
Encoding: UTF-8
Imports: broom, car, cli, detectseparation, dplyr, forcats, ggplot2, glue, gt, janitor, purrr, rlang, scales, stats, stringr, tibble, tidyr, tidyselect
RoxygenNote: 7.3.3
Suggests: datasets, knitr, labelled, magrittr, MASS, medicaldata (≥ 0.2.0.9001), NHANES, R4HCR, rmarkdown, svglite, testthat (≥ 3.0.0), vdiffr
VignetteBuilder: knitr
URL: https://github.com/craig-parylo/plotor, https://craig-parylo.github.io/plotor/
BugReports: https://github.com/craig-parylo/plotor/issues
Config/testthat/edition: 3
Depends: R (≥ 4.1.0)
Config/Remotes: higgi13425/medicaldata
NeedsCompilation: no
Packaged: 2025-12-08 08:00:24 UTC; craigparylo
Author: Craig Parylo ORCID iD [aut, cre, cph]
Repository: CRAN
Date/Publication: 2025-12-08 08:20:07 UTC

plotor: Odds Ratio Tools for Logistic Regression

Description

logo

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.

Author(s)

Maintainer: Craig Parylo craig.parylo2@nhs.net (ORCID) [copyright holder]

See Also

Useful links:


Check OR

Description

Performs a series of tests to ensure that assumptions for logistic regression are met, with optional detailed feedback if any tests fail.

Usage

check_or(glm_model_results, confint_fast_estimate = FALSE, details = TRUE)

Arguments

glm_model_results

Results from a binomial Generalised Linear Model (GLM), as produced by stats::glm().

confint_fast_estimate

Boolean (default = FALSE) Use a faster estimate of the confidence interval? Note: this assumes normally distributed data, which may not be suitable for your data.

details

Boolean (default = TRUE) Show detailed feedback for any failed tests?

Value

Logical, TRUE if all assumption tests pass, FALSE if one or more tests fail

Examples

# 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)

Plot OR

Description

Produces an Odds Ratio plot to visualise the results of a logistic regression analysis.

Usage

plot_or(
  glm_model_results,
  conf_level = 0.95,
  confint_fast_estimate = FALSE,
  assumption_checks = TRUE
)

Arguments

glm_model_results

Results from a binomial Generalised Linear Model (GLM), as produced by stats::glm().

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 = FALSE) indicating whether to use a faster estimate of the confidence interval. Note: this assumes normally distributed data, which may not be suitable for your data.

assumption_checks

Boolean (default = TRUE) indicating whether to conduct checks to ensure that the assumptions of logistic regression are met.

Value

The function returns an object of class gg and ggplot, which can be customised and extended using various ggplot2 functions.

See Also

Examples

# 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)

Table OR

Description

Produces a formatted table displaying the outputs from the Odds Ratio analysis, including details on covariate characteristics and model results.

Usage

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
)

Arguments

glm_model_results

Results from a binomial Generalised Linear Model (GLM), as produced by stats::glm().

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 = FALSE) indicating whether to use a faster estimate of the confidence interval. Note: this assumes normally distributed data, which may not be suitable for your data.

assumption_checks

Boolean (default = TRUE) indicating whether to conduct checks to ensure that the assumptions of logistic regression are met.

anonymise_counts

Boolean (default = FALSE) indicating whether to anonymise counts in the output table. If TRUE, counts less than 10 are suppressed and otherwise rounded to the nearest multiple of 5.

use_model_data_only

Boolean (default = FALSE) indicating whether to use only the subset of data that was used as part of the multivariable model, or set to TRUE to use the full set of data provided to the multivariable model. Note, any records containing missing values for any of the outcome or predictor variables are automatically excluded from the multivariable model by stats::glm, so the overall number of records used in multivariable models can be much lower than the total number of records supplied to the function. Set to TRUE to increase comparability between the univariable and multivariable models, set to FALSE to gain a more holistic view of the invididual relationships between predictors and outcome.

Details

The table includes the following information:

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.

Value

The returned object depends on the output parameter:

Examples

# 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')