Skip to content
Project: Hypothesis Testing with Men's and Women's Soccer Matches
  • AI Chat
  • Code
  • Report
  • 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.

    # Imports
    import pandas as pd
    import matplotlib.pyplot as plt
    from scipy import stats
    
    # EDA
    women_results = pd.read_csv('women_results.csv', parse_dates = True)
    men_results = pd.read_csv('men_results.csv', parse_dates = True)
    
    women_results.info()
    women_results['tournament'].value_counts(normalize=True)
    # Filter to only FIFA World Cup events
    women_results = women_results[women_results['tournament'] == 'FIFA World Cup']
    men_results = men_results[men_results['tournament'] == 'FIFA World Cup']
    
    # Filter to only events after 2002-01-01
    women_results = women_results[women_results['date'] > '2002-01-01']
    men_results = men_results[men_results['date'] > '2002-01-01']
    
    women_results.sort_values('date').head()
    # Create a total_score column that adds home_score and away_score
    women_results['total_score'] = women_results['home_score'] + women_results['away_score']
    men_results['total_score'] = men_results['home_score'] + men_results['away_score']
    men_results.head()

    Since there are two independent groups, we will need an unpaired two-sample test. If the data is normally distributed, we will use an unpaired t-test. If it is not normally distributed, we will use a Wilcoxon-Mann-Whitney test.

    # Visualize distributions
    women_results.hist('total_score')
    plt.show()
    
    men_results.hist('total_score')
    plt.show()

    The data is clearly not normally distributed, so we will use a Mann-Whitney U test as our hypothesis test.

    # Perform Wilcoxon-Mann-Whitney test
    stat, p_val = stats.mannwhitneyu(x=women_results['total_score'], y=men_results['total_score'], alternative='greater')
    
    # Use 10% significance level to determine whether to reject the null hypthesis
    sig_level = 0.1
    if p_val <= sig_level:
        result = 'reject'
    else:
        result = 'fail to reject'
          
    # Final result
    result_dict = {'p_val': p_val, 'result': result}
    print(result_dict)