# https://stats.stackexchange.com/questions/6206/how-to-plot-decision-boundary-in-r-for-logistic-regression-model
beta_0 <- coef(probit_model)[1]
beta_1 <- coef(probit_model)[2]
beta_2 <- coef(probit_model)[3]
boundary_slope <- -1.0 * beta_1 / beta_2
boundary_intercept <- -1.0 * beta_0 / beta_2
penguin_pred_df <- penguin_class_df |>
mutate(species_pred = ifelse(
bill_length_mm > boundary_intercept + boundary_slope * flipper_length_mm,
1,0)) |>
mutate(across(species_pred, as.factor))
penguin_pred_df |>
ggplot(aes(x = flipper_length_mm, y = bill_length_mm,
color = chinstrap_bool)) +
geom_point(size = 3) +
geom_abline(intercept = boundary_intercept,
slope = boundary_slope,
color = adelie_color,
linewidth = 2,
linetype = 2) +
labs(title = "Probit Approximation",
subtitle = "<span style = 'color:#fb7504'>decision boundary</span>",
caption = "Data Science Learning Community") +
scale_color_manual(values = c("gray70", chinstrap_color)) +
theme_minimal() +
theme(plot.title = element_markdown(face = "bold", size = 24),
plot.subtitle = element_markdown(size = 16))