Skip to content

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:

: The mean number of goals scored in women's international soccer matches is the same as men's.

: The mean number of goals scored in women's international soccer matches is greater than men's.

# Start your code here!
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
import pingouin
from scipy.stats import t

Exploratory Data Analysis

As a first step we will perfomr EDA over the data.

# Loading men_results.csv
men_results = pd.read_csv("men_results.csv", usecols=range(1,7))
display(men_results.head(10))
display(men_results.describe())
display(men_results.info())
# Loading women_results.csv
women_results = pd.read_csv("women_results.csv", usecols=range(1,7))
display(women_results.head(10))
print(women_results.info())

Converting date to datetimes data type

# converting date column of the men_results to datetime
men_results['date'] = pd.to_datetime(men_results['date'])
print(men_results.info())
# converting date column of the women_results to datetime
women_results['date'] = pd.to_datetime(women_results['date'])
print(women_results.info())

Exploring tournament values

# What tournaments exist in the database
print(men_results["tournament"].value_counts())
print(women_results["tournament"].value_counts())

Filtering FIFA World Cup after 2002

# Filter FIFA World Cup
fifa_men_results = men_results[men_results["tournament"] == "FIFA World Cup"]
fifa_women_results = women_results[women_results["tournament"] == "FIFA World Cup"]

# Filter games after 2002
fifa_men_results_post_2002 = fifa_men_results[fifa_men_results['date'] >= '2002-01-01']\
    .reset_index(drop=True)
fifa_women_results_post_2002 = fifa_women_results[fifa_women_results['date'] >= '2002-01-01']\
    .reset_index(drop=True)
display(fifa_men_results_post_2002.head(10))
display(fifa_women_results_post_2002.head(10))

Hypothesis testing

Choosing the hypothesis test

Our null hypothesis, , states that mean number of goals scored in women's international soccer matches is the same as men's, while the alternative hypothesis, , statest that goals scored in women's international soccer matches is greater than men's. We therefore choose a right-tailed test for our analysis.

Exploring the distribution

To explore the distribution of goals per worldcup we are going to need to add a column of the total goals per game.

# Adding a new column of the total goals per game
fifa_men_results_post_2002['total_goals'] = fifa_men_results_post_2002['home_score'] + fifa_men_results_post_2002['away_score']
fifa_men_results_post_2002['total_goals'].hist(alpha=0.5, label='Men')
fifa_women_results_post_2002['total_goals'] = fifa_women_results_post_2002['home_score'] + fifa_women_results_post_2002['away_score']
fifa_women_results_post_2002['total_goals'].hist(alpha=0.5, label='Women')
plt.legend()
plt.show()

Looking at the above figure, at first glance the distribution does not look normal. The main reasoning for that is that it is bounded by 0, i.e., there are no negative scores in soccer and, by definition, a normal distribution goes from to . The distribution looks like a left-skewd distribution. This breaks one of the assumption of parametric tests:

The sample distribution can be assumed to be normally distributed.

We therefore need to use a non-parametric test. Our data is non-paired, so makes sense to use the Wilcoxon-Mann-Whitney test.