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 numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
data_women=pd.read_csv("women_results.csv",index_col=0,parse_dates=["date"])
data_men=pd.read_csv("men_results.csv",index_col=0,parse_dates=["date"])Data quality control
print(data_women)
print(data_men)
data_women.info()
data_men.info()
data_women["sum_score"]=data_women["home_score"]+data_women["away_score"]
data_men["sum_score"]=data_men["home_score"]+data_men["away_score"]
print(data_women["sum_score"].isnull().sum())
print(data_men["sum_score"].isnull().sum())Limiting the data to FIFA World Cup matches since 2002-01-01
women_filtered=data_women[(data_women["tournament"]=="FIFA World Cup")&(data_women["date"]>"2002-01-01")]
men_filtered=data_men[(data_men["tournament"]=="FIFA World Cup")&(data_men["date"]>"2002-01-01")]
print(women_filtered)
print(men_filtered)Can I perform t-test?
print(len(women_filtered["sum_score"]))
print(len(men_filtered["sum_score"]))
#Raw data distribution
g=sns.histplot(women_filtered["sum_score"],kde=True,label="Women",color="red",bins=50)
g=sns.histplot(men_filtered["sum_score"],kde=True,label="Men",color="blue",bins=50)
g.set_title("Raw data",y=1.03)
plt.legend(title="Groups")
plt.show()
#Bootstrap sample distribution
list_women=[]
list_men=[]
for i in range(1000):
list_women.append(np.mean(women_filtered.sample(frac=1,replace=True)["sum_score"]))
list_men.append(np.mean(men_filtered.sample(frac=1,replace=True)["sum_score"]))
g=sns.histplot(list_women,kde=True,label="Women",color="red",bins=30)
g=sns.histplot(list_men,kde=True,label="Men",color="blue",bins=30)
g.set_title("Bootstrap means of scores",y=1.03)
plt.legend(title="Groups")
plt.show()
The sample means obtained by bootstraping show the normal distribution but the raw data seems to have more right-skewed distribution,each of the groups counts more than 30 observations and it is assumed that each match is fully independentwhat. Because the criteria of normality is not fullfilled, a Wilcoxon-Mann-Whitney test is applied. 10% significance level is used. H_0: The mean number of goals scored in women's international soccer matches is the same as men's. H_A: The mean number of goals scored in women's international soccer matches is greater than men's.
alpha = 0.1
import pingouin as pg
##Converting the data from the long to wide format
###women_filtered["sum_score"].pivot()
mwutest = pg.mwu(x=women_filtered["sum_score"], y=men_filtered["sum_score"], alternative="greater")
p_val = mwutest["p-val"].values[0]
if p_val >= alpha:
print("The mean number of goals scored in women's international soccer matches is the same as men's.")
else:
print("The mean number of goals scored in women's international soccer matches is greater than men's.")
### Answer
def result():
if p_val >= alpha:
return "fail to reject"
else:
return "reject"
result_dict={"p_val":p_val,"result":result()}
print(mwutest[["U-val","p-val"]])