Hypothesis Testing with Men's and Women's Soccer Matches
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:
Load data
# Import libraries
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import pingouin
from scipy.stats import mannwhitneyu
# Load data
men = pd.read_csv('men_results.csv')
women = pd.read_csv('women_results.csv')Clean data
# Convert date data type
men['date'] = pd.to_datetime(men['date'])
women['date'] = pd.to_datetime(women['date'])
# Filter data
men_subset = men[(men['date'] >= '2002-01-01') & (men['tournament'].isin(['FIFA World Cup']))]
women_subset = women[(women['date'] >= '2002-01-01') & (women['tournament'].isin(['FIFA World Cup']))]
# Add gender and total goals column
men_subset['gender'] = 'men'
women_subset['gender'] = 'women'
men_subset['total_goals'] = men_subset['home_score'] + men_subset['away_score']
women_subset['total_goals'] = women_subset['home_score'] + women_subset['away_score']Statistical exploration
# Determine if the distribution is normal
sns.countplot(data=men_subset, x='total_goals', color='blue', alpha=1)
plt.title('Men total goals per match')
plt.show()
sns.countplot(data=women_subset, x='total_goals', color='pink', alpha=1)
plt.title('Women total goals per match')
plt.show()We can notice that the distribution is not gaussian so we should use the Wilcoxon-Mann-Whitney test of two groups instead of the t-test.
Data preparation for statistical analysis
# Gather both dataframe in a new dataframe
both = pd.concat([men_subset, women_subset], axis=0, ignore_index=True)
# Prepare the data for the WMW test
both_subset = both[['gender', 'total_goals']]
print(both_subset)# Pivot the data for the WMW test
both_subset_wide = both_subset.pivot(columns='gender', values='total_goals')
print(both_subset_wide)Statistical analysis
# Perform right-tailed Wilcoxon-Mann-Whitney test with 'greater' alternative
stat_results = pingouin.mwu(x=both_subset_wide['men'], y=both_subset_wide['women'], alternative='greater')
print(stat_results)# Verify the hypothesis
p_val = stat_results['p-val'].values[0]
significance = 0.1
if p_val <= significance:
result = 'reject'
else:
result = 'fail to reject'
result_dict = {"p_val": p_val, "result": result}
print(result_dict)