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 pandas as pd
import matplotlib.pyplot as plt
from scipy.stats import mannwhitneyu
# read csv
df_men = pd.read_csv('men_results.csv', parse_dates=['date'])
df_women = pd.read_csv('women_results.csv', parse_dates=['date'])
# filter for matches
def filter_for_matches(df):
"""Filter for FIFA World Cup matches from 2002 onwards."""
mask_1 = df['tournament'] == 'FIFA World Cup'
mask_2 = df['date'] >= '2002-01-01'
return df[mask_1 & mask_2]
f_men = filter_for_matches(df_men)
f_women = filter_for_matches(df_women)
# calcualte total goals
f_men['total_score'] = f_men['home_score'] + f_men['away_score']
f_women['total_score'] = f_women['home_score'] + f_women['away_score']
print(f_men[['home_team', 'away_team', 'home_score', 'away_score', 'total_score']].head())
# create histograms
fig, axes = plt.subplots(1, 2, figsize=(14, 5))
# men's distribution
axes[0].hist(f_men['total_score'], bins=10, edgecolor='black', alpha=0.7)
axes[0].set_title("Men's World Cup - Total Goals Distribution")
axes[0].set_xlabel('Total Score per Match')
axes[0].set_ylabel('Frequency')
axes[0].axvline(f_men['total_score'].mean(), color='red', linestyle='--',
linewidth=2, label=f"Mean: {f_men['total_score'].mean():.2f}")
axes[0].legend()
# women's distribution
axes[1].hist(f_women['total_score'], bins=10, edgecolor='black', alpha=0.7, color='orange')
axes[1].set_title("Women's World Cup - Total Goals Distribution")
axes[1].set_xlabel('Total Score per Match')
axes[1].set_ylabel('Frequency')
axes[1].axvline(f_women['total_score'].mean(), color='red', linestyle='--',
linewidth=2, label=f"Mean: {f_women['total_score'].mean():.2f}")
axes[1].legend()
plt.tight_layout()
plt.show()
# test normality of distribution
alpha_normality = 0.05
stat_men, p_men_norm = stats.shapiro(f_men['total_score'])
stat_women, p_women_norm = stats.shapiro(f_women['total_score'])
print("Normality Check")
print(f"Men's p-value: {p_men_norm:.7f} → {'Normal' if p_men_norm > alpha else 'NOT Normal'}")
print(f"Women's p-value: {p_women_norm:.7f} → {'Normal' if p_women_norm > alpha else 'NOT Normal'}")
print()
if p_men_norm <= alpha_normality or p_women_norm <= alpha_normality:
print("→ At least one distribution is NOT normal")
print("→ Using Mann-Whitney U test (non-parametric)")
else:
print("→ Both distributions are normal")
print("→ Could use t-test, but Mann-Whitney also works")
# perform hypothesis test
print("Hypotheses:")
print(" H₀: There is no difference in goals scored")
print(" H₁: Men's World Cup has MORE goals than Women's World Cup")
print(f" Significance level: α = {alpha}\n")
alpha = 0.01
result=""
# Perform Mann-Whitney U test
result_hyp = mannwhitneyu(
x=f_women['total_score'],
y=f_men['total_score'],
alternative='greater' # One-tailed: women's > men's
)
p_val = result_hyp.pvalue
print("Decision")
if p_val <= alpha:
print(f"✓ Reject H₀ (p = {p_val:.6f} ≤ α = {alpha})")
result='reject'
print()
print("Conclusion:")
print(f"There IS a statistically significant difference.")
print(f"Men's World Cup matches have MORE goals than Women's World Cup.")
else:
print(f"✗ Fail to reject H₀ (p = {p_value:.6f} > α = {alpha})")
result='fail to reject'
print()
print("CONCLUSION:")
print(f"There is NO statistically significant difference in goals scored.")
result_dict = {
"p_val": p_val,
"result": result
}