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) | |
n_games <- 100 | |
# Define the teams | |
teams <- c("rock", "paper", "scissors") | |
# simulated home advantage # | |
home_adv<-2 | |
# Generate the data frame |
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(Matrix) | |
library(dplyr) | |
library(ggplot2) | |
# set points to win - 25 for sets 1-4, 15 for set 5 # | |
ptw<-15 | |
# set point probabilities # | |
srp<-0.42 # probability of winning a point when serving # | |
sop<-0.58 # probability of winning a point when receiving serve (sideout) # | |
# create tibble of game states |
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
rm(list = ls(all = TRUE)) | |
library(XML) | |
library(tidyverse) | |
library(lubridate) | |
library(scales) | |
library(ggthemes) | |
library(ggridges) | |
library(rpart) |
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
# Code for creating an Elam Ending simulation model # | |
rm(list = ls(all = TRUE)) | |
library(dplyr) | |
library(tidyr) | |
loc<-"" # enter file path for exporting model output # | |
# point probabilities for each possession : 0-1-2-3-4 points # | |
tp<-c(0.505,0.031,0.325,0.137,0.002) # team with possession # |
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
# this code creates animated shooting windup charts for multiple players on a single chart # | |
rm(list = ls(all = TRUE)) | |
library(dplyr) | |
library(ggplot2) | |
library(gganimate) | |
library(readr) | |
# enter location to output animated gifs # | |
locout<-"" |
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
# this code creates animated shooting windup charts for a selected player # | |
rm(list = ls(all = TRUE)) | |
library(dplyr) | |
library(ggplot2) | |
library(gganimate) | |
library(readr) | |
# enter location to output animated gifs # | |
locout<-"" |
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
# this code generates hexbin heat maps for bank shots, overlaid over a backboard # | |
# dbdr is a data frame with the following columns (sourced from 2013-2016 tracking data): | |
# bx (x-coordinate of backboard strike) | |
# by (y-coordinate of backboard strike) | |
ggplot(dbdr,aes(x=by,y=bz)) + | |
theme_bw() + | |
coord_fixed() + | |
geom_hex(binwidth=c(0.25,0.25),aes(fill = stat((count)))) + | |
scale_fill_gradient(low="lightblue1",high="darkblue") + |
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
# this code generates bank shot scatterplots for different players via facet_wrap | |
# dbsel is a data frame with the following columns (sourced from 2013-2016 tracking data): | |
# nm (player name) | |
# bx (x-coordinate of backboard strike) | |
# by (y-coordinate of backboard strike) | |
ggplot(dbsel,aes(x=by,y=bz)) + | |
theme_bw() + | |
coord_fixed() + # so the backboard is shown to scale # |