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
women_general = pd.read_csv('women_results.csv')
men_general = pd.read_csv('men_results.csv')
print(women_general.info())
print(men_general.info())
Filtering the data for the time range and tournament.
men_general["date"] = pd.to_datetime(men_general["date"])
men = men_general[(men_general["date"] > "2002-01-01") & (men_general["tournament"].isin(["FIFA World Cup"]))]
women_general["date"] = pd.to_datetime(women_general["date"])
women = women_general[(women_general["date"] > "2002-01-01") & (women_general["tournament"].isin(["FIFA World Cup"]))]
Creating a column "total_score" that is the sum of home and away score goals in the same game.
women['total_score'] = women['home_score'] + women['away_score']
men['total_score'] = men['home_score'] + men['away_score']
Finding the average goals per game for women and men.
women_goals_mean = women['total_score'].mean()
men_goals_mean = men['total_score'].mean()
print("The women's average goals per match is" + " " + str(women_goals_mean))
print("The men's average goals per match is" + " " + str(men_goals_mean))
Checking if the data are normally distributed.
from scipy.stats import shapiro
# Ho(Accepted): Sample is from the normal distributions.(Po>0.1)
# H1(Rejected): Sample is not from the normal distributions.
print(shapiro(women['total_score']))
print(shapiro(men['total_score']))
# the p-value is less than the alpha(0.1) then we reject the null hypothesis i.e. we have sufficient evidence to say that sample does not come from a normal distribution.
Applying the Mann-Whitney hypothesis test, since we have non-parametric data.
import numpy as np
from scipy.stats import mannwhitneyu
import scipy.stats as stats
# The null hypothesis (H0) is that the mean number of goals scored in women's international soccer matches is the same as men's.
# The null alternative (H1) is that the mean number of goals scored in women's international soccer matches is greater than men's.
U1, p = mannwhitneyu(np.array(women['total_score']), np.array(men['total_score']), alternative='greater')
# r = stats.mannwhitneyu(np.array(mens['total_score']), np.array(womans['total_score']), alternative='greater')
print(p)
RESULT: As the p-value is less than the alpha(0.1) then we reject the null hypothesis i.e. we have sufficient evidence to say that the mean number of goals scored in women's international soccer matches is greater than men's.
result_dict = {"p_val": p, "result": "reject"}
print(result_dict)