Skip to content

Instantly share code, notes, and snippets.

@elsherbini
Created August 16, 2018 16:03
Show Gist options
  • Save elsherbini/8edfa5ada46a020132ec61436d011cba to your computer and use it in GitHub Desktop.
Save elsherbini/8edfa5ada46a020132ec61436d011cba to your computer and use it in GitHub Desktop.
library(tidyverse)
library(cowplot)
library(scales)
library(colorblindr)
point_map <- tribble(~place, ~old_value, ~new_value,
1,6,10,
2,5,7,
3,4,4,
4,3,2,
5,2,1,
6,1,1,
7,0,0
)
simulations <- crossing(simulation=seq_len(5000), floor_game=seq_len(7), participating_floor=seq_len(7)) %>%
group_by(simulation, floor_game) %>%
mutate(place=sample(seq_len(7), 7, replace=FALSE)) %>%
left_join(point_map)
results <- simulations %>%
group_by(simulation, participating_floor) %>%
summarise(new_total=sum(new_value), old_total=sum(old_value)) %>%
group_by(simulation) %>%
mutate(new_rank = factor(min_rank(desc(new_total)), levels=seq_len(7)), old_rank=factor(min_rank(desc(old_total)), seq_len(7)))
# what do the new ranks look like compared to old?
p1 <- results %>%
group_by(new_rank, old_rank) %>%
summarise(count=n()) %>%
group_by(old_rank) %>%
mutate(proportion=count/sum(count)) %>%
ggplot(aes(x=new_rank, y=proportion)) +
geom_bar(aes(fill=old_rank), stat="identity", show.legend=FALSE) +
facet_wrap(~paste("Old Rank", old_rank)) +
scale_y_continuous("Percentage", labels = percent_format()) +
scale_x_discrete("New Rank") +
scale_fill_OkabeIto() +
ggtitle("New scoring system","1st and 7th don't change much, others change more")
p2 <- simulations %>% group_by(simulation, participating_floor, place) %>% summarise(count=n()) %>% left_join(results %>% select(simulation, participating_floor, new_rank, old_rank)) %>% gather("new_or_old", "rank", -simulation, -participating_floor, -place, -count) %>% filter(rank %in% c(1,2,3)) %>% group_by(place, new_or_old, rank) %>% summarise(count=sum(count)) %>% ggplot(aes(x=place, y=count)) + geom_bar(aes(fill=new_or_old), stat="identity", show.legend=FALSE) + facet_grid(paste("rank=", rank)~new_or_old) + scale_fill_OkabeIto() + ggtitle("Distribution of placements in individual games", "In new system, 1st counts more!")
p3 <- plot_grid(p1, p2, ncol=1, nrow=2)
ggsave("~/research/procrasti_cup.png", p3, width=6, height=12)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment