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 necessary libraries
import pandas as pd
import numpy as np
from scipy.stats import t, shapiro
import pingouin as pg
import matplotlib.pyplot as plt # For visualization
# Load men's football results and filter for matches from 2002 onwards (modern era)
men_df = pd.read_csv("men_results.csv")
men_df = men_df[men_df["date"] >= '2002-01-01']
# Load women's football results and filter for matches from 2002 onwards
women_df = pd.read_csv("women_results.csv")
women_df = women_df[women_df["date"] >= '2002-01-01']
# Calculate total goals scored in each match
men_df["goals_scored"] = men_df["home_score"] + men_df["away_score"]
women_df["goals_scored"] = women_df["home_score"] + women_df["away_score"]
# Filter to only FIFA World Cup matches to keep tournament type consistent
men_df = men_df[men_df["tournament"] == 'FIFA World Cup']
women_df = women_df[women_df["tournament"] == 'FIFA World Cup']
# Plot histogram to visually compare the goal distributions
plt.hist(men_df["goals_scored"], alpha=0.7, label="Men")
plt.hist(women_df["goals_scored"], alpha=0.7, label="Women")
plt.legend()
plt.title("Goals Scored per Match (FIFA World Cup since 2002)")
plt.xlabel("Goals")
plt.ylabel("Number of Matches")
plt.grid(True)
plt.tight_layout()
plt.show()
# Manual t-test calculation (not used due to non-normality)
x_bar_men = men_df["goals_scored"].mean()
x_bar_women = women_df["goals_scored"].mean()
n_men = len(men_df)
n_women = len(women_df)
std_men = men_df["goals_scored"].std(ddof=1)
std_women = women_df["goals_scored"].std(ddof=1)
numerator = x_bar_women - x_bar_men
denominator = np.sqrt((std_men**2 / n_men) + (std_women**2 / n_women))
t_test = numerator / denominator
# Degrees of freedom (used in manual t-test, though Welch's df not applied here)
df = (n_men + n_women)
# One-tailed p-value assuming normality (for reference only)
p_val = 1 - t.cdf(t_test, df=df)
alpha = 0.1
if p_val < alpha:
result = "reject"
else:
result = "fail to reject"
result_dict = {"p_val": p_val, "result": result}
# Display manual t-test result
print("this value would be true if the data was normally distributed")
print("wrong p_value using manual calculations : ", result_dict)
# Now we perform the correct test (non-parametric) due to non-normal distribution
# Add group labels for combining datasets
men_df['group'] = 'men'
women_df['group'] = 'women'
# Combine both groups into one DataFrame
combined_df = pd.concat([men_df[['goals_scored', 'group']], women_df[['goals_scored', 'group']]])
# Perform Mann-Whitney U test (non-parametric alternative to independent t-test)
# We use this because the goal data is not normally distributed
ttest_result = pg.mwu(
x=combined_df[combined_df['group'] == 'women']['goals_scored'],
y=combined_df[combined_df['group'] == 'men']['goals_scored'],
alternative="greater" # Test whether women score more than men
)
# Update result_dict with the correct p-value from the Mann-Whitney test
result_dict["p_val"] = ttest_result['p-val'][0]
print("p_value using pingouin calculations : ", result_dict)