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 libraries
import pandas as pd
import matplotlib.pyplot as plt
import pingouin
# Load datasets
men_results = pd.read_csv("men_results.csv", index_col=0, parse_dates=["date"])
women_results = pd.read_csv("women_results.csv", index_col=0, parse_dates=["date"])
# Filter DataFrames
men_filtered = men_results[
(men_results["tournament"] == "FIFA World Cup") & (men_results["date"] > "2002-01-01")
]
women_filtered = women_results[
(women_results["tournament"] == "FIFA World Cup") & (women_results["date"] > "2002-01-01")
]
# Create group and total_goal columns
men_filtered["group"] = "men"
men_filtered["total_goals"] = men_filtered["home_score"] + men_filtered["away_score"]
women_filtered["group"] = "women"
women_filtered["total_goals"] = women_filtered["home_score"] + women_filtered["away_score"]
# Determine normality using histograms
# Check normality of total goals distribution for each group
men_filtered["total_goals"].hist()
plt.title("Distribution of Total Goals (Men's World Cup)")
plt.show()
women_filtered["total_goals"].hist()
plt.title("Distribution of Total Goals (Women's World Cup)")
plt.show()
# Total scores not normally distributed, use Wilcoxon-Mann-Whitney test
# Set significance level
alpha = 0.01
# Combine data
combined_data = pd.concat([men_filtered, women_filtered], axis=0, ignore_index=True)
# Transform data
goal_data = combined_data[["group", "total_goals"]]
goal_data_pivot = goal_data.pivot(columns="group", values="total_goals")
# Perform right-tailed Wilcoxon-Mann-Whitney test with pingouin
result_mwu = pingouin.mwu(
x=goal_data_pivot["women"],
y=goal_data_pivot["men"],
alternative="greater",
)
# Extract p-values
p_val = result_mwu["p-val"].values[0]
# Determine hypothesis test result
if p_val <= alpha:
result = "reject"
else:
result = "fail to reject"
# Create a dictionary to store results
result_dict = {"p_val": p_val, "result": result}
print(result_dict)