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
import pingouin
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
from scipy import stats
women=pd.read_csv('women_results.csv')
men=pd.read_csv('men_results.csv')
import pingouin
women['sex']='Feminino' #criando a coluna sexo na base de mulher (não precisei usar pq não precisei mergear)
men['sex']='Masculino' #criando a coluna sexo na base de homem (não precisei usar pq não precisei mergear)
women['gols_jogo']=women['home_score']+women['away_score'] #criando a coluna total de gols por jogo na base women
men['gols_jogo']=men['home_score']+men['away_score'] #criando a coluna total de gols por jogo na base men
#deixando nas bases só copa do mundo a partir de 2002
women=women[women['date']>='2002']
women=women[women['tournament']=='FIFA World Cup']
men=men[men['date']>='2002']
men=men[men['tournament']=='FIFA World Cup']
#buscando entender se os dados seguem distribuição normal
plt.hist(data=women,x='gols_jogo') #plot histogram mostra que a distribuição de women é assimétrica à direita
plt.show()
#teste de kolmogorov-smirnov com p-valor baixo me faz rejeitar a hipótese de que os dados são normais. logo usar teste não paramétrico
ks_statistic, p_value = stats.kstest(women['gols_jogo'], 'norm', args=(women['gols_jogo'].mean(), women['gols_jogo'].mean()))
print(ks_statistic,p_value)
#testar a hipótese do número médio de gols ser igual independente do sexo para dados não normalizados
alfa=0.1 #nível de significância
teste=pingouin.mwu(x=women['gols_jogo'],y=men['gols_jogo'],alternative='greater') #teste mann-whitney para comparação de médias
p_val=teste['p-val'].values[0] #guardar o p-valor em um objeto
#criando a formula para trazer a string a depender do resultado do teste
if p_val<alfa:
result="reject"
elif p_val>=alfa:
result="fail to reject"
result_dict={"p_val":p_val,"result":result} #criando o dicionário
print(result_dict)
#rascunho women.head() men.head() #women.shape #men.shape total.shape total['sex'].value_counts() print(media_homem,media_mulher) men.head() women.head()
print(men['gols_jogo'].mean()) print(women['gols_jogo'].mean()) #total=pd.concat([men,women],ignore_index=True) #total['gols_jogo']=total['home_score']+total['away_score'] #media_homem=total.groupby('sex')['gols_jogo'].mean()[0] #media_mulher=total.groupby('sex')['gols_jogo'].mean()[1] print(isinstance(result,str))