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) since 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 the necessary libraries
import pandas as pd
import numpy as np
import pingouin as pg
from scipy import stats
import matplotlib.pyplot as plt
from scipy.stats import mannwhitneyu
# Load the women's and men's results datasets
women_df = pd.read_csv("women_results.csv")
men_df = pd.read_csv("men_results.csv")
# Explore the women's data
women_df.head()
# Explore the men's data
men_df.head()
# Filter for FIFA World Cup matches after 2002-01-01
filtered_women_df = women_df[
(women_df["tournament"] == "FIFA World Cup") & (pd.to_datetime(women_df["date"]) > "2002-01-01")
]
filtered_men_df = men_df[
(men_df["tournament"] == "FIFA World Cup") & (pd.to_datetime(men_df["date"]) > "2002-01-01")
]
filtered_women_df["total_goals"] = filtered_women_df["home_score"] + filtered_women_df["away_score"]
filtered_men_df["total_goals"] = filtered_men_df["home_score"] + filtered_men_df["away_score"]
filtered_men_df
filtered_men_df.describe().T
filtered_women_df.describe().T
# Plot histograms
plt.hist(filtered_women_df["total_goals"], alpha=0.5, color="cornflowerblue", label="Women's Scores")
plt.hist(filtered_men_df["total_goals"], alpha=0.5, color="salmon", label="Men's Scores")
plt.legend()
plt.show()
# Visualize the distributions of goals scored using histograms
fig, axes = plt.subplots(1, 2)
axes[0].hist(filtered_women_df["total_goals"])
axes[0].set_title("Total Scores - Women")
axes[0].set_xlim([0, 10])
axes[0].set_ylim([0, 100])
axes[1].hist(filtered_men_df["total_goals"])
axes[1].set_title("Total Scores - Men")
axes[1].set_xlim([0, 10])
axes[1].set_ylim([0, 100])
plt.subplots_adjust(wspace=0.4, hspace=0.4)
plt.show()
From the plots we can see that both distributions of scores are right-skewed.
# Check the length of the datasets
print(f"Number of samples in women's group is: {len(filtered_women_df)}")
print(f"Number of samples in men's group is: {len(filtered_men_df)}")
# Using Shapiro-Wilk test to confirm if distribution is normal
stats.shapiro(filtered_women_df["total_goals"])