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:
After plotting the histogram distributions of men's and women's sum of home and away goals, we observed that the distributions are not normal(right-skewed). This observation led us to conclude that a non-parametric test would be more appropriate to determine if there is a significant difference between the average goals scored in women's matches compared to men's matches.
To test our hypotheses, we set up the following:
- Null Hypothesis (H0): The average goals scored in women's matches is the same as in men's matches.
- Alternative Hypothesis (H1): The average goals scored in women's matches is more than in men's matches.
We performed Mann-Whitney U test, a non-parametric hypothesis test, to evaluate the alternative hypotheses. The results of the test showed a small p-value(0.0051), indicating that there is enough evidence to reject the null hypothesis. Therefore, we rejected the null hypothesis and conclude that there is a significant difference in the average goals scored between men's and women's matches and women's average scored goals is more than men's.
import pandas as pd
import matplotlib.pyplot as plt
import pingouin as pg
# Load datasets
men_df = pd.read_csv("men_results.csv")
women_df = pd.read_csv("women_results.csv")
# Filter data
men_df["date"] = pd.to_datetime(men_df["date"])
men_filtered = men_df[(men_df["date"] > "2002-01-01") & (men_df["tournament"] == "FIFA World Cup")]
women_df["date"] = pd.to_datetime(women_df["date"])
women_filtered = women_df[(women_df["date"] > "2002-01-01") & (women_df["tournament"] == "FIFA World Cup")]
# Add columns
men_filtered["category"] = "men"
women_filtered["category"] = "women"
men_filtered["total_goals"] = men_filtered["home_score"] + men_filtered["away_score"]
women_filtered["total_goals"] = women_filtered["home_score"] + women_filtered["away_score"]
# Create a single plot with two subplots for histograms
fig, axes = plt.subplots(1, 2, figsize=(12, 6), sharey=True)
# Plot histogram for men's data
axes[0].hist(men_filtered["total_goals"], bins=10, color='blue', edgecolor='black', alpha=0.7)
axes[0].set_title('Men\'s FIFA World Cup Goal Distribution')
axes[0].set_xlabel('Total Goals')
axes[0].set_ylabel('Frequency')
axes[0].grid(True)
# Plot histogram for women's data
axes[1].hist(women_filtered["total_goals"], bins=10, color='orange', edgecolor='black', alpha=0.7)
axes[1].set_title('Women\'s FIFA World Cup Goal Distribution')
axes[1].set_xlabel('Total Goals')
axes[1].set_ylabel('Frequency')
axes[1].grid(True)
# Adjust layout for better spacing
plt.tight_layout()
plt.show()
# Combine data for the hypothesis test
combined_df = pd.concat([women_filtered, men_filtered], ignore_index=True)
# Prepare data for test
test_data = combined_df[["total_goals", "category"]]
test_data_wide = test_data.pivot(columns="category", values="total_goals")
# Perform Mann-Whitney U test from pingouin package
test_result_pg = pg.mwu(x=test_data_wide["women"], y=test_data_wide["men"], alternative="greater")
# Extract p-value
p_value = test_result_pg["p-val"].values[0]
# Hypothesis test result
hypothesis_result = "reject" if p_value <= 0.01 else "fail to reject"
result_summary = {"p_value": p_value, "hypothesis_result": hypothesis_result}