| 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 |
| Repository: | CRAN |
| Date/Publication: | 2025-12-08 08:20:07 UTC |
plotor: 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.
Author(s)
Maintainer: Craig Parylo craig.parylo2@nhs.net (ORCID) [copyright holder]
See Also
Useful links:
Report bugs at https://github.com/craig-parylo/plotor/issues
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 |
confint_fast_estimate |
Boolean (default = |
details |
Boolean (default = |
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 |
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 = |
Value
The function returns an object of class gg and ggplot, which can be
customised and extended using various ggplot2 functions.
See Also
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
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 |
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 = |
Details
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.
Value
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".
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')