forked from Will-Renius/TennisAnalytics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nadal_analysis.Rmd
47 lines (39 loc) · 1.76 KB
/
nadal_analysis.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
---
title: "Project"
author: "Jacob Schmitter"
date: "November 13, 2017"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE,comment = NA)
library(dplyr)
```
```{r}
load("data/aggregated_mens.RData")
```
```{r}
men.data <- t2
```
Below I filter the `men.data` data frame to only have games that Rafael Nadal played in as well as add varibales that state if he won the match and if he was favored in the B365 betting line.
```{r}
nadal <- filter(men.data, Winner == "Nadal R." | Winner == "Nadal-Parera R." | Loser == "Nadal R." | Loser == "Nadal-Parera R.")
#remove rows with NaN in average betting odds columns
nadal <- nadal[!is.na(nadal$avgW),]
nadal <- nadal[!is.na(nadal$avgL),]
nadal$Outcome <- (nadal$Winner == "Nadal R." | nadal$Winner == "Nadal-Parera R.")
nadal$Favored <- ((nadal$Outcome == TRUE) & (nadal$avgW < nadal$avgL)) | ((nadal$Outcome == FALSE) & (nadal$avgL < nadal$avgW))
```
```{r}
#win percentage for Nadal by surface
nadal %>% group_by(Surface) %>% summarise("Win Percentage" = sum(Outcome)/length(Surface))
#win percentage for Nadal by surface and if favored in match
nadal %>% group_by(Surface,Favored) %>% summarise("Win Percentage" = sum(Outcome)/length(Surface))
#win percentage for Nadal by series
nadal %>% group_by(Series) %>% summarise("Win Percentage" = sum(Outcome)/length(Series))
#win percentage for Nadal by series and if favored in match
nadal %>% group_by(Series,Favored) %>% summarise("Win Percentage" = sum(Outcome)/length(Series))
#win percentage for Nadal by round
nadal %>% group_by(Round) %>% summarise("Win Percentage" = sum(Outcome)/length(Round))
#win percentage for Nadal by round and if favored in match
nadal %>% group_by(Round,Favored) %>% summarise("Win Percentage" = sum(Outcome)/length(Round))
```