Created
December 20, 2018 16:59
Star
You must be signed in to star a gist
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
### --- | |
# | |
# from @expersso | |
set.seed(894) # number of regular season NHL goals Wayne Gretzky scored | |
x <- replicate(10000, sum(sample(0:1, 20, TRUE, c(0.945, 0.055)))) | |
table(ifelse(x == 0, "Team A win", ifelse(x == 1, "Draw", "Team B win"))) / 100 | |
### --- | |
library(tidyverse) | |
x <- as.tibble(x) | |
x %>% | |
group_by(value) %>% | |
tally() | |
### --- plot | |
ggplot(data=x, aes(value)) + | |
geom_histogram(binwidth = 1, fill = "white", colour = "black") + | |
scale_x_continuous(breaks=seq(0,8,1)) + | |
theme(panel.grid.major.x = element_blank()) + | |
labs(x = "goals per 20 shots", | |
y = "number of games (out of 10,000", | |
title = "Distribution of games by number of goals scored", | |
subtitle = "20 shots per game each with 5.5% chance of scoring", | |
caption = "source: a question @nnstats posed on twitter") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment