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 required libraries
import pandas as pd
import numpy as np
import seaborn as sns
import pingouin as pg# Load dataframes
men = pd.read_csv("men_results.csv", parse_dates=["date"])
women = pd.read_csv("women_results.csv", parse_dates=["date"])# Preview men dataframe
men.head()# Preview men dataframe
women.head()# Check both dataframe info
men.info()
women.info()# Subset both dataframes to only include official FIFA World Cup matches that took place after 2002-01-01
men.query('tournament == "FIFA World Cup" and date > "2002-01-01"', inplace=True)
women.query('tournament == "FIFA World Cup" and date > "2002-01-01"', inplace=True)# Check both dataframe info
men.info()
women.info()# Add a total_goals column in each dataframe
men['total_goals'] = men['home_score'] + men['away_score']
women['total_goals'] = women['home_score'] + women['away_score']# Plot an histgram to see if the data is normally distributed
plt.figure(figsize=(10, 6))
sns.histplot(data=women, x='total_goals', label='Women', alpha=0.5)
sns.histplot(data=men, x='total_goals', label='Men', alpha=0.5)
plt.title('Distribution of Total Goals per Match')
plt.legend()
plt.show()# As the data is not normally distributed, perform a two-sided Wilcoxon-Mann-Whitney test
wmw_test = pg.mwu(women['total_goals'], men['total_goals'], alternative='greater')
print(wmw_test)# Extract p-value from wmw_test
p_val = wmw_test['p-val'].iloc[0]
# Define significance level
alpha = 0.10
# Determine the result
result = "reject" if p_val < alpha else "fail to reject"
# Store results in a dictionary
result_dict = {"p_val": p_val, "result": result}
print(result_dict)