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
men = pd.read_csv('men_results.csv')
women = pd.read_csv('women_results.csv')
women = women[(women['tournament'] == 'FIFA World Cup') &
( women['date'] >= '2002-01-01')]
women.head()
men = men[(men['tournament'] == 'FIFA World Cup') &
( men['date'] >= '2002-01-01')]
men.head()
# union dataframes
footbal = pd.concat([men, women], keys=['men', 'women'], axis=0)
footbal['total_score'] = footbal['home_score'] + footbal['away_score']
footbal.reset_index(inplace=True)
footbal.rename(columns={'level_0': 'gender'}, inplace=True)
footbal.head()
Determining suitable hypothesis test
import seaborn as sns
sns.countplot(data=footbal, x='total_score', hue='gender')
Shapiro-Wilk Test to determine normality
import numpy as np
from scipy.stats import shapiro
from scipy.stats import lognorm
#make this example reproducible
np.random.seed(1)
#perform Shapiro-Wilk test for normality
norm_men = shapiro(footbal[footbal['gender']=='men']['total_score'])
norm_women = shapiro(footbal[footbal['gender']=='women']['total_score'])
print(norm_men, norm_women)
p-value is close to 0 --> the distribution is not normal
import pingouin
# converting to wide format
footbal_wide = footbal.pivot(columns='gender', values='total_score')
footbal_wide.head()