# 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)
Run the code above in your browser using DataLab