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:
# Import the necessary libraries
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import pingouin as pg
from scipy.stats import shapiro
# Load the women results and display the info
women = pd.read_csv('women_results.csv')
women.info()
# Load the men results and display the info
men = pd.read_csv('men_results.csv')
men.info()
# Convert the date columns to datetime data type
women['date'] = pd.to_datetime(women['date'])
men['date'] = pd.to_datetime(men['date'])
# Add a goals column that contains the total number of goals
women['goals'] = women['home_score'] + women['away_score']
men['goals'] = men['home_score'] + men['away_score']
# Filter both DataFrames for the given tournament and date
filtered_women = women[(women['tournament'] == 'FIFA World Cup') & (women['date'] >= '2002-01-01')]
filtered_men = men[(men['tournament'] == 'FIFA World Cup') & (men['date'] >= '2002-01-01')]
# Set the scale
sns.set_context('notebook')
# Plot the distribution of goals to check for normality
women_plot = sns.histplot(data=filtered_women, x='goals', bins=10, color='darkblue')
# Add a title
women_plot.set_title ("Distribution of Goals in Women's Matches", y=1.05, fontweight='bold')
# Add axis labels
women_plot.set(xlabel='Total goals', ylabel='Frequency')
# Show the plot
plt.show()
# Plot the distribution of goals to check for normality
men_plot = sns.histplot(data=filtered_men, x='goals', bins=10, color='darkblue')
# Add a title
men_plot.set_title ("Distribution of Goals in Men's Matches", y=1.05, fontweight='bold')
# Add axis labels
men_plot.set(xlabel='Total goals', ylabel='Frequency')
# Show the plot
plt.show()
# Perform Shapiro-Wilk test for normality on the goals column for both datasets
stat_women, p_women = shapiro(filtered_women['goals'])
stat_men, p_men = shapiro(filtered_men['goals'])
# Display the results
stat_women, p_women, stat_men, p_men
# Define the significance level
alpha = 0.10
# Use Wilcoxon-Mann-Whitney test since the distributions are not normal
mwu_results = pingouin.mwu(x=filtered_women['goals'], y=filtered_men['goals'], alternative='greater')
# Display the results
mwu_results
# Get the p-value from the results
p_val = mwu_results['p-val'].values[0]
p_val
# Assign the appropriate strings to result
result = 'reject' if p_val <= alpha else 'fail to reject'
# Store the result in a dictionary as required for the project submission
result_dict = {'p_val' : p_val, 'result' : result}