Created
August 31, 2018 09:33
-
-
Save Torvaney/34eff3f87eecd0fc744cf903e2d559e6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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