library(tidyverse)
## -- Attaching packages ----------------------------------------------------------------------------------------------------------- tidyverse 1.2.1 --
## v ggplot2 3.1.0 v purrr 0.2.5
## v tibble 2.0.1 v dplyr 0.8.0.1
## v tidyr 0.8.3 v stringr 1.4.0
## v readr 1.3.1 v forcats 0.3.0
## -- Conflicts -------------------------------------------------------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
n = 70
p = numeric(n)
for (i in 1:n){
prob_match = 1 - (0:(i-1))/366
p[i] = 1 - prod(prob_match)
}
graph = ggplot(data.frame(x = 1:n, probability = p), aes(x=x, y=probability)) +
geom_point() +
xlab("Number of people") + ylab("Probability of at least one match")
ggplotly(graph)