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
import seaborn as sns
import matplotlib.pyplot as plt
import pingouin
pd.set_option('display.max_columns', None)
sns.set(style="darkgrid")
# Load the female players data and check the first few rows
women = pd.read_csv('women_results.csv')
print(women.head())
# Load in the male players data
men = pd.read_csv('men_results.csv')
print(men.head())
# Exploratory data analysis
# Get more information about the female players
women.info()
# Get more information about male players
men.info()
# Check the value counts in the tournament column
women.tournament.value_counts()
# Convert date column to datetime
women.date = pd.to_datetime(women.date)
men.date = pd.to_datetime(men.date)
# Filtering data for FIFA World Cup matches after 2002-01-01
women_fifa = women.loc[(women.tournament == 'FIFA World Cup') & (women.date > '2002-01-01')]
men_fifa = men.loc[(men.tournament == 'FIFA World Cup') & (men.date > '2002-01-01')]
print(women_fifa.head())
print(women_fifa.shape, men_fifa.shape)
# Create group and scores columns
women_fifa['group'] = 'women'
men_fifa['group'] = 'men'
women_fifa['scores'] = women_fifa['home_score'] + women_fifa['away_score']
men_fifa['scores'] = men_fifa['home_score'] + men_fifa['away_score']
# Determine normality using histograms
fig, axes = plt.subplots(1, 2, figsize=(10,5))
sns.histplot(data=women_fifa, x='scores', ax=axes[0])
sns.histplot(data=men_fifa, x='scores', ax=axes[1])
axes[0].set_title('Distribution of scores for women ')
axes[1].set_title('Distribution of scores for men')
plt.show()
Results show that the parametric assumption of a normal distribution is not met, so we need to use a non-parametric test. The data is unpaired, so we use the Wilcoxon Mann Whitney test.
# Combine women"s and men"s data and calculate goals scored in each match
fifa = pd.concat([women_fifa, men_fifa], axis=0, ignore_index=True)
print(fifa.head())
# Transform the data for the pingouin Mann-Whitney U t-test
fifa_subset = fifa[['scores', 'group']]
fifa_subset_wide = fifa_subset.pivot(columns='group', values='scores')
# Perform right-tailed Wilcoxon-Mann-Whitney test with pingouin
results = pingouin.mwu(x=fifa_subset_wide['women'],
y=fifa_subset_wide['men'],
alternative='greater')
print(results)