Anže Ambrožič

Research question: Are there any differences in the number of games played by the players in 3 different seasons?

StrikerPerformance <- read.csv("./StrikerPerformance.csv", header = TRUE, sep = ",")
mydata <- StrikerPerformance[, c(14, 18, 22, 28, 30)]
head(mydata)
##   X15.16.games X16.17.games X17.18.games  foot              name
## 1           30           40           24 right      Dmitri Poloz
## 2           20           31           21  both   Emiliano Rigoni
## 3           15           35           31  both Sebastián Driussi
## 4           24           38           34 right Aleksandr Kokorin
## 5           29           34           24 right  Anton Zabolotnyi
## 6           32           29           28  both     Quincy Promes
names(mydata)[1] <- "15/16"
names(mydata)[2] <- "16/17"
names(mydata)[3] <- "17/18"

Unit of observation: One football player Size of population is 1177 players and I will randomly choose a sample size of 200 football players. Units of measurment: number of games played in a specific season.

Variables: name = (name of the player) foot = (preffered foot of the player) 15/16 = (number of games played in the season 15/16) 16/17 = (number of games played in the season 16/17) 17/18 = (number of games played in the season 17/18)

The data set was taken from Kaggle.com (Football striker performance, data was extracted from Transfermarkt)

set.seed(1)
mydata <- mydata[sample(nrow(mydata), 200), ] #Random sample of 200 units.
library(tidyr)
mydata <- drop_na(mydata) #Removing units with missing values.
library(rstatix)
## Warning: package 'rstatix' was built under R version 4.3.2
## 
## Attaching package: 'rstatix'
## The following object is masked from 'package:stats':
## 
##     filter
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.3.2
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.3     ✔ purrr     1.0.2
## ✔ forcats   1.0.0     ✔ readr     2.1.4
## ✔ ggplot2   3.4.3     ✔ stringr   1.5.0
## ✔ lubridate 1.9.2     ✔ tibble    3.2.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks rstatix::filter(), stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
#Wide format of data is changed to long format.
mydata_long <- mydata %>%
                 pivot_longer(
                   cols = c("15/16", "16/17", "17/18"),
                   names_to = "Season", 
                   values_to = "Games_Played") %>%
                 convert_as_factor(Season)


mydata_long <- as.data.frame(mydata_long)

tail(mydata_long, 10)
##      foot            name Season Games_Played
## 522 right     Dyego Sousa  17/18           20
## 523 right  Fotis Georgiou  15/16           30
## 524 right  Fotis Georgiou  16/17           23
## 525 right  Fotis Georgiou  17/18           13
## 526 right Bernard Berisha  15/16           43
## 527 right Bernard Berisha  16/17           27
## 528 right Bernard Berisha  17/18           17
## 529 right   Yoan Gouffran  15/16           10
## 530 right   Yoan Gouffran  16/17           45
## 531 right   Yoan Gouffran  17/18           23
library(ggpubr)
## Warning: package 'ggpubr' was built under R version 4.3.2
#Boxplot for each variable.
ggboxplot(mydata_long, 
          x = "Season", 
          y = "Games_Played", 
          add = "jitter")

library(tidyverse)
library(ggpubr)
library(rstatix)

#Finding outliers.
mydata_long %>%
  group_by(Season) %>%
  identify_outliers(`Games_Played`)
## [1] Season       foot         name         Games_Played is.outlier  
## [6] is.extreme  
## <0 rows> (or 0-length row.names)
Assumptions for RANOVA TEST:
  1. All variables are numeric
  2. The Variables in the population are normally distributed
  3. The variences of the differences between player varaibles are equal
  4. No significant outliers
library(rstatix)

#Checking normality with Shapiro-Wilk test
mydata_long %>%
  group_by(Season) %>%
  shapiro_test(Games_Played)
## # A tibble: 3 × 4
##   Season variable     statistic        p
##   <fct>  <chr>            <dbl>    <dbl>
## 1 15/16  Games_Played     0.978 0.00764 
## 2 16/17  Games_Played     0.969 0.000524
## 3 17/18  Games_Played     0.983 0.0281

H0= Variable Games Played is normally distributed within Season. H1= Variable Games Played is not normally distributed within Season.

We reject null hypothesis, therefore we cannot continue with rAnova, we will do Friedman Anova.

FRIEDMAN ANOVA

library(rstatix)

#Friedman ANOVA.
FriedmanANOVA <- friedman_test(Games_Played ~ Season | name,
                               data = mydata_long)
FriedmanANOVA #Summary of results.
## # A tibble: 1 × 6
##   .y.              n statistic    df        p method       
## * <chr>        <int>     <dbl> <dbl>    <dbl> <chr>        
## 1 Games_Played   177      74.1     2 8.16e-17 Friedman test

H0: Location distribution for all three variables is the same

H1: At least one location distribution is different.

The calculated P value is 8.158163e-17. We reject the null hypothesis.

library(effectsize)
## 
## Attaching package: 'effectsize'
## The following objects are masked from 'package:rstatix':
## 
##     cohens_d, eta_squared
effectsize::kendalls_w(Games_Played ~ Season | name,
                       data = mydata_long)
## Warning: 15 block(s) contain ties, some containing only 1 unique ranking.
## Kendall's W |       95% CI
## --------------------------
## 0.21        | [0.15, 1.00]
## 
## - One-sided CIs: upper bound fixed at [1.00].
interpret_kendalls_w(0.21)
## [1] "fair agreement"
## (Rules: landis1977)

I reject the null hypothesis at P value = 8.158163e-17. There is a fair agreement in affect size.

library(rstatix)

#Wilcoxon signed rank tests - comparing all possible paires.
paires_nonpar <- wilcox_test(Games_Played ~ Season, 
                             paired = TRUE, 
                             p.adjust.method = "bonferroni",
                             data = mydata_long)

paires_nonpar
## # A tibble: 3 × 9
##   .y.         group1 group2    n1    n2 statistic        p    p.adj p.adj.signif
## * <chr>       <chr>  <chr>  <int> <int>     <dbl>    <dbl>    <dbl> <chr>       
## 1 Games_Play… 15/16  16/17    177   177     6741  4.13e- 1 1   e+ 0 ns          
## 2 Games_Play… 15/16  17/18    177   177    12196. 2.09e-11 6.27e-11 ****        
## 3 Games_Play… 16/17  17/18    177   177    12070. 1.68e-14 5.04e-14 ****

I cannot reject H0 for pairwise comaprison between 15/16 games and 16/17 games since p value is 0.413. For other pairs P value is lower than 5% so I we can say that games played differ in comparison to seasons.

library(rstatix)
comparisons <- paires_nonpar %>% 
                 add_y_position(fun = "median", step.increase = 0.35)

library(ggpubr)
ggboxplot(mydata_long, x = "Season", y = "Games_Played", add = "point", ylim=c(0, 100)) +
  stat_pvalue_manual(comparisons, hide.ns = FALSE) +
  stat_summary(fun = median, geom = "point", shape = 16, size = 4,
               aes(group = Season), color = "darkred",
               position = position_dodge(width = 0.8)) +
  stat_summary(fun = median, colour = "darkred", 
               position = position_dodge(width = 0.8),
               geom = "text", vjust = 0.5, hjust = -8,
               aes(label = round(after_stat(y), digits = 2), group = Season)) +
  labs(subtitle = get_test_label(FriedmanANOVA,  detailed = TRUE),
       caption = get_pwc_label(comparisons))

CONCLUSION: Based on the data of the sample I found out that there is differences between number of games played of players in 3 different seasons. Using Friedman Anova we got a P value lower than 0.01%. The effect size is 0.21 which states fair agreement and indicates that there are differences in the Games Played by the players in 3 different seasons.

RANOVA

Even though Shapiro-Wilk normality test has shown that variables are not normally distrbuted, I will conduct rANOVA. To show the results from the parametric test.

We will start with showing some descriptive statistics.

library(rstatix)

mydata_long %>%
  group_by(Season) %>%
  get_summary_stats(Games_Played, type = "common")
## # A tibble: 3 × 11
##   Season variable         n   min   max median   iqr  mean    sd    se    ci
##   <fct>  <fct>        <dbl> <dbl> <dbl>  <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 15/16  Games_Played   177     1    56     31    15  28.8 11.7  0.88   1.74
## 2 16/17  Games_Played   177     1    60     31    15  29.7 11.8  0.886  1.75
## 3 17/18  Games_Played   177     0    44     23    12  21.7  9.54 0.717  1.42

Number of unit is 177. Mean for season 15/16 is 28.825, for season 16/17 is 29.729 and for 17/18 is 21.746. Median is the same for 15/16 and 16/17 - 31 and for season 17/18 the median is 23.

library(rstatix)

#rANOVA
ANOVA_results <- anova_test(dv = Games_Played, #Dependent variable
                            wid = name, #Subject identifier
                            within = Season, #Within-subject factor variable
                            data = mydata_long)

ANOVA_results #Summary of results.
## ANOVA Table (type III tests)
## 
## $ANOVA
##   Effect DFn DFd      F        p p<.05   ges
## 1 Season   2 352 46.967 8.32e-19     * 0.095
## 
## $`Mauchly's Test for Sphericity`
##   Effect    W     p p<.05
## 1 Season 0.99 0.422      
## 
## $`Sphericity Corrections`
##   Effect  GGe       DF[GG]   p[GG] p[GG]<.05   HFe    DF[HF]    p[HF] p[HF]<.05
## 1 Season 0.99 1.98, 348.58 1.2e-18         * 1.002 2, 352.53 8.32e-19         *
get_anova_table(ANOVA_results, correction = "auto")
## ANOVA Table (type III tests)
## 
##   Effect DFn DFd      F        p p<.05   ges
## 1 Season   2 352 46.967 8.32e-19     * 0.095

HYPOTHESIS FOR RANOVA: H0: Mean of all three variables are the same H1: At least one of the means is different than means of other variables.

Calculated P value is 8.32e-19, that means we reject the null hypothesis.

library(effectsize)
interpret_eta_squared(0.095, rules = "cohen1992")
## [1] "small"
## (Rules: cohen1992)
library(rstatix)


pwc <- mydata_long %>%
  pairwise_t_test(Games_Played ~ Season, 
                  paired = TRUE,
                  p.adjust.method = "bonferroni")

pwc
## # A tibble: 3 × 10
##   .y.   group1 group2    n1    n2 statistic    df        p    p.adj p.adj.signif
## * <chr> <chr>  <chr>  <int> <int>     <dbl> <dbl>    <dbl>    <dbl> <chr>       
## 1 Game… 15/16  16/17    177   177     -1.02   176 3.11e- 1 9.33e- 1 ns          
## 2 Game… 15/16  17/18    177   177      7.49   176 3.12e-12 9.36e-12 ****        
## 3 Game… 16/17  17/18    177   177      9.16   176 1.28e-16 3.84e-16 ****

When comparing different season we got the p value pf 3.11e-01 when comparing season 15/16 and 16/17 we cannot reject H0 - saying that games played do differ in comaprison. When comparing other season between each ohter, P value is lower than 5% so we can say that for other season Games Played differ in comaprison.

library(rstatix)
pwc <- pwc %>% 
       add_y_position(fun = "median", step.increase = 0.35)

library(ggpubr)
ggboxplot(mydata_long, x = "Season", y = "Games_Played", add = "point", ylim=c(0, 100)) +
  stat_pvalue_manual(pwc, hide.ns = FALSE) +
  stat_summary(fun = mean, geom = "point", shape = 16, size = 4,
               aes(group = Season), color = "darkred",
               position = position_dodge(width = 0.8)) +
  stat_summary(fun = mean, colour = "darkred", 
               position = position_dodge(width = 0.8),
               geom = "text", vjust = 0.5, hjust = -2,
               aes(label = round(after_stat(y), digits = 2), group = Season)) +
  labs(subtitle = get_test_label(ANOVA_results,  detailed = TRUE),
       caption = get_pwc_label(pwc))

CONCLUSION: After conducting r-Anova I got similar results as I got at Friedman Anova. The calucated p value was 8.32e-19, so we have rejected the null hypothesis (H0: Mean of all three variables are the same.) since the P value was lower than 5%. We conclude the statistical analysis, understanding that there is a difference in the number of games played by the players in 3 different seasons.