Skip to content

Instantly share code, notes, and snippets.

@Torvaney
Created August 31, 2018 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Torvaney/34eff3f87eecd0fc744cf903e2d559e6 to your computer and use it in GitHub Desktop.
Save Torvaney/34eff3f87eecd0fc744cf903e2d559e6 to your computer and use it in GitHub Desktop.
library(tidyverse)
# https://math.stackexchange.com/questions/35791/birthday-problem-expected-number-of-collisions
exp_collisions <- function(n, d) {
n * (1 - (1 - (1 / d)) ^ (n - 1))
}
tibble(n = 1:80) %>%
mutate(collisions = exp_collisions(n, 365)) %>%
ggplot(aes(x = n, y = collisions)) +
geom_point() +
scale_y_continuous(breaks = function(x, n = 5) pretty(x, n)[pretty(x, n) %% 1 == 0],
minor_breaks = NULL) +
scale_x_continuous(minor_breaks = function(x, n = 1) pretty(x, n)[pretty(x, n) %% 1 == 0]) +
labs(title = "Expected number of shared birthdays",
subtitle = "By size of organisation",
y = NULL,
x = "# of people")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment