Produces an Odds Ratio plot to visualise the results of a logistic regression analysis.
Arguments
- glm_model_results
Results from a binomial Generalised Linear Model (GLM), as produced by
stats::glm()
.
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)
#>
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#>
#> filter, lag
#> The following objects are masked from ‘package:base’:
#>
#> intersect, setdiff, setequal, union
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)
#> Warning: Removed 3 rows containing missing values or values outside the scale range
#> (`geom_point()`).
#> Warning: Removed 3 rows containing missing values or values outside the scale range
#> (`geom_errorbarh()`).
#> Warning: Removed 5 rows containing missing values or values outside the scale range
#> (`geom_point()`).