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 pingouin
# Import both .csv files
# Import men_results.csv; parse for date format
men_results = pd.read_csv('men_results.csv', parse_dates = ['date'])
# Import women_results.csv; parse for date format
women_results = pd.read_csv('women_results.csv', parse_dates = ['date'])
# Adding a gender column to both tables
men_results['Sex'] = 'M'
women_results['Sex'] = 'W'
# Display men's results
display(men_results.info())
display(men_results.head())
display(men_results.shape)
# Display women's results
display(women_results.info())
display(women_results.head())
display(women_results.shape)
# Combining both tables into one
results = pd.concat([men_results, women_results], ignore_index=True, sort='date')
# Total goals scored per game
results['total_score'] = results['home_score'] + results['away_score']
# Filter for requirements
res_fil = results[(results['date'] > '2002-01-01') & (results['tournament'] == 'FIFA World Cup')]
# Display results
display(res_fil.info())
display(res_fil.head())
display(res_fil.shape)
# Visualising distribution to decide on parametric or non-parametric test
res_plot = sns.histplot(data = res_fil, x='total_score', binwidth=1, hue = 'Sex').set_title('Total Goals Scored per Game')
print("Data does not exibit a bell-shaped distribution, therefore, it has shown to not follow normal distribution as data skews to the left. Will use a non-parametric test.")
# Now that we know that both of our sets of data was non-normally distributed, we'll use a Wilcoxon-Mann-Whitney test to find a p-value.
# First, we'll subset the data for the appropriate columns
res_fil2 = res_fil[['Sex', 'total_score']]
# Pivoting the table into a wide format
res_wide = res_fil2.pivot(columns='Sex', values='total_score')
display(res_wide)
# Wilcoxon-Mann-Whitney test
# Women go first as they are suspected to have a greater mean. The alternative is that women score more.
wmw_test = pingouin.mwu(x = res_wide['W'], y = res_wide['M'], alternative='greater')
print(wmw_test)
# Results dictionary
# Inference statistical parameters
alpha = 0.01
p_val = float(wmw_test['p-val'])
print(p_val)
# Logical test for comnparing p-value to significance level alpha
if p_val >= alpha:
print('fail to reject')
else:
print('reject')
# Setting the result to the conclusion of the above if-else statement
result = "reject"
# Results of the test in the format of the question
result_dict = {"p_val": p_val, "result": result}
print(result_dict)