Package 'plotor'

Title: 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% confidence interval and plot the results using 'ggplot2'.
Authors: Craig Parylo [aut, cre, cph]
Maintainer: Craig Parylo <[email protected]>
License: MIT + file LICENSE
Version: 0.5.2.9000
Built: 2025-03-09 12:27:45 UTC
Source: https://github.com/craig-parylo/plotor

Help Index


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)

Arguments

glm_model_results

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

conf_level

Numeric between 0.001 and 0.999 (default = 0.95). The confidence level to use when setting the confidence interval, most commonly will be 0.95 or 0.99 but can be set otherwise.

Value

an object of class gg and ggplot

See Also

See vignette('using_plotor', package = 'plotor') for more details on use.

More details and examples are found on the website: https://craig-parylo.github.io/plotor/index.html

Examples

# libraries
library(plotor)
library(datasets)
library(dplyr)
library(ggplot2)
library(stats)
library(forcats)
library(tidyr)

# get some data
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.

Usage

table_or(glm_model_results, conf_level = 0.95, output = "tibble")

Arguments

glm_model_results

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

conf_level

Numeric between 0.001 and 0.999 (default = 0.95). The confidence level to use when setting the confidence interval, most commonly will be 0.95 or 0.99 but can be set otherwise.

output

String description of the output type. Default = 'tibble'. Options include 'tibble' and 'gt'.

Details

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

object returned depends on output parameter - output = 'tibble' returns an object of "tbl_df", "tbl", "data.frame" class, whilst output = 'gt' returns an object of class "gt_tbl" and "list".

Examples

# get some data
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, first as a tibble then as gt object
table_or(lr)
table_or(lr, output = 'gt')