this is the nav!
Workspace
Maya Balkanova/

# Project: Hypothesis Testing with Men's and Women's Soccer Matches

0
Beta

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.

.mfe-app-workspace-jfrv3u{font-size:13px;line-height:20px;font-family:JetBrainsMonoNL,Menlo,Monaco,'Courier New',monospace;}# Start your code here!
import pandas as pd
import matplotlib.pyplot as plt
import pingouin

# Exploratory data analysis
men_results.info()
men_results.tournament.value_counts()

# Filtering the data

men_results['date']=pd.to_datetime(men_results.date)
men_results = men_results[(men_results['date'] > '2002-01-01') & (men_results['tournament'] == 'FIFA World Cup')]

women_results['date']=pd.to_datetime(women_results.date)
women_results = women_results[(women_results['date'] > '2002-01-01') & (women_results['tournament'] == 'FIFA World Cup')]

# Performing the hypothesis test
# Choosing the correct hypothesis test
men_results['goals_scored'] = men_results['home_score'] + men_results['away_score']
women_results['goals_scored'] = women_results['home_score'] + women_results['away_score']

men_results['goals_scored'].hist()
plt.show()
plt.clf()

women_results['goals_scored'].hist()
plt.show()
plt.clf()

# Goals scored is not normally distributed, so Wilcoxon-Mann-Whitney test is the choice

# Preparing dataframe format for test
men_results['group'] = 'men'
women_results['group'] = 'women'

# Combine the data
men_and_women = pd.concat([men_results, women_results], axis = 0, ignore_index = True)

# Transform the data
men_and_women = men_and_women[['goals_scored', 'group']]
men_and_women_wide = men_and_women.pivot(columns = 'group', values = 'goals_scored')

# Right-tailed Wilcoxon-Mann-Whitney test
test_result = pingouin.mwu(x = men_and_women_wide['women'], y= men_and_women_wide['men'], alternative = 'greater')
p_val = test_result['p-val'].values[0]

# Result of the hypothesis test

if p_val < 0.010:
result = 'reject'
else:
result = 'fail to reject'

result_dict = {'p_val':p_val, 'result':result}
result_dict

• AI Chat
• Code