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:
Project Instructions
Perform an appropriate hypothesis test to determine the p-value, and hence result, of whether to reject or fail to reject the null hypothesis that the mean number of goals scored in women's international soccer matches is the same as men's. Use a 10% significance level.
- For this analysis, you'll use Official FIFA World Cup matches since 2002-01-01, and you'll also assume that each match is fully independent, i.e., team form is ignored.
- The p-value and the result of the test must be stored in a dictionary called result_dict in the form:
result_dict = {"p_val": p_val, "result": result}
where p_val is the p-value and result is either the string "fail to reject" or "reject", depending on the result of the test.
import pandas as pd
import matplotlib.pyplot as plt
import pingouin as pg
from scipy.stats import mannwhitneyu
# Load men's and women's datasets
men_results = pd.read_csv('men_results.csv', parse_dates=["date"])
women_results = pd.read_csv('women_results.csv', parse_dates=["date"])
men_results.info()
women_results.info()
# Filter the data for the time range and tournament
men_results_FIFA = men_results[men_results['tournament'] == 'FIFA World Cup']
women_results_FIFA = women_results[women_results['tournament'] == 'FIFA World Cup']
men_subset = men_results_FIFA[men_results_FIFA['date'] > '2002-01-01']
women_subset = women_results_FIFA[women_results_FIFA['date'] > '2002-01-01']
# 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"]
# Determine normality using histograms
men_subset["goals_scored"].hist()
plt.show()
plt.clf()
# Combine women's and men's data and calculate goals scored in each match
both = pd.concat([women_subset, men_subset], axis=0, ignore_index=True)
# Transform the data for the pingouin Mann-Whitney U t-test/Wilcoxon-Mann-Whitney test
both_subset = both[["goals_scored", "group"]]
print(both_subset)
both_subset_wide = both_subset.pivot(columns="group", values="goals_scored")
print(both_subset_wide)
# Perform right-tailed Wilcoxon-Mann-Whitney test with pingouin
results_pg = pg.mwu(x=both_subset_wide["women"],
y=both_subset_wide["men"],
alternative="greater")
# Extract p-value as a float
p_val = results_pg["p-val"].values[0]
# Determine hypothesis test result using sig. level
if p_val <= 0.01:
result = "reject"
else:
result = "fail to reject"
result_dict = {"p_val": p_val, "result": result}
print(result_dict)