Type: | Package |
Title: | Produces an Odds Ratio Plot from a Logistic Regression Model |
Version: | 0.7.0 |
Maintainer: | Craig Parylo <craig.parylo2@nhs.net> |
Description: | Produces an Odds Ratio (OR) Plot to visualise the result of a logistic regression analysis. Provide it with a binomial regression model produced by 'glm()' and it will convert the estimates to odds ratios with a 95% confidence interval and plot the results using 'ggplot2'. |
License: | MIT + file LICENSE |
Encoding: | UTF-8 |
Imports: | broom, car, cli, detectseparation, dplyr, forcats, ggplot2, glue, gt, janitor, purrr, rlang, scales, stats, stringr, tibble, tidyselect |
RoxygenNote: | 7.3.2 |
Suggests: | datasets, knitr, labelled, rmarkdown, svglite, testthat (≥ 3.0.0), tidyr, 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) |
NeedsCompilation: | no |
Packaged: | 2025-07-01 13:26:20 UTC; Craig.Parylo |
Author: | Craig Parylo |
Repository: | CRAN |
Date/Publication: | 2025-07-01 13:40:01 UTC |
plotor: Produces an Odds Ratio Plot from a Logistic Regression Model
Description
Produces an Odds Ratio (OR) Plot to visualise the result of a logistic regression analysis. Provide it with a binomial regression model produced by 'glm()' and it will convert the estimates to odds ratios with a 95
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)
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 = |
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 showing 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 = "tibble",
confint_fast_estimate = FALSE
)
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 of the output type (default = 'tibble'). Options include 'tibble' and 'gt'. |
confint_fast_estimate |
Boolean (default = |
Details
The table includes the following information:
Covariate characteristics:
Number of observations for each characteristic
Number of observiations resulting in the outcome of interest
Conversion rate of outcome by 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 OR plot is also provided for an at-a-glance view of the model results
Includes details on the characteristics of the covariates, such as:
the number of observations for each characteristic,
the number of observations resulting in the outcome of interest,
the conversion rate of outcome by the number of observations,
Details are calculated showing the:
estimated Odds Ratio, standard error and p-value,
calculated confidence interval for the confidence level,
Also included is a visualisation of the OR plot to provide an at-a-glance view of the model results.
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')