library(tidyverse)
<- read_csv("https://raw.githubusercontent.com/Aranaur/aranaur.rbind.io/main/datasets/courage/courage.csv")
courage
courage
Lab 01: NC Courage Analysis
This report analyzes the performance of the NC Courage soccer team, examining home-field advantage, win rates, and average points scored. The analysis includes visualizations and statistical summaries to provide insights into the team’s performance trends.
1. Import Data
2. Game Results Visualization
library(ggplot2)
library(plotly)
%>%
courage count(result) %>%
ggplot(aes(x = result, y = n, fill = result)) +
geom_bar(stat = "identity", color = "black") +
labs(
title = "Game Results of NC Courage",
x = "Result",
y = "Number of Games"
+
) theme_light()
3. Home vs Away Games Count
<- courage %>%
courage mutate(home_courage = ifelse(courage$home_team == "NC", "home", "away"))
<- courage %>%
game_count count(home_courage)
::kable((game_count), caption = "Count of Home vs Away Games") knitr
home_courage | n |
---|---|
away | 36 |
home | 42 |
4. Results by Home and Away
%>%
courage count(home_courage, result) %>%
ggplot(aes(x = home_courage, y = n, fill = result, width = 0.6)) +
geom_bar(stat = "identity", position = "stack") +
labs(
title = "Game Results by Home and Away",
x = "Game Location",
y = "Number of Games",
fill = "Result"
+
) theme_light()
<- courage %>%
win_rate group_by(home_courage) %>%
summarise(
total_games = n(),
win = sum(result == "win")
%>%
) mutate(win_rate = win / total_games)
::kable(win_rate, caption = "Win Rate by Home and Away") knitr
home_courage | total_games | win | win_rate |
---|---|---|---|
away | 36 | 22 | 0.6111111 |
home | 42 | 31 | 0.7380952 |
NC have home advantage, because win rate at home(0.74) higher than away(0.61).
5. Average Points Won By
<- courage %>%
avg_win_by filter(result == "win") %>%
summarise(
avg_points_difference = mean(ifelse(home_team == "NC", home_pts - away_pts, away_pts - home_pts))
%>%
) pull(avg_points_difference)
On average, NC Courage won by 2.11 points.
6. Average Points Scored
<- courage %>%
courage mutate(courage_pts = ifelse(home_team == "NC", home_pts, away_pts))
<- courage %>%
avg_pts_win filter(result == "win") %>%
summarise(avg_pts = mean(courage_pts)) %>%
pull(avg_pts)
<- courage %>%
avg_pts_loss filter(result == "loss") %>%
summarise(avg_pts = mean(courage_pts)) %>%
pull(avg_pts)
When NC win, they score 2.58 points in average. When they lose, they score 0.86 points in average.
7. Points Analysis
<- courage %>%
courage mutate(
total_pts = home_pts + away_pts,
opponent_pts = total_pts - courage_pts
)
%>% select(total_pts, opponent_pts, courage_pts) courage
8. Scatter Plot of Points
<- ggplot(courage, aes(x = courage_pts, y = opponent_pts, color = home_team == "NC")) +
p geom_jitter(width = 0.1, height = 0.1) +
geom_abline(slope = 1, intercept = 0, linetype = "dashed") +
facet_wrap(~ season) +
labs(
x = "Points Scored by NC Courage",
y = "Points Scored by Opponent",
title = "Scatter Plot of NC Courage Points vs Opponent Points",
color = "Home Game"
+
) theme_light()
ggplotly(p)
The dashed line represents equal points scored by NC Courage and their opponents. Points above the line indicate NC Courage scored more, while points below indicate they scored less.
9. Home-Field Advantage Definition
A home-field advantage means that a team performs better when playing at their home venue compared to when they play away. This could be due to familiar surroundings, fan support, and reduced travel fatigue.
In contrast, no home-field advantage means that the team’s performance is consistent regardless of whether they play at home or away, showing no significant difference in results.