Skip to content

Instantly share code, notes, and snippets.

@MonkmanMH
Created December 20, 2018 16:59
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save MonkmanMH/3b3b3bafccabb67daa888c12e5047ca5 to your computer and use it in GitHub Desktop.
### ---
#
# 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