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 pingouin
import matplotlib.pyplot as plt
#Create dataframes from the csv files
women_results = pd.read_csv('women_results.csv', parse_dates=['date'])
men_results = pd.read_csv('men_results.csv', parse_dates=['date'])
#Explore women dataframe
women_results.info()
print(women_results['tournament'].value_counts())
#Select the 4 relevant columns and only official FIFA World Cup matches from '2002-01-01' upwards
women_results_since_2002 = women_results[['date','home_score', 'away_score', 'tournament']].query('date>"2002-01-01" and tournament == "FIFA World Cup"')
#Create 'total_score' column as sum of home and away score
women_results_since_2002['total_score'] = women_results_since_2002['home_score']+ women_results_since_2002['away_score']
#Drop home and away score columns
women_results_since_2002_total = women_results_since_2002.drop(['home_score', 'away_score'],axis=1)
#Check total score column for normality
plt.hist(x=women_results_since_2002_total['total_score'])
#Resulting distribution is not normal
#Explore men dataframe
men_results.info()
print(men_results['tournament'].value_counts())
#Select the 4 relevant columns and only official FIFA World Cup matches from '2002-01-01' upwards
men_results_since_2002 = men_results[['date','home_score', 'away_score', 'tournament']].query('date>"2002-01-01" and tournament =="FIFA World Cup"')
#Create 'total_score' column as sum of home and away score
men_results_since_2002['total_score'] = men_results_since_2002['home_score']+ men_results_since_2002['away_score']
#Drop home and away score columns
men_results_since_2002_total = men_results_since_2002.drop(['home_score','away_score'], axis=1)
#Check total score column for normality
plt.hist(x=men_results_since_2002_total['total_score'])
#Resulting distribution is not normal, hence we will be using a non parametric ttest (Wilcoxon-Mann-Whitney-test)
#Calculate p value
p_val = pingouin.mwu(x =women_results_since_2002_total['total_score'], y=men_results_since_2002_total['total_score'], alternative='greater')['p-val'].values[0]
print(p_val)
#Determine decision of the hypothesis test using an if statement
alpha = 0.1
if p_val<=alpha:
result = 'reject'
else:
result = 'fail to reject'
print(result)
#Create dictionary containing p value and result of the hypothesis test
result_dict = {'p_val':p_val, 'result':result}
print(result_dict)