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:
# Start your code here!
import pandas as pd# Imports
import matplotlib.pyplot as plt
import pingouin as pg
from scipy.stats import mannwhitneyu
# Load men's and women's datasets
men = pd.read_csv("men_results.csv")
women = pd.read_csv("women_results.csv")
# Filter the data for the time range and tournament
men["date"] = pd.to_datetime(men["date"])
men_subset = men[(men["date"] > "2002-01-01") & (men["tournament"] == "FIFA World Cup")]
women["date"] = pd.to_datetime(women["date"])
women_subset = women[(women["date"] > "2002-01-01") & (women["tournament"] == "FIFA World Cup")]
# Create group and goals_scored columns
men_subset["group"] = "men"
women_subset["group"] = "women"
men_subset["goals_scored"] = men_subset["home_score"] + men_subset["away_score"]
women_subset["goals_scored"] = women_subset["home_score"] + women_subset["away_score"]
# Combine the datasets for further analysis
both = pd.concat([women_subset, men_subset], axis=0, ignore_index=True)
# Visualize the distribution of goals scored for men and women
plt.hist(men_subset["goals_scored"], alpha=0.7, label="Men", bins=10, color="blue", edgecolor="black")
plt.hist(women_subset["goals_scored"], alpha=0.7, label="Women", bins=10, color="orange", edgecolor="black")
plt.xlabel("Goals Scored")
plt.ylabel("Frequency")
plt.title("Goals Scored Distribution in Men's and Women's FIFA World Cup Matches")
plt.legend()
plt.show()
# Perform the Wilcoxon-Mann-Whitney test with pingouin
results_pg = pg.mwu(x=women_subset["goals_scored"],
y=men_subset["goals_scored"],
alternative="greater")
# Perform the same test with SciPy for verification
results_scipy = mannwhitneyu(x=women_subset["goals_scored"],
y=men_subset["goals_scored"],
alternative="greater")
# Extract the p-value
p_val = results_pg["p-val"].values[0]
# Determine the result of the hypothesis test
significance_level = 0.10 # 10% significance level
result = "reject" if p_val <= significance_level else "fail to reject"
# Store results in a dictionary
result_dict = {"p_val": p_val, "result": result}
# Output the result
print("Results from pingouin:")
print(result_dict)
print("\nResults from SciPy:")
print({"p_val": results_scipy.pvalue, "result": "reject" if results_scipy.pvalue <= significance_level else "fail to reject"})