library(tidyverse)
p_at_least_one_event <- function(p_event, periods = 50) {
tibble(
time = 1:periods,
p_at_least_one_event = 1 - (1 - p_event)^(1:periods)
)
}
tibble(
p_event = seq(0.01, 0.1, by = 0.01)
) |>
mutate(
curve = map(p_event, p_at_least_one_event),
p_event = forcats::fct_inseq(as.factor(p_event))
) |>
unnest(c(curve)) |>
ggplot(aes(time, p_at_least_one_event, color = p_event)) +
geom_line() +
scale_color_viridis_d() +
labs(
title = "The cumulative risk of repeated small hazards",
x = "Years",
y = "Probability of at least one event",
color = "Event chance\neach year"
) +
theme_minimal(18)
Created on 2023-11-27 with reprex v2.0.2