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
df1 = pd.read_csv("men_results.csv")
df2 = pd.read_csv("women_results.csv")
#Visualizing data
display(df1.head())
display(df2.head())#Exploratory analysis
print(df1.info(), "\n")
print(df2.info(),"\n")
print(df1["tournament"].value_counts(),"\n")
print(df2["tournament"].value_counts())
#Filtering the data
df1_filtered = df1[(df1["tournament"] == "FIFA World Cup") & (df1["date"] > "2002-01-01")]
df2_filtered = df2[(df2["tournament"] == "FIFA World Cup") & (df2["date"] > "2002-01-01")]
display(df1_filtered.head())
display(df2_filtered.head())#Sample sizes and normality
print(f"Sample size of men: {len(df1_filtered)} ")
print(f"Sample size of women: {len(df2_filtered)} ")
#Creating the total goals column
df1_filtered["total_goals"] = df1_filtered["home_score"] + df1_filtered["away_score"]
df2_filtered["total_goals"] = df2_filtered["home_score"] + df2_filtered["away_score"]
#Visualizing the data with histogram plots
import matplotlib.pyplot as plt
import seaborn as sns
sns.histplot(data=df1_filtered, x="total_goals", kde=True, color="pink")
plt.title("Frequency of total goals in men matches")
plt.show()
sns.histplot(data=df2_filtered, x="total_goals", kde=True, color="pink")
plt.title("Frequency of total goals in women matches")
plt.show()
#For better results we are going to do a test of normality
from scipy.stats import shapiro
alpha = 0.05
statistic1, p_value1 = shapiro(df1_filtered["total_goals"])
statistic2, p_value2 = shapiro(df2_filtered["total_goals"])
if p_value1 > 0.05:
print(f"There is insufficient evidence to reject the null hypothesis, So the data may be normally distributed. P-value: {p_value1}")
else:
print(f"There is sufficient evidence to reject the null hypothesis, So the data may not be normally distributed. P-value: {p_value1}\n")
if p_value2 > 0.05:
print(f"There is insufficient evidence to reject the null hypothesis, So the data may be normally distributed. P-value: {p_value2}")
else:
print(f"There is sufficient evidence to reject the null hypothesis, So the data may not be normally distributed. P-value: {p_value2}\n")
#Hypotesis testing
#Pingouin
import pingouin as pg
alpha = 0.10
result_pg = pg.mwu(df1_filtered["total_goals"], df2_filtered["total_goals"], alternative="less")
print(result_pg, "\n")
#Scipy
from scipy.stats import mannwhitneyu
result_scipy = mannwhitneyu(df1_filtered["total_goals"], df2_filtered["total_goals"], alternative="less")
print(result_scipy, "\n")
p_val = result_pg["p-val"]
import numpy as np
numpy_p_val = np.array(p_val)
p_val = numpy_p_val[0]
result_dict = {"p_val": p_val,
"result": "reject"}