Skip to content

Instantly share code, notes, and snippets.

@turgeonmaxime
Created August 10, 2018 02:01
Show Gist options
  • Save turgeonmaxime/6bbac037c7c21920873c9346146156a8 to your computer and use it in GitHub Desktop.
Save turgeonmaxime/6bbac037c7c21920873c9346146156a8 to your computer and use it in GitHub Desktop.
library(tidyverse)
# Create dataset with fantasy scores
data_ottawa <- tibble::tribble(
~harris, ~Sinopoli, ~Spencer, ~Ellingson,
19.8, 13.4, 20.2, 18.4,
3.4, 8, 4.1, 21.7,
25.7, 31.8, 5.9, 9.9,
-0.3, 7.7, 6.6, 5.6,
18.5, 34.1, 7.8, 7.7,
9.1, 17.2, 5.8, 6.4,
21.2, 21.9, 28.5, 4.6
) %>%
gather(WR, score, -harris)
# Scatterplot
data_ottawa %>%
ggplot(aes(harris, score, colour = WR)) +
geom_point() + theme_minimal() +
geom_smooth(method = 'lm', se = FALSE) +
xlab("Harris' Fantasy Points") +
ylab("WR's Fantasy Points")
# Correlations
data_ottawa %>%
group_by(WR) %>%
summarise(cor(harris, score))
# Linear regression
data_ottawa %>%
group_by(WR) %>%
nest() %>%
mutate(model = map(data, ~lm(harris ~ score, data = .)),
coef = map(model, broom::tidy)) %>%
unnest(coef) %>%
filter(term == "score")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment