Skip to content

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:

: The mean number of goals scored in women's international soccer matches is the same as men's.

: The mean number of goals scored in women's international soccer matches is greater than men's.

# Importing libraries
import pandas as pd
import numpy as np

# Visualization
import matplotlib.pyplot as plt
import seaborn as sns
# Loading data
# Men's data
men_df=pd.read_csv('men_results.csv',index_col=0,parse_dates=['date'])
men_fil=men_df[(men_df['date']>='2002-01-01') & (men_df["tournament"].isin(["FIFA World Cup"]))] # Filtering by the dates of interest
men_fil['tot_goals']=men_fil['home_score']+men_fil['away_score'] # Total goals variable

# Women's data
women_df=pd.read_csv('women_results.csv',index_col=0,parse_dates=['date'])
women_fil=women_df[(women_df['date']>='2002-01-01') & (women_df['tournament'].isin(["FIFA World Cup"]))] # Filtering by the dates of interest
women_fil['tot_goals']=women_fil['home_score']+women_fil['away_score'] # Total goals variable

print(f"Men's\nObs:{len(men_fil)}\nCols:{men_fil.columns}")
print(f"Women's\nObs:{len(women_fil)}\nCols:{women_fil.columns}")
fix, ax = plt.subplots()
ax.hist(men_fil['tot_goals'],color='darkblue',alpha=0.5)
ax.hist(women_fil['tot_goals'],color='darkgreen',alpha=0.5)
plt.show()

Both distribitions has not look like normal distribution, they have right skweness. However because of number of match with low scores looks like men score less goals than women.

Lest prove it using hypothesis testing!

Since none distributions has normal distribution, we should use non-parametric tests.

# Performance non-parametric tests.
from pingouin import mwu # Non-parametris test with unpaired data
from scipy.stats import mannwhitneyu

u_stat,u_pval=mannwhitneyu(x=women_fil['tot_goals'],y=men_fil['tot_goals'],alternative='greater')
print("Critical Value:",u_stat,"p-value: ",u_pval)
# Condition for hypothesis testing
if u_pval<=0.1:
    result='reject'
else:
    result='fail to reject'
# Store results
print(f"Given a 10% significance level, we {result} the null hypothesis that both, men and women, score the same mean number of goals in international matches in favor to the alternative hypothesis that the mean number of goals in women's international matches is greater than mens.")
result_dict = {"p_val": u_pval, "result": result}