The transfers of football players (slo: prestopni roki) happen twice a year, once in the winter and once in the summer.
This is a way for clubs to buy players, to boost their squad and ultimately achieve better game results.
I am a big football fan, thus I acquired data of the summer transfer window, as that’s where usually bigger fees are spent and more spectacular moves are made (in comparison to the winter one). Also, I chose the 2019 season, as that is the year where I recall, in my experience, the most iconic signings being made.
Here is how I imported the data. I found it online on this link: https://data.world/dcereijo/player-scores under the player evaluations tab Importing caused major problems, some football players had an apostrophe (this ’ symbol) in their names, which caused the separator to read it as a coma. It was fixed.
Transfers <- read.table("C:/Users/38631/Desktop/Only the 18 19 season.csv", header=TRUE, sep=",", dec=".")
I chose the 2019 season mainly because of these two signings, which were more than 100mil EUR each.
head(Transfers, 3)
## NAME POSITION AGE LEAGUE FEE GOALS ASSISTS
## 1 Kylian Mbappé 3 19 1 135000000 39 17
## 2 Cristiano Ronaldo 3 33 1 117000000 28 11
## 3 Thomas Lemar 3 22 1 70000000 6 18
The unit of observation (sample size = 244) is one football player. I also have 6 variables, the position of play on the field, the age of the player, the league from where the player was bought from, the number of goals scored that season, the number of assists (passes that led to goals) that season, and the final variable is the transfer fee in EUR.
Note: The League categorical value also has three possibilities. The original data included leagues from all over the world (20+). I’ve shortened them up into three categories with the line representing the division in Europe. (This is in my experience a fair division when it comes to football power, though this line could be virtually anywhere).
knitr::include_graphics("C:/Users/38631/Desktop/R Software/The division of Europe.png")
There are three values for the Position Categorical Variable
unique(Transfers$POSITION)
## [1] 3 1 2
There are also three values for the League Categorical Variable
unique(Transfers$LEAGUE)
## [1] 1 2 3
Here, I renamed the categorical variables for the Positions:
Transfers$POSITIONFACTOR <- factor(Transfers$POSITION, levels = c(1,2,3), labels = c("Defence", "Midfield", "Attack"))
And also renamed the categorical variables for the Leagues:
Transfers$LEAGUEFACTOR <- factor(Transfers$LEAGUE, levels = c(1,2,3), labels = c("West Europe", "East Europe", "Rest of world"))
Here are the descriptive statistics after the factoring of the categorical variables.
summary(Transfers)
## NAME POSITION AGE LEAGUE
## Length:244 Min. :1.000 Min. :16.00 Min. :1.000
## Class :character 1st Qu.:1.000 1st Qu.:22.00 1st Qu.:1.000
## Mode :character Median :2.000 Median :25.00 Median :1.000
## Mean :2.053 Mean :24.55 Mean :1.615
## 3rd Qu.:3.000 3rd Qu.:27.00 3rd Qu.:2.000
## Max. :3.000 Max. :35.00 Max. :3.000
## FEE GOALS ASSISTS POSITIONFACTOR
## Min. : 4500000 Min. : 0.000 Min. : 0.000 Defence :81
## 1st Qu.: 6000000 1st Qu.: 1.000 1st Qu.: 1.000 Midfield:69
## Median : 9000000 Median : 3.000 Median : 3.000 Attack :94
## Mean : 14060123 Mean : 3.561 Mean : 3.582
## 3rd Qu.: 15000000 3rd Qu.: 4.000 3rd Qu.: 4.000
## Max. :135000000 Max. :39.000 Max. :18.000
## LEAGUEFACTOR
## West Europe :125
## East Europe : 88
## Rest of world: 31
##
##
##
For example, we can see how many units play for different positions and in what leagues. We can therefore see that the previous European League (geographical) division is fairly accurate, as it nearly divides the number of players approximately in half.
When it comes to age, we can see that the players are on average
approximately 24 and a half years old.
3rd Qu. (Third quartile), this represents the age below which 75% of the
players fall. In other words, 75% of the players are younger than or
equal to 27 years.
The mean for the fee is 14060123 EUR, so approximately 14 million EUR.
Also, another note: It makes sense that the means of both goals and assists are roughly the same numbers. Every goal scored needs a person scoring it and a pass beforehand.
This is the final dataset:
colnames(Transfers) <- c("Name", "Position", "Age", "League", "Fee", "Goals", "Assists", "PositionFactor", "LeagueFactor")
head(Transfers)
## Name Position Age League Fee Goals Assists PositionFactor
## 1 Kylian Mbappé 3 19 1 135000000 39 17 Attack
## 2 Cristiano Ronaldo 3 33 1 117000000 28 11 Attack
## 3 Thomas Lemar 3 22 1 70000000 6 18 Attack
## 4 Riyad Mahrez 3 27 1 67800000 12 12 Attack
## 5 Alisson 1 25 2 62500000 0 0 Defence
## 6 Naby Keïta 2 23 2 60000000 14 12 Midfield
## LeagueFactor
## 1 West Europe
## 2 West Europe
## 3 West Europe
## 4 West Europe
## 5 East Europe
## 6 East Europe
Name: ID variable.
Age: Age of football player at the time of transfer in years.
Fee: The total amount spent in the player to acquire his services in
EUR.
Goals: Number of Goals scored that season.
Assists: Number of assists that season.
PositionFactor: The position on the field of which the player is mostly
used for.
LeagueFactor: The league where the player played at the time (rather
before) of the transfer.
Adding some statistics while removing the first row.
library(psych)
describe(Transfers[ ,-1])
## vars n mean sd median trimmed mad
## Position 1 244 2.05 0.85 2 2.07 1.48
## Age 2 244 24.55 3.74 25 24.40 4.45
## League 3 244 1.61 0.70 1 1.52 0.00
## Fee 4 244 14060122.95 15403783.63 9000000 10774336.73 4892580.00
## Goals 5 244 3.56 4.13 3 2.89 2.97
## Assists 6 244 3.58 3.57 3 3.03 2.97
## PositionFactor* 7 244 2.05 0.85 2 2.07 1.48
## LeagueFactor* 8 244 1.61 0.70 1 1.52 0.00
## min max range skew kurtosis se
## Position 1 3.00e+00 2 -0.10 -1.60 0.05
## Age 16 3.50e+01 19 0.38 -0.23 0.24
## League 1 3.00e+00 2 0.69 -0.74 0.04
## Fee 4500000 1.35e+08 130500000 4.17 23.75 986126.20
## Goals 0 3.90e+01 39 4.04 26.32 0.26
## Assists 0 1.80e+01 18 1.38 1.58 0.23
## PositionFactor* 1 3.00e+00 2 -0.10 -1.60 0.05
## LeagueFactor* 1 3.00e+00 2 0.69 -0.74 0.04
Research Question: I chose the PCA mainly because we can find out firstly the correlations between the fee and the other variables, maybe those are the main indicators as to why players get sold for alot of money. Ofcourse, there are, in theory, many others, such as player history, attitude, style of play, fair play etc. PCA helps identify relationships and patterns among variables. By examining the loadings (mentioned later) of variables on each principal component, we can understand which variables tend to vary together and which ones are relatively independent.
Shorter Research Question: Are there observable trends in player characteristics that make them a part of the most valuable lists of football transfers?
In PCA, we never include categorical variables.
First, I Standardized the data
Transfers$AgeScaled <- scale(Transfers$Age)
Transfers$GoalsScaled <- scale(Transfers$Goals)
Transfers$AssistsScaled <- scale(Transfers$Assists)
Transfers$FeeScaled <- scale(Transfers$Fee)
library(car)
## Loading required package: carData
##
## Attaching package: 'car'
## The following object is masked from 'package:psych':
##
## logit
fit<- lm(Fee ~ Age + Goals + Assists + Position + League, data=Transfers)
vif(fit)
## Age Goals Assists Position League
## 1.034530 1.277316 1.262995 1.062285 1.041747
Clearly, we can see most (though not strong) of the correlation with the price being with the goals and assists.
First, we make a new dataframe.
TransfersPCA <- Transfers[, c("Age", "Goals", "Assists")]
library(pastecs)
Next, at the statistics descriptions we can see that there’s differences in the means and var of the data, this makes the variables uncomparable.
round(stat.desc(TransfersPCA, basic=FALSE))
## Age Goals Assists
## median 25 3 3
## mean 25 4 4
## SE.mean 0 0 0
## CI.mean.0.95 0 1 0
## var 14 17 13
## std.dev 4 4 4
## coef.var 0 1 1
Using the Correlation matrix, we can see standardized data. We can also see a strong connection between Goals and Assists, which makes sense.
R <- cor(TransfersPCA)
round(R, 3)
## Age Goals Assists
## Age 1.000 -0.076 -0.085
## Goals -0.076 1.000 0.445
## Assists -0.085 0.445 1.000
Next , we have to test an assumption of the PCA, the Bartlett Test of
Sphericity. The null hypothesis assumes that the population correlation
matrix is the same as an identity matrix (I), which has all correlations
set at zero.
The P value is low enough to decline the Null Hypothesis, meaning the
matrices are not the same.
library(psych)
cortest.bartlett(R, n = nrow(TransfersPCA))
## $chisq
## [1] 55.43366
##
## $p.value
## [1] 5.548728e-12
##
## $df
## [1] 3
Next, we can calculate the Chi-Squared statistics. Also a part of the test above.
det(R)
## [1] 0.7946478
Next are the KMO Statistics. It’s recommended the Overall MSA should be above 0.5, which it is. Also, this gives us a look into individual MSA statistics.
library(psych)
KMO(R)
## Kaiser-Meyer-Olkin factor adequacy
## Call: KMO(r = R)
## Overall MSA = 0.51
## MSA for each item =
## Age Goals Assists
## 0.72 0.51 0.51
Next, we figure out the Eigenvalues. Dim 1 through 3 are Principled
Components, here’s important to check the eigenvalues.
There are many rules that help us choose the number of Principled
components. According to the Kaiser’s rule, we should select the
eigenvalues higher than 1 (average is equal to 1 when standardized), we
can see only the first PCA is bigger than 1, though the second one is
very, very close. The other one says that the chosen number of
components should at least explain about 70% of the variance. The final
one says that the last component should explain at least 5% of the total
variability.
library(FactoMineR)
Components <- PCA(TransfersPCA, scale.unit = TRUE, graph=FALSE)
library(factoextra)
## Loading required package: ggplot2
##
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
##
## %+%, alpha
## Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
get_eigenvalue(Components)
## eigenvalue variance.percent cumulative.variance.percent
## Dim.1 1.4722930 49.07643 49.07643
## Dim.2 0.9729882 32.43294 81.50937
## Dim.3 0.5547188 18.49063 100.00000
At the next visualization we need to check where the line gets less steap.
library(factoextra)
fviz_eig(Components, choice = "eigenvalue", main = "screeplot", ylab = "Eigenvalue", xlab = "PC", addlabels = TRUE)
At the next one, we need to check where the red line goes above the blue one, again, very close to the second PC, yet the visualization suggests one PC.
library(psych)
fa.parallel (TransfersPCA, sim = FALSE, fa = "pc")
## Parallel analysis suggests that the number of factors = NA and the number of components = 1
Next, I opened the command for further analysis. Here we choose the fourth, sixth and eight one.
library(FactoMineR)
Components <- PCA(TransfersPCA, scale.unit = TRUE, graph = FALSE, ncp = 2)
Components
## **Results for the Principal Component Analysis (PCA)**
## The analysis was performed on 244 individuals, described by 3 variables
## *The results are available in the following objects:
##
## name description
## 1 "$eig" "eigenvalues"
## 2 "$var" "results for the variables"
## 3 "$var$coord" "coord. for the variables"
## 4 "$var$cor" "correlations variables - dimensions"
## 5 "$var$cos2" "cos2 for the variables"
## 6 "$var$contrib" "contributions of the variables"
## 7 "$ind" "results for the individuals"
## 8 "$ind$coord" "coord. for the individuals"
## 9 "$ind$cos2" "cos2 for the individuals"
## 10 "$ind$contrib" "contributions of the individuals"
## 11 "$call" "summary statistics"
## 12 "$call$centre" "mean of the variables"
## 13 "$call$ecart.type" "standard error of the variables"
## 14 "$call$row.w" "weights for the individuals"
## 15 "$call$col.w" "weights for the variables"
This might m+be the most important data of the whole project. These loadings indicate how much each original variable contributes to each principal component (or rather lambda). These are all linear relationships.
Here we can also calculate the R squared by squaring and then summing the squares of how much each variable contributed to both components separately. This value tells us how much of the variable was transferred into the first two components.
For Dim.1:
Age has a negative correlation of -0.2826981 with Dim.1.
Goals has a positive correlation of 0.8329908 with Dim.1.
Assists has a positive correlation of 0.8357638 with Dim.1.
print(Components$var$cor)
## Dim.1 Dim.2
## Age -0.2826981 0.9591459
## Goals 0.8329908 0.1728241
## Assists 0.8357638 0.1521816
print(Components$var$contrib)
## Dim.1 Dim.2
## Age 5.428145 94.550048
## Goals 47.128771 3.069735
## Assists 47.443083 2.380217
print(Components$var$coord)
## Dim.1 Dim.2
## Age -0.2826981 0.9591459
## Goals 0.8329908 0.1728241
## Assists 0.8357638 0.1521816
Next, we can do some more visualization
library(factoextra)
fviz_pca_var(Components, repel = TRUE)
Here we can see the two principal components and each unit being
represented individually.
library(factoextra)
fviz_pca_biplot(Components)
This is an example of a specific unit or player. These are coordinates
for Cristiano Ronaldo, a player of 33 years of age with 18 goals and 11
assists. Generally, his age is higher and so is his goal output. The
first PC component tells us he’s generally above average, which he is,
while the second one is a contrast. He’s not near the average age
profile.
Components$ind$coord[2, ]
## Dim.1 Dim.2
## 4.981459 3.564663
Here we can see Ronaldo’s individual performance. His Goal output is
fairly above 0, even above 3, this means he really performed well
goal-wise. Same for assists. His age is 33, not that extreme, but still
higher than the average.
These values represent standardized data, in the normal distribution,
these values span from [-3 to 3], anything out of that interval
TransfersPCAStandard <- scale(TransfersPCA)
TransfersPCAStandard [2, ]
## Age Goals Assists
## 2.261371 5.922142 2.079778
At number one is the player with the name Kylian Mbappe, his goal and assist output is by far the highest, thus his price was so high.
Components$ind$coord[1, ]
## Dim.1 Dim.2
## 8.8512824 0.6406895
These are coordinates for each variable, we can se how above average his goal output was. Though his age was below average. His goal output that 2018/2019 season really brought him to popularity and to what he is today.
TransfersPCAStandard [1, ]
## Age Goals Assists
## -1.486733 8.587751 3.761986
A final example i would like to point out is the third unit, Thomas Lemar. He ranker third on the most expensive transfer scale.
TransfersPCAStandard [3, ]
## Age Goals Assists
## -0.6835682 0.5909231 4.0423537
We can see that he was fairly younger, and very, very average with the goal output. Though his assists numbers we’re clearly above average, most consider this the reason behind his expensive move in theory. He was a young prospect with much talent and good assist numbers. Yet today, interestingly, he is regarded as being a waste of money as he still cannot score many goals today. Interesting how those three variables interact.
PCA was performed on three standardized variables (n=244). KMO statistics, which were above 0.5 confirm that the variables were appropriate. MSA was also above 0.5 for all. Based on the parallel analysis (and other rules) I retained the first two principled components, though some rules indicated (though barely) said that only one would be a better choice. Those two together accounted for 81% of the total information of the three original variables.
Though I had difficulties naming both Principled components, one could be understood as the general “uniqueness of play” of a player and the other a more “age-considering” factor, maybe even experience.
Here i added the Principled Components into the original dataset.
Transfers$PC1 <- Components$ind$coord[ ,1]
Transfers$PC2 <- Components$ind$coord[ ,2]
head(Transfers)
## Name Position Age League Fee Goals Assists PositionFactor
## 1 Kylian Mbappé 3 19 1 135000000 39 17 Attack
## 2 Cristiano Ronaldo 3 33 1 117000000 28 11 Attack
## 3 Thomas Lemar 3 22 1 70000000 6 18 Attack
## 4 Riyad Mahrez 3 27 1 67800000 12 12 Attack
## 5 Alisson 1 25 2 62500000 0 0 Defence
## 6 Naby Keïta 2 23 2 60000000 14 12 Midfield
## LeagueFactor AgeScaled GoalsScaled AssistsScaled FeeScaled PC1
## 1 West Europe -1.4867333 8.5877509 3.761986 7.851310 8.851282
## 2 West Europe 2.2613707 5.9221416 2.079778 6.682766 4.981459
## 3 West Europe -0.6835682 0.5909231 4.042354 3.631567 3.356146
## 4 West Europe 0.6550404 2.0448918 2.360146 3.488745 2.882770
## 5 East Europe 0.1195970 -0.8630456 -1.004269 3.144674 -1.314775
## 6 East Europe -0.4158464 2.5295480 2.360146 2.982376 3.466184
## PC2
## 1 0.6406895
## 2 3.5646632
## 3 0.0626343
## 4 1.3621355
## 5 -0.1902473
## 6 0.4037880
cor(x=Transfers$PC1, y=Transfers$PC2)
## [1] 1.446992e-16
Adding the categorical variables
fit <- lm(Fee ~ PC1 + PC2 + League + Position, data=Transfers)
library(car)
vif(fit)
## PC1 PC2 League Position
## 1.017808 1.031266 1.030261 1.060992
mean(vif(fit))
## [1] 1.035082
Transfers$StdResid <- rstandard(fit)
Transfers$StdFitted <- scale(fit$fitted.values)
shapiro.test(Transfers$StdResid)
##
## Shapiro-Wilk normality test
##
## data: Transfers$StdResid
## W = 0.85239, p-value = 1.605e-14
With the Shapiro-Wilk test, we can see that it’s not normally distributed.
library(ggplot2)
ggplot(Transfers, aes(y=StdResid, x=StdFitted)) +
theme_dark() +
geom_point(colour = "snow") +
xlab("Standardized residuals") +
ylab("Standardized fitted values")
Linearity looks like it’s just barely being met, homoskedacity
isn’t.
library(olsrr)
##
## Attaching package: 'olsrr'
## The following object is masked from 'package:datasets':
##
## rivers
ols_test_breusch_pagan(fit)
##
## Breusch Pagan Test for Heteroskedasticity
## -----------------------------------------
## Ho: the variance is constant
## Ha: the variance is not constant
##
## Data
## -------------------------------
## Response : Fee
## Variables: fitted values of Fee
##
## Test Summary
## -------------------------------
## DF = 1
## Chi2 = 126.7118
## Prob > Chi2 = 2.148117e-29
The P-Value is too low. Linearity and/or homoskedacity is not met.
head(Transfers[order(Transfers$StdResid), c("Name", "StdResid") ], 5)
## Name StdResid
## 57 Lautaro Martínez -2.541849
## 130 Roger Martínez -2.140622
## 73 Jean-Eudes Aholou -2.065944
## 69 Xherdan Shaqiri -2.018455
## 119 Riccardo Saponara -1.864614
These are all High Impact units. Not appropriate for the data.
Transfers$CooksD <- cooks.distance(fit)
head(Transfers[order(-Transfers$CooksD), c("Name", "CooksD")], 10)
## Name CooksD
## 1 Kylian Mbappé 0.84715446
## 2 Cristiano Ronaldo 0.80170708
## 5 Alisson 0.14194770
## 57 Lautaro Martínez 0.06893563
## 3 Thomas Lemar 0.04713669
## 4 Riyad Mahrez 0.04551139
## 7 Fred 0.02688468
## 29 Bernd Leno 0.02361522
## 51 Paulinho 0.02185073
## 8 Jorginho 0.02148145
These are all players that can be considered outliers. Next step is to eliminate them.
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:pastecs':
##
## first, last
## The following object is masked from 'package:car':
##
## recode
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
Transfers <- Transfers %>%
filter(!Name %in% c("Kylian Mbappé", "Cristiano Ronaldo", "Alisson", "Lautaro Martínez", "Roger Martínez", "Jean-Eudes Aholou", "Xherdan Shaqiri", "Thomas Lemar", "Riyad Mahrez", "Fred"))
shapiro.test(Transfers$StdResid)
##
## Shapiro-Wilk normality test
##
## data: Transfers$StdResid
## W = 0.96125, p-value = 5.998e-06
The test for normality got significantly better, but further data removal would be necessary, normality is violated because the reject the Null Hypothesis, even after removing multiple units.
fit <- lm(Fee ~ PC1 + PC2 + League + Position, data=Transfers)
summary(fit)
##
## Call:
## lm(formula = Fee ~ PC1 + PC2 + League + Position, data = Transfers)
##
## Residuals:
## Min 1Q Median 3Q Max
## -13195859 -4062510 -1060223 2122909 26822734
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 14674868 1423885 10.306 <2e-16 ***
## PC1 7398976 458881 16.124 <2e-16 ***
## PC2 716959 454557 1.577 0.1161
## League -1260575 626707 -2.011 0.0455 *
## Position 248830 521897 0.477 0.6340
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 6574000 on 228 degrees of freedom
## Multiple R-squared: 0.5362, Adjusted R-squared: 0.528
## F-statistic: 65.89 on 4 and 228 DF, p-value: < 2.2e-16
We can see that the only the first is surely statistically significant. The P-value of the second one is too high to be safely implemented into the population.
To answer the research question, there clearly is (or are) some trends that boost football player’s fees and make them a part of the most expensive lists. Goals scored and assists provided is generally an above average trait where football players’ price rises.