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) | |
# CF en.wikipedia.org/wiki/Rule_of_succession | |
# True probabilities | |
true_probs <- c(0.1, 0.3, 0.7, 0.9) | |
# How many runs for each probability and prior? | |
n_repetitions <- 10 | |
# How many observations to update estimated probability? | |
n_observations <- 500 |
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) | |
library(lubridate) | |
source("https://raw.githubusercontent.com/mjfrigaard/RDataSets/master/DotR/monarchs.R") | |
monarchs <- | |
monarchs %>% | |
mutate(reign_length = lubridate::interval(from, to) / years(1)) | |
monarchs %>% |
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
--- | |
title: "UK flights" | |
--- | |
```{r} | |
library(tidyverse) | |
library(rvest) | |
``` |
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
# install.packages("babynames") | |
library(babynames) | |
babynames %>% | |
filter(str_detect(name, "Hill?ary")) %>% | |
count(year, sex, wt = prop) %>% | |
ggplot(aes(x = year, y = nn)) + | |
geom_line(aes(colour = sex)) + | |
scale_y_continuous(labels = scales::percent_format()) + | |
theme_minimal() + |
We can't make this file beautiful and searchable because it's too large.
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
match_id,date,home,away,hgoals,agoals,side,xg,league,season | |
4749,2014-08-16T12:45:00Z,Manchester United,Swansea,1,2,h,0.01874101348221302,EPL,2014 | |
4749,2014-08-16T12:45:00Z,Manchester United,Swansea,1,2,h,0.015597633086144924,EPL,2014 | |
4749,2014-08-16T12:45:00Z,Manchester United,Swansea,1,2,h,0.06492315977811813,EPL,2014 | |
4749,2014-08-16T12:45:00Z,Manchester United,Swansea,1,2,h,0.057787537574768066,EPL,2014 | |
4749,2014-08-16T12:45:00Z,Manchester United,Swansea,1,2,h,0.0488010048866272,EPL,2014 | |
4749,2014-08-16T12:45:00Z,Manchester United,Swansea,1,2,h,0.03097105398774147,EPL,2014 | |
4749,2014-08-16T12:45:00Z,Manchester United,Swansea,1,2,h,0.02559618093073368,EPL,2014 | |
4749,2014-08-16T12:45:00Z,Manchester United,Swansea,1,2,h,0.06947857141494751,EPL,2014 | |
4749,2014-08-16T12:45:00Z,Manchester United,Swansea,1,2,h,0.5765787363052368,EPL,2014 |
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
benchmark <- | |
games %>% | |
mutate( | |
outcome = case_when( | |
hgoals > agoals ~ "home_win", | |
agoals > hgoals ~ "away_win", | |
hgoals == agoals ~ "draw" | |
) | |
) %>% | |
count(outcome) %>% |
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
to_clipboard <- function(data) { | |
clip <- pipe("pbcopy", "w") | |
write.table(data, file = clip, row.names = FALSE) | |
close(clip) | |
} |
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
lower_bound <- function(d) { | |
(1 - sqrt(1 - 2*d)) / 2 | |
} | |
upper_bound <- function(d) { | |
(1 + sqrt(1 - 2*d)) / 2 | |
} | |
tibble(d = seq(0, 0.5, 0.001), | |
lower = lower_bound(d), |
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
suppressPackageStartupMessages({ | |
library(tidyverse) | |
library(sf) | |
}) | |
# c.f. http://web.mit.edu/tee/www/bertrand/problem.html | |
chord_length <- function(theta) { | |
2 * sin(theta / 2) | |
} |