#Import data
FullEPLFinal <- `FullEPLFinal.(1)`
#Isolate the columns we will be using for our dataset.
my_dataEPL <- FullEPLFinal[c(4, 5, 8, 11)]
# Removing Draws from the HTResult and FTResult by subsetting.
my_dataEPL <- subset(my_dataEPL, HTResult!="D")
my_dataEPL <- subset(my_dataEPL, FTResult!="D")
# Now, only count the instances where the HTResult is the same as the FTResult
library(tidyverse)
HTMomentum <- my_dataEPL[c("Home", "Away", "HTResult", "FTResult")] %>%
subset(FTResult!= "D")%>%
subset(HTResult!="D") %>%
subset(HTResult==FTResult)
#Now looking at instances where the HTResult does not match the FTresult, calling it an 'upset'
HTUpset <- my_dataEPL[c("Home", "Away", "HTResult", "FTResult")] %>%
subset(FTResult!= "D") %>%
subset(HTResult!="D") %>%
subset(HTResult!=FTResult)
#Counting how often a draw at HT leads to a draw at FT
HTMomentumDraws <- my_dataEPL[c("Home", "Away", "HTResult", "FTResult")] %>%
subset(FTResult=="D") %>%
subset(HTResult=="D") %>%
subset(HTResult==FTResult)
#Now looking at the HT Frequencies
HalfTimeResults_freq <- table(my_dataEPL$HTResult)
#away winnings in HTR
my_dataEPL2 <- subset(my_dataEPL, HTResult!="H")
#teams that won in the FTR where away won in the HTR
FullTimeResults_freq_away <- table(my_dataEPL2$FTResult)
#data where home won in the HTR
my_dataEPL3 <- subset(my_dataEPL, HTResult!="A")
#Team that won in the FTR where home won in the HTR
FullTimeResults_freq_home <- table(my_dataEPL3$FTR)
class(FullTimeResults_freq_home)
FullTimeResults_freq_home <- data.frame(FullTimeResults_freq_home)
view(FullTimeResults_freq_home)
class(FullTimeResults_freq_home)
#Pie chart showing the amount of game won by the home team when they were in the lead at halftime.
HomePieValues <- c(FullTimeResults_freq_home["H"], FullTimeResults_freq_home["A"])
percentlabels_H <- round(100*HomePieValues/sum(HomePieValues), 1)
HomePieLabels <- paste(percentlabels_H, "%", sep="")
HomePie <- pie(HomePieValues, labels = HomePieLabels,
main="Percentage of Home teams that are leading at HT, \n win at FT",
col=rainbow(length(HomePieValues)))
Home_Legend <- legend("topright", c("Home Team wins at FT", "Home Team lose at FT"),
cex=1,
fill=rainbow(length(HomePieValues)))
class(HomePieValues)
HomePieValues <- data.frame(HomePieValues)
class(HomePieValues)
head(HomePieValues)
#Use a barplot to visualize the data:
library(ggplot2)
bp1 <- ggplot(HomePieValues, aes(x= Home, y= value, fill=HomePieValues)) +
geom_bar(width =1, stat = "identity")
PieChart_Home <- ggplot(HomePieValues, aes(x="", y=value, fill=column)) +
geom_bar(stat="identity", width=1, color="white") +
coord_polar("y", start=0)
PieChart_Home
#Pie Chart showing the amount of games won by the Away Team when they were in the lead at halftime.
AwayPieValues <- c(FullTimeResults_freq_away["A"], FullTimeResults_freq_away["H"])
percentlabels_A <- round(100*AwayPieValues/sum(AwayPieValues), 1)
AwayPieLabels <- paste(percentlabels_A, "%", sep="")
AwayPie <- pie(AwayPieValues, labels=AwayPieLabels,
main="Percentage of Away Teams that are leading at HT, \n win at FT ",
col=rainbow(length(AwayPieValues)))
Away_Legend <- legend("topright",c("Away Team wins at FT","Away Team lose at FT"),
cex=1,
fill=rainbow(length(AwayPieValues)))
AwayPie
#Summary
#Looking at the half time results, out of 1884 matches played (excluding the draws), 1147 games were won by the home team and 737 games were won by the away team.
#HOME: Out of the 1147 home teams that won in the first half, 1086 home teams continued to win in the full time. Hence only 61 Home teams lost even after winning at half time.
#AWAY: Out of the 737 away teams that won in the first half, 645 away teams continued to win in the full time, hence only 92 away teams lost even after winning at half time
#Betting: In terms of betting, one could possibly increase their bets if their team is winning at HT or withdraw their betting if they are loosing at HT.
#in terms of playing at home, if the home team is loosing at HT, fans may expect a higher chance of recovery and winning the game as opposed to if the away team is loosing at HT, one would not expect a recovery.