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.

# Start your code here!
import pandas as pd
import numpy as np
from scipy.stats import t
import matplotlib as plt
import seaborn as sns
import pingouin as pg
from scipy.stats import shapiro, normaltest, kstest

# Reading the csv files
df_w = pd.read_csv('women_results.csv')
df_m = pd.read_csv('men_results.csv')

# Filtering the matches that are 2002-01-01 at the earliest and not a qualification match
not_qualification = ['Euro', 'AFC Championship',
       'OFC Championship', 'UEFA Euro', 'African Championship',
       'CONCACAF Championship', 'Copa América', 'FIFA World Cup',
       'CONCACAF Invitational Tournament', 'Algarve Cup', 'Olympic Games',
       'Four Nations Tournament',
       'CONCACAF Gold Cup', 'AFC Asian Cup', 'Cyprus Cup', 'Friendly', 'SheBelieves Cup',
       'Tournament of Nations',
       'African Cup of Nations',
       'OFC Nations Cup', 'Tournoi de France',
       "Basque Country Women's Cup"]

df_w_filtered = df_w[(df_w['date'] >= '2002-01-01') & (df_w['tournament'] == 'FIFA World Cup')]
df_m_filtered = df_m[(df_m['date'] >= '2002-01-01') & (df_m['tournament'] == 'FIFA World Cup')]

# Calculating the mean of total goals in women and men matches
df_w_filtered['total_goals'] = df_w_filtered['home_score'] + df_w_filtered['away_score']
w_mean_goals = df_w_filtered['total_goals'].mean()

df_m_filtered['total_goals'] = df_m_filtered['home_score'] + df_m_filtered['away_score']
m_mean_goals = df_m_filtered['total_goals'].mean()

x_bar_women = w_mean_goals
x_bar_men = m_mean_goals

s_w = df_w_filtered['total_goals'].std()
s_m = df_m_filtered['total_goals'].std()

n_w = len(df_w_filtered['total_goals'])
n_m = len(df_m_filtered['total_goals'])

numerator = x_bar_women - x_bar_men
denominator = np.sqrt(s_w ** 2/n_w + s_m ** 2/n_m)
t_stat = numerator/denominator

dof = n_w + n_m - 2

p_val = 1 - t.cdf(t_stat, df=dof)

result_dict = {'p_val': p_val, 'result': result}

result = pg.ttest(df_w_filtered['total_goals'], 
                  df_m_filtered['total_goals'], 
                  alternative='greater')

stat, p_value = normaltest(df_m_filtered['total_goals'])  
print(f"D'Agostino: statistic={stat:.4f}, p-value={p_value:.4f}")