Workspace
Atul Bhuju/

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

0
Beta
Spinner

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!
library(tidyverse)
library(ggplot2)

# Read the data
women_data <- read_csv("women_results.csv")
men_data <- read_csv("men_results.csv")

# Filter data for FIFA World Cup matches since 2002-01-01
women_world_cup_result <- women_data %>%
  filter(tournament == "FIFA World Cup" & date >= "2002-01-01") %>%
	mutate(goals_scored = home_score + away_score)

head(women_world_cup_result)
glimpse(women_world_cup_result)

men_world_cup_result <- men_data %>%
  filter(tournament == "FIFA World Cup" & date >= "2002-01-01") %>%
	mutate(goals_scored = home_score + away_score)

head(men_world_cup_result)
glimpse(men_world_cup_result)

# Determining the type of hypothesis and if the data is normally distributed

ggplot(women_world_cup_result, aes(goals_scored)) + 
  geom_histogram(color = "black", fill = "red", bins = 30) +
  ggtitle("Goals Scored by Women") +
  xlab("Goals Scored") +
  ylab("Count")


ggplot(men_world_cup_result, aes(goals_scored)) + 
  geom_histogram(color = "black", fill = "blue", bins = 30) +
  ggtitle("Goals Scored by Men") +
  xlab("Goals Scored") +
  ylab("Count")

# Result - it is a right tail test and is not normally disributed

# Performing hypothesis test to perform and carry out the test to return the p-value.
# Non-parametric test is appropriate, because we can't use the assumption of normal distributions
# Refer Non-parametric ANOVA and unpaired t-tests from Hpothesis Testing in R

# Setting of Hypothesis 
#H0: mu_women = mu_men
#HA: mu_women > mu_men

wilcox.test(
	x = women_world_cup_result$goals_scored, 
	y = men_world_cup_result$goals_scored, 
	alternative = "greater"
)

# here the test returns the p-value of 0.005107
p_val <-  0.005107
result <- ifelse(p_val <= 0.1, "reject", "fail to reject")

# significance level is assumed 10%, if p_value < alpha, "reject the null hypothesis"
result_df <- data.frame(p_val, result)
result_df
  • AI Chat
  • Code