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 matplotlib.pyplot as plt
import seaborn as sns
import pingouin
from scipy.stats import mannwhitneyu
men = pd.read_csv('men_results.csv')
women = pd.read_csv('women_results.csv')
men.info()
women.info()#view of dataset
men.head()
women.head()# For men's dataset
print("Value counts for men's dataset:")
for col in ['home_team', 'away_team', 'tournament']:
print(f'/nColumn: {col}')
print(men[col].value_counts())
# For women's dataset
print("Value counts for women's dataset:")
for col in ['home_team', 'away_team', 'tournament']:
print(f'/nColumn: {col}')
print(women[col].value_counts())#filter the Data of FIFA after 2002-01-01
men['date'] = pd.to_datetime(men['date'])
women['date'] = pd.to_datetime(women['date'])
men_subset = men[(men['date']>'2002-01-01') & (men['tournament'].isin(['FIFA World Cup']))]
women_subset = women[(women['date']>'2002-01-01') & (women['tournament'].isin(['FIFA World Cup']))]#add columns in subset to identify men and women
men_subset['group']="men"
women_subset['group']="women"
men_subset["goals_scored"]=men_subset["home_score"]+men_subset["away_score"]
women_subset["goals_scored"]=women_subset["home_score"]+women_subset["away_score"]# Visualizing Goals Distribution
men_subset["goals_scored"].hist()
plt.show()
plt.clf()
women_subset["goals_scored"].hist()
plt.show()
plt.clf()# Normality CHeck -Goals scored is not normally distributed, so use Wilcoxon-Mann-Whitney test
# Combine Data for Comparison
both = pd.concat([women_subset,men_subset], axis=0,ignore_index=True)
both_subset= both[['goals_scored','group']]
both_subset_wide=both_subset.pivot(columns='group',values='goals_scored')
# Plot boxplot
plt.figure(figsize=(8, 6))
sns.boxplot(x='group', y='goals_scored', data=both)
plt.title('Goals Scored in FIFA World Cup Matches (Women vs Men)')
plt.xlabel('Group')
plt.ylabel('Goals Scored')
plt.show()#Statistical Testing
# Wilcoxon-Mann-Whitney U test
results_pg=pingouin.mwu(x=both_subset_wide['women'],y=both_subset_wide['men'],alternative='greater')
#alternative="greater" tests if women's goals are statistically greater than men's.
p_val=results_pg['p-val'].values[0]
print("P-value:", p_val)#Interpreting the result of the hypothesis test
if p_val <= 0.01:
result="reject"
else:
result="fail to reject"
result_dict = {"p_val": p_val, "result": result}
print(result_dict)