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:
# importing necessary libraries
import pandas as pd
import numpy as np
import scipy.stats as sc
import matplotlib.pyplot as plt
import seaborn as sns
# explore men's data
m_results = pd.read_csv('men_results.csv', parse_dates=['date'])
m_results.info()
# explore women's data
w_results = pd.read_csv('women_results.csv', parse_dates=['date'])
w_results.info()
# filtering men's tournaments
m_results_fifa = m_results.loc[(m_results['tournament'] == 'FIFA World Cup') & (m_results['date'] >= '2002-01-01')]
# filtering women's tournaments
w_results_fifa = w_results.loc[(w_results['tournament'] == 'FIFA World Cup') & (w_results['date'] >= '2002-01-01')]
# sample sizes and normality checks
m_results_fifa['total_score'] = m_results_fifa['home_score'] + m_results_fifa['away_score']
w_results_fifa['total_score'] = w_results_fifa['home_score'] + w_results_fifa['away_score']
sns.histplot(x='total_score', data=m_results_fifa, label='Man\'s matches')
sns.histplot(x='total_score', data=w_results_fifa, label='Women\'s matches')
plt.xlabel('number of goals')
plt.ylabel('number of matches')
plt.legend()
plt.show()
norm_alpha = 0.05
stat_m, p_m = sc.shapiro(m_results_fifa.total_score)
stat_w, p_w = sc.shapiro(m_results_fifa.total_score)
print(f'P-value for men\'s soccer matches scores is:{p_m:.3f}.\nP-value for women\'s soccer matches scores is:{p_w:.3f}.\nBoth p-values less than 0.5, so, samples are not normaly distributed.')
# hypothesis testing
m_data = m_results_fifa['total_score']
w_data = w_results_fifa['total_score']
stat, p = sc.mannwhitneyu(w_data, m_data, alternative='greater')
print('stat=%.2f, p=%.2f' % (stat, p))
if p > 0.1:
print('Probably the same distribution')
else:
print('The distributions are different')
m_av = np.mean(m_data)
w_av = np.mean(w_data)
diff = w_av - m_av
print(f'On average, women\'s FIFA soccer matches have {w_av:.2f} goals, man\'s - {m_av:.2f}, which is {diff:.2f} goals more per match.')
result_dict = {"p_val": p, "result": "reject"}