You're working as a sports journalist at a major online sports media company, specializing in soccer analysis and reporting. You've been watching both men's and women's international soccer matches for a number of years, and your gut instinct tells you that more goals are scored in women's international football matches than men's. This would make an interesting investigative article that your subscribers are bound to love, but you'll need to perform a valid statistical hypothesis test to be sure!
While scoping this project, you acknowledge that the sport has changed a lot over the years, and performances likely vary a lot depending on the tournament, so you decide to limit the data used in the analysis to only official FIFA World Cup matches (not including qualifiers) after 2002-01-01.
You create two datasets containing the results of every official men's and women's international football match since the 19th century, which you scraped from a reliable online source. This data is stored in two CSV files: women_results.csv and men_results.csv.
The question you are trying to determine the answer to is:
Are more goals scored in women's international soccer matches than men's?
You assume a 10% significance level, and use the following null and alternative hypotheses:
# Import necessary libraries
library(tidyverse)
library(readr)
library(dplyr)
library(infer)# Start your code here!
# Use as many cells as you like# Load data
women_matches <- read.csv("women_results.csv")
men_matches <- read.csv("men_results.csv")# Explore female soccer data
str(women_matches)
head(women_matches)# Explore male soccer data
str(men_matches)
head(men_matches)# Add column to identify female or male, a column with total goals and filter data
women_matches <- women_matches %>%
filter(tournament == "FIFA World Cup", date > 2002-01-01) %>%
group_by(X) %>%
mutate(total_goals = sum(home_score + away_score), gender = "female") %>%
ungroup() %>%
arrange(X)
women_matches
men_matches <- men_matches %>%
filter(tournament == "FIFA World Cup", date > 2002-01-01) %>%
group_by(X) %>%
mutate(total_goals = sum(home_score + away_score), gender = "male") %>%
ungroup() %>%
arrange(X)
men_matches# Explore female data distribution
ggplot(women_matches, aes(total_goals)) +
geom_bar(bin = 1) +
xlim(0,15) +
ylim(0,45)ggplot(men_matches, aes(total_goals)) +
geom_bar(bin = 1) +
xlim(0,15) +
ylim(0,45)# Create data frame with both female and male data
fifawvm <-
bind_rows(women_matches, men_matches) %>%
filter(tournament == "FIFA World Cup", date > 2002-01-01) %>%
arrange(X)
fifawvm# Explore difference in data by gender
ggplot(fifawvm, aes(gender, total_goals)) +
geom_boxplot()# Because data does not follow a normal distribution and we are trying to assess if the means of two populations are equal we will be using a Wilcoxon-Mann-Whitney test
alpha <- 0.1
test_results <- wilcox.test(
total_goals ~ gender,
data = fifawvm,
alternative = "greater"
)
test_results
p_val <- 0.005107
p_val < alpha# Creating a data frame with the result and the conclusion regarding the hypothesis
result_df <- tibble(p_val, result = "reject")result_df