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.

1 - Exploratory data analysis

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from scipy.stats import shapiro

# Loading the data from the CSV files and parse dates
men_results = pd.read_csv('men_results.csv', parse_dates=['date'])
women_results = pd.read_csv('women_results.csv', parse_dates=['date'])

# Display the first few rows of each dataset
print("Men's results:")
print(men_results.head())
print("\nWomen's results:")
print(women_results.head())

# Display information aboud the datasets
print("\nMen's results info:")
print(men_results.info())
print("\nWomen's results info:")
print(women_results.info())

# Determine the counts of unique values in the "Tournament" column for each dataset
print("\nMen's tournament counts:")
print(men_results["tournament"].value_counts())
print("\nWomen's tournament counts:")
print(women_results["tournament"].value_counts())

2 - Filtering the data

# Filter for FIFA World Cup matches
men_world_cup = men_results[men_results['tournament'] == 'FIFA World Cup']
women_world_cup = women_results[women_results['tournament'] == 'FIFA World Cup']

# Display the first few rows to verify filtering by tournament
print("\nMen's World Cup matches:")
print(men_world_cup.head())
print("\nWomen's World Cup matches:")
print(women_world_cup.head())

# Filter for matches after 2002-01-01
start_date = pd.to_datetime('2002-01-01')
men_world_cup_recent = men_world_cup[men_world_cup['date'] > start_date]
women_world_cup_recent = women_world_cup[women_world_cup['date'] > start_date]

# Display the first few rows to verif filtering by date
print("\nMen's World Cup matches after 2002-01-01:")
print(men_world_cup_recent.head())
print("\nWomen's World Cup matches after 2002-01-01:")
print(women_world_cup_recent.head())

3 - Choosing the correct hypothesis test

# Step 1 - Plotting histograms

# Histogram for goals scored in men's and women's matches
plt.figure(figsize=(14, 6))

# Men's goals
plt.subplot(1, 2, 1)
sns.histplot(men_world_cup_recent['home_score'] + men_world_cup_recent['away_score'], bins=20, kde=True)

plt.title("Distribution of goals in Men's World Cup Matches")
plt.xlabel("Total Goals")
plt.ylabel("Frequency")

# Women's goals
plt.subplot(1, 2, 2)
sns.histplot(women_world_cup_recent['home_score'] + women_world_cup_recent['away_score'], bins=20, kde=True)

plt.title("Distribution of goals in Women's World Cup Matches")
plt.xlabel("Total Goals")
plt.ylabel("Frequency")

plt.tight_layout()
plt.show()

# Step 2 - Performing normality tests

# Combining home and away scores for total goals
men_goals = men_world_cup_recent['home_score'] + men_world_cup_recent['away_score']
women_goals = women_world_cup_recent['home_score'] + women_world_cup_recent['away_score']

# Shapiro-Wilk test for normality
men_shapiro = shapiro(men_goals)
women_shapiro = shapiro(women_goals)

print(f"Men's Shapiro-Wilk Test: W={men_shapiro.statistic}, p-value={men_shapiro.pvalue}")
print(f"Women's Shapiro-Wilk Test: W={women_shapiro.statistic}, p-value={women_shapiro.pvalue}")

Based on our exploratory data analysis, we determined that the distributions of goals scored in men's and women's soccer matches were not normally distributed. Given this non-normality, a parametric test like the t-test would not be appropriate. Instead, we opted for the Mann-Whitney U test, a non-parametric alternative that does not assume normal distribution. This test is suitable for comparing two independent samples and allowed us to accurately assess whether the average number of goals in women’s international soccer matches is significantly higher than in men’s.

4 - Performing the hypothesis test

from scipy.stats import mannwhitneyu

# Performing Mann-Whitney U Test
u_stat, p_val = mannwhitneyu(men_goals, women_goals, alternative='less')

5 - Interpreting the result of the hypothesis test

# Interpreting the result of Mann-Whitney test
alpha = 0.10 

if u_pvalue < alpha:
    result = "reject"
else:
    result = "fail to reject"
    
# Creating a dictionary for the final results
result_dict = {"p_val": p_val, "result": result}
print(result_dict)

Conclusion

After performing the Mann-Whitney U test to compare the average number of goals in international women's and men's soccer matches, we obtained a p-value of 0.0051. This value is significantly lower than the 10% (0.10) significance level.

Test Conclusion: We reject the null hypothesis. This indicates that there is sufficient evidence to claim that the average number of goals scored in international women's soccer matches is greater than in men's.

This result suggests a statistically significant difference in the number of goals scored between the two categories, supporting the hypothesis that women's soccer may have a higher average number of goals in international tournaments since 2002. This insight could provide a new perspective on performance in soccer competitions and serve as a foundation for more detailed analyses.