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 pandas as pd
import datetime as dt
import numpy as np
import matplotlib.pyplot as plt
df_m = pd.read_csv('men_results.csv')
df_w = pd.read_csv('women_results.csv')
# Parse date column
df_m['date'] = pd.to_datetime(df_m['date']).dt.strftime('%Y-%m-%d')
df_w['date'] = pd.to_datetime(df_w['date']).dt.strftime('%Y-%m-%d')
# Slice data as per conditions
df_m = df_m[(df_m['tournament'] == "FIFA World Cup") & (df_m['date'] >= "2002-01-01")]
df_w = df_w[(df_w['tournament'] == "FIFA World Cup") & (df_w['date'] >= "2002-01-01")]
# Summarize
df_m['total_score'] = np.sum([df_m['home_score'], df_m['away_score']], axis=0)
df_w['total_score'] = np.sum([df_w['home_score'], df_w['away_score']], axis=0)
df_m_mean = np.mean(df_m['total_score'])
df_w_mean = np.mean(df_w['total_score'])
# Compute difference of means (Observed Test Statistic)
diff_of_means_observed = df_w_mean - df_m_mean
# Reshape
df_m = df_m.drop(['home_score', 'away_score'], axis=1)
df_w = df_w.drop(['home_score', 'away_score'], axis=1)
# Compute combined mean to normalise datasets
combined_mean = (df_m_mean + df_w_mean) / 2
# new arrays to perform bootstrap on
men_shifted = (df_m['total_score'] - df_m_mean) + combined_mean
women_shifted = (df_w['total_score'] - df_w_mean) + combined_mean
# Write function call signature for bootstrapping
def draw_bs_reps(data, func, size=1):
bs_replicates = np.empty(size)
for i in range(size):
bs_replicates[i] = func(np.random.choice(data.ravel(), len(data)))
return bs_replicates
# Acquire 10000 replicates of means
replicates_m = draw_bs_reps(men_shifted, np.mean, size=10000)
replicates_w = draw_bs_reps(women_shifted, np.mean, size=10000)
# Compute difference of means for replicates (Sample Test Statistic)
diff_of_means_reps = replicates_w - replicates_m
# Compute p-value(
p_val = np.sum(diff_of_means_reps >= diff_of_means_observed)/len(diff_of_means_reps)
if p_val <= 0.01:
result = "reject"
else:
result = "fail to reject"
result_dict = {"p_val": p_val, "result": result}
print(result_dict)