####WORKSPACE SETTING####
#working directory
setwd("C:/Users/vitto/Desktop/Chef's Hat 1/Analisi dat")
#clear workspace
rm(list=ls())
#load libraries
library(dplyr)
library(gplots)
library(tseries)
####READ DATA####
#new metrics
NewMetrics <- read.csv("NewMetrics.csv") %>%
#improve readability and adding column to identify rounds uniquely
mutate(player = Source %>% gsub("RANDOM_Random","",.) %>% as.factor,
Source = NULL,
Round = Round %>% as.factor(),
ma.ro=paste(Match,Round,sep="-") %>% as.character,
#Eccentricity=NULL,
)
#old metrics
OldMetrics <- read.csv("OldMetrics.csv") %>%
#improve readability and adding column to identify rounds uniquely
#and removing pizza for now
mutate(player = Source %>% gsub("RANDOM_Random","",.) %>% as.factor,
Source = NULL,
Round = Round %>% as.factor(),
ma.ro=paste(Match,Round,sep="-") %>% as.character,
Eccentricity=NULL,
#convert logical to numerical 0-1
Pizza_Player=Pizza_Player %>% toupper %>% as.logical %>% as.numeric,
)
The new metrics are recorded in a dataset with the scores of attack, defense, vitality and eccentricity of each player for each round.
New metrics dataset subset showing the first match:
NewMetrics[NewMetrics$Match==1,] %>%
print
## Match Round Attack Defense Vitality Eccentricity player ma.ro
## 1 1 1 0 0 1 NA 4 1-1
## 2 1 1 3 0 1 0.030946265 1 1-1
## 3 1 1 0 0 0 NA 2 1-1
## 4 1 1 0 0 0 NA 3 1-1
## 5 1 2 2 0 1 NA 1 1-2
## 6 1 2 0 0 0 NA 2 1-2
## 7 1 2 0 0 0 NA 3 1-2
## 8 1 2 1 2 1 0.000000000 4 1-2
## 9 1 3 1 0 1 NA 4 1-3
## 10 1 3 0 0 0 NA 1 1-3
## 11 1 3 2 1 1 0.019125878 2 1-3
## 12 1 3 0 0 0 NA 3 1-3
## 13 1 4 0 0 1 NA 2 1-4
## 14 1 4 1 2 2 0.000000000 3 1-4
## 15 1 4 2 0 1 NA 4 1-4
## 16 1 4 0 0 0 NA 1 1-4
## 17 1 5 1 2 2 0.000000000 3 1-5
## 18 1 5 2 0 1 NA 4 1-5
## 19 1 5 0 0 0 NA 1 1-5
## 20 1 5 0 0 0 NA 2 1-5
## 21 1 6 0 0 1 NA 3 1-6
## 22 1 6 0 0 1 NA 4 1-6
## 23 1 6 3 0 1 0.018888043 1 1-6
## 24 1 6 0 0 0 NA 2 1-6
## 25 1 7 0 0 0 NA 1 1-7
## 26 1 7 0 1 1 NA 2 1-7
## 27 1 7 2 1 1 0.030870951 3 1-7
## 28 1 7 0 0 0 NA 4 1-7
## 29 1 8 2 0 1 NA 3 1-8
## 30 1 8 0 0 0 NA 4 1-8
## 31 1 8 0 0 0 NA 1 1-8
## 32 1 8 1 2 1 0.037795906 2 1-8
## 33 1 9 1 0 1 NA 2 1-9
## 34 1 9 0 0 0 NA 3 1-9
## 35 1 9 2 1 1 0.000000000 4 1-9
## 36 1 9 0 0 0 NA 1 1-9
## 37 1 10 0 0 1 NA 4 1-10
## 38 1 10 1 0 1 NA 1 1-10
## 39 1 10 0 0 0 NA 2 1-10
## 40 1 10 2 1 1 0.008546195 3 1-10
## 41 1 11 0 0 0 NA 3 1-11
## 42 1 11 0 1 1 NA 4 1-11
## 43 1 11 0 1 1 NA 1 1-11
## 44 1 11 2 1 1 0.000000000 2 1-11
## 45 1 12 0 0 1 NA 2 1-12
## 46 1 12 3 0 1 0.000000000 3 1-12
## 47 1 12 0 0 0 NA 4 1-12
## 48 1 12 0 0 0 NA 1 1-12
## 49 1 13 1 0 1 NA 3 1-13
## 50 1 13 0 0 0 NA 4 1-13
## 51 1 13 2 1 1 0.000000000 1 1-13
## 52 1 13 0 0 0 NA 2 1-13
## 53 1 14 0 0 0 NA 1 1-14
## 54 1 14 0 0 0 NA 2 1-14
## 55 1 14 0 0 0 NA 3 1-14
## 56 1 14 0 3 1 0.000000000 4 1-14
## 57 1 15 0 0 0 NA 4 1-15
## 58 1 15 1 1 1 NA 1 1-15
## 59 1 15 0 0 0 NA 2 1-15
## 60 1 15 1 2 1 0.018182467 3 1-15
## 61 1 16 0 0 0 NA 3 1-16
## 62 1 16 0 0 0 NA 4 1-16
## 63 1 16 0 2 1 NA 1 1-16
## 64 1 16 1 2 1 0.046195437 2 1-16
## 65 1 17 3 0 1 0.066415355 2 1-17
## 66 1 17 0 0 0 NA 3 1-17
## 67 1 17 0 0 0 NA 4 1-17
## 68 1 17 0 0 0 NA 1 1-17
## 69 1 18 0 0 0 NA 2 1-18
## 70 1 18 2 1 1 0.049707463 3 1-18
## 71 1 18 0 0 0 NA 4 1-18
## 72 1 18 0 0 0 NA 1 1-18
## 73 1 19 3 0 1 0.000000000 3 1-19
## 74 1 19 0 0 0 NA 4 1-19
## 75 1 19 0 0 0 NA 1 1-19
## 76 1 19 0 0 0 NA 2 1-19
## 77 1 20 3 0 1 0.000000000 3 1-20
## 78 1 20 0 0 0 NA 4 1-20
## 79 1 20 0 0 0 NA 1 1-20
## 80 1 20 0 0 0 NA 2 1-20
For the old metrics we used a dataset with the number of discards and passes and who made the pizza each round in the same matches as above.
Old metrics dataset subset showing the first match:
OldMetrics[OldMetrics$Match==1,] %>%
print
## Match Round Number_Pass Number_Discard Pizza_Player player ma.ro
## 1 1 1 1 2 0 4 1-1
## 2 1 1 0 3 1 1 1-1
## 3 1 1 1 0 0 2 1-1
## 4 1 1 1 0 0 3 1-1
## 5 1 2 1 4 0 1 1-2
## 6 1 2 1 0 0 2 1-2
## 7 1 2 1 0 0 3 1-2
## 8 1 2 0 3 1 4 1-2
## 9 1 3 1 2 0 4 1-3
## 10 1 3 1 0 0 1 1-3
## 11 1 3 0 1 1 2 1-3
## 12 1 3 1 0 0 3 1-3
## 13 1 4 1 1 0 2 1-4
## 14 1 4 0 2 1 3 1-4
## 15 1 4 1 1 0 4 1-4
## 16 1 4 1 0 0 1 1-4
## 17 1 5 0 2 1 3 1-5
## 18 1 5 1 1 0 4 1-5
## 19 1 5 1 0 0 1 1-5
## 20 1 5 1 0 0 2 1-5
## 21 1 6 1 2 0 3 1-6
## 22 1 6 1 2 0 4 1-6
## 23 1 6 0 3 1 1 1-6
## 24 1 6 1 0 0 2 1-6
## 25 1 7 1 0 0 1 1-7
## 26 1 7 1 1 0 2 1-7
## 27 1 7 0 2 1 3 1-7
## 28 1 7 1 0 0 4 1-7
## 29 1 8 1 1 0 3 1-8
## 30 1 8 1 0 0 4 1-8
## 31 1 8 1 0 0 1 1-8
## 32 1 8 0 1 1 2 1-8
## 33 1 9 1 1 0 2 1-9
## 34 1 9 1 0 0 3 1-9
## 35 1 9 0 1 1 4 1-9
## 36 1 9 1 0 0 1 1-9
## 37 1 10 1 1 0 4 1-10
## 38 1 10 1 1 0 1 1-10
## 39 1 10 1 0 0 2 1-10
## 40 1 10 0 1 1 3 1-10
## 41 1 11 1 0 0 3 1-11
## 42 1 11 1 1 0 4 1-11
## 43 1 11 1 1 0 1 1-11
## 44 1 11 0 1 1 2 1-11
## 45 1 12 1 1 0 2 1-12
## 46 1 12 0 1 1 3 1-12
## 47 1 12 1 0 0 4 1-12
## 48 1 12 1 0 0 1 1-12
## 49 1 13 1 1 0 3 1-13
## 50 1 13 1 0 0 4 1-13
## 51 1 13 0 1 1 1 1-13
## 52 1 13 1 0 0 2 1-13
## 53 1 14 1 0 0 1 1-14
## 54 1 14 1 0 0 2 1-14
## 55 1 14 1 0 0 3 1-14
## 56 1 14 0 1 1 4 1-14
## 57 1 15 1 0 0 4 1-15
## 58 1 15 1 1 0 1 1-15
## 59 1 15 1 0 0 2 1-15
## 60 1 15 0 1 1 3 1-15
## 61 1 16 1 0 0 3 1-16
## 62 1 16 1 0 0 4 1-16
## 63 1 16 1 1 0 1 1-16
## 64 1 16 0 2 1 2 1-16
## 65 1 17 0 3 1 2 1-17
## 66 1 17 1 0 0 3 1-17
## 67 1 17 1 0 0 4 1-17
## 68 1 17 1 0 0 1 1-17
## 69 1 18 1 0 0 2 1-18
## 70 1 18 0 2 1 3 1-18
## 71 1 18 1 0 0 4 1-18
## 72 1 18 1 0 0 1 1-18
## 73 1 19 0 1 1 3 1-19
## 74 1 19 1 0 0 4 1-19
## 75 1 19 1 0 0 1 1-19
## 76 1 19 1 0 0 2 1-19
## 77 1 20 0 1 1 3 1-20
## 78 1 20 1 0 0 4 1-20
## 79 1 20 1 0 0 1 1-20
## 80 1 20 1 0 0 2 1-20
Correlation within players did not change from player to player, as expected from the fact that these are random agents.
corMat <- NewMetrics[NewMetrics$player==1,] %>%
select(Attack,Defense,Vitality,Eccentricity) %>%
cor(use="pairwise") %>%
round(2)
corMat_new_rnd <- corMat
heatmap.2(1-abs(corMat),
Rowv = F,
Colv = F,
dendrogram="none",
symm=T,
scale="none",
revC=F,
cellnote=matrix(gsub("0.",".",corMat,fixed=T),ncol=ncol(corMat),nrow=ncol(corMat)),
trace = "none",
notecol = "black",
notecex=1,
key=F,
keysize=1,
margins = c(6,6),
col=hcl.colors(100,"mint"),
cexRow = 1,
cexCol = 1,
offsetRow = 0.01,
offsetCol = 0.01,
main="Correlation of indexes within player 1"
)
Some observations (assuming correlation is due to a causal link from player 1 to player 2, as the other way around seems unlikely) :
for (i in 1:6){
j <- combn(4,2)[,i]
corMat <- cor(
NewMetrics[NewMetrics$player==j[1],c("Attack","Defense","Vitality","Eccentricity")],
NewMetrics[NewMetrics$player==j[2],c("Attack","Defense","Vitality","Eccentricity")],
use="pairwise") %>%
data.frame %>%
`rownames<-`(paste(c("Atk","Def","Vit","Ecc"),j[1])) %>%
`colnames<-`(paste(c("Atk","Def","Vit","Ecc"),j[2])) %>%
as.matrix %>%
round(2)
heatmap.2(1-abs(corMat),
Rowv = F,
Colv = F,
dendrogram="none",
symm=T,
scale="none",
revC=F,
cellnote=matrix(gsub("0.",".",corMat,fixed=T),ncol=ncol(corMat),nrow=ncol(corMat)),
trace = "none",
notecol = "black",
notecex=1,
key=F,
keysize=1,
margins = c(6,6),
col=hcl.colors(100,"mint"),
cexRow = 1,
cexCol = 1,
offsetRow = 0.01,
offsetCol = 0.01,
main=paste("Correlation between player",j[1],"and",j[2])
)
}
The number of passes and the pizza player seem to be the same information, and it makes sense since the player that doesn’t pass makes the pizza. One row is just the opposite of the other (in a TRUE/FALSE sense). I’m surprised the correlation is not exactly -1 but I guess it’s just some hiccups in the data.
corMat <- OldMetrics[OldMetrics$player==1,] %>%
select(Number_Pass,Number_Discard,Pizza_Player) %>%
cor(use="pairwise") %>%
round(2)
corMat_old_rnd <- corMat
heatmap.2(1-abs(corMat),
Rowv = F,
Colv = F,
dendrogram="none",
symm=T,
scale="none",
revC=F,
cellnote=matrix(gsub("0.",".",corMat,fixed=T),ncol=ncol(corMat),nrow=ncol(corMat)),
trace = "none",
notecol = "black",
notecex=1,
key=F,
keysize=1,
margins = c(6,6),
col=hcl.colors(100,"mint"),
cexRow = 1,
cexCol = 1,
offsetRow = 0.01,
offsetCol = 0.01,
main="Correlation of indexes within player 1"
)
for (i in 1:6){
j <- combn(4,2)[,i]
corMat <- cor(
OldMetrics[OldMetrics$player==j[1],c("Number_Pass","Number_Discard","Pizza_Player")],
OldMetrics[OldMetrics$player==j[2],c("Number_Pass","Number_Discard","Pizza_Player")],
use="pairwise") %>%
data.frame %>%
`rownames<-`(paste(c("Pass","Disc","Pizza"),j[1])) %>%
`colnames<-`(paste(c("Pass","Disc","Pizza"),j[2])) %>%
as.matrix %>%
round(2)
heatmap.2(1-abs(corMat),
Rowv = F,
Colv = F,
dendrogram="none",
symm=T,
scale="none",
revC=F,
cellnote=matrix(gsub("0.",".",corMat,fixed=T),ncol=ncol(corMat),nrow=ncol(corMat)),
trace = "none",
notecol = "black",
notecex=1,
key=F,
keysize=1,
margins = c(6,6),
col=hcl.colors(100,"mint"),
cexRow = 1,
cexCol = 1,
offsetRow = 0.01,
offsetCol = 0.01,
main=paste("Correlation between player",j[1],"and",j[2])
)
}
Eccentricity seems to be the big novelty-introducing metric! With defense it’s the only one that doesn’t seem redundant with other metrics and shares a very small portion of variance with the old metrics.
corMat <- cor(
cbind(OldMetrics[,c("Number_Pass","Number_Discard","Pizza_Player")]," "=rep(NA,nrow(OldMetrics))),
NewMetrics[,c("Attack","Defense","Vitality","Eccentricity")],
use="pairwise") %>%
round(2)
## Warning in cor(cbind(OldMetrics[, c("Number_Pass", "Number_Discard",
## "Pizza_Player")], : la deviazione standard è zero
heatmap.2(1-abs(corMat),
Rowv = F,
Colv = F,
dendrogram="none",
symm=T,
scale="none",
revC=F,
cellnote=matrix(gsub("0.",".",corMat,fixed=T),ncol=ncol(corMat),nrow=ncol(corMat)),
trace = "none",
notecol = "black",
notecex=1,
key=F,
keysize=1,
margins = c(6,6),
col=hcl.colors(100,"mint"),
cexRow = 1,
cexCol = 1,
offsetRow = 0.01,
offsetCol = 0.01,
main="Correlation of indexes within player 1"
)
All the correlation within player 1 in one big table
corMat <- cor(
cbind(OldMetrics[,c("Number_Pass","Number_Discard","Pizza_Player")],NewMetrics[,c("Attack","Defense","Vitality","Eccentricity")]),
use="pairwise") %>%
round(2)
## Warning in cor(cbind(OldMetrics[, c("Number_Pass", "Number_Discard",
## "Pizza_Player")], : la deviazione standard è zero
corMat_rnd <- corMat
heatmap.2(1-abs(corMat),
Rowv = F,
Colv = F,
dendrogram="none",
symm=T,
scale="none",
revC=F,
cellnote=matrix(gsub("0.",".",corMat,fixed=T),ncol=ncol(corMat),nrow=ncol(corMat)),
trace = "none",
notecol = "black",
notecex=1,
key=F,
keysize=1,
margins = c(6,6),
col=hcl.colors(100,"mint"),
cexRow = 1,
cexCol = 1,
offsetRow = 0.01,
offsetCol = 0.01,
main="Correlation of indexes within player 1"
)
####READ DATA####
#new metrics
NewMetrics <- read.csv("LargerValuevsRandom.csv") %>%
#improve readability and adding column to identify rounds uniquely
mutate(Player = Source %>% gsub("LARGER_VALUE_0|RANDOM_0","",.) %>% as.factor,
Source = NULL,
Round = Round %>% as.factor(),
ma.ro=paste(Match,Round,sep="-") %>% as.character,
#Eccentricity=NULL,
)
#old metrics
OldMetrics <- read.csv("LargerValuevsRandom_OldMetrics.csv") %>%
#improve readability and adding column to identify rounds uniquely
#and removing pizza for now
mutate(player = Source %>% gsub("LARGER_VALUE_0|RANDOM_0","",.) %>% as.factor,
Source = NULL,
Round = Round %>% as.factor(),
ma.ro=paste(Match,Round,sep="-") %>% as.character,
#convert logical to numerical 0-1
Pizza_Player=Pizza_Player %>% toupper %>% as.logical %>% as.numeric,
)
New metrics dataset subset showing the first match:
NewMetrics[NewMetrics$Match==1,] %>%
print
## Match Round Attack Defense Vitality Eccentricity Player ma.ro
## 1 1 1 0 0 1 NA 2 1-1
## 2 1 1 0 0 1 NA 3 1-1
## 3 1 1 3 0 1 0.05643422 4 1-1
## 4 1 1 0 0 0 NA 1 1-1
## 5 1 2 0 0 1 NA 4 1-2
## 6 1 2 0 0 1 NA 1 1-2
## 7 1 2 3 0 1 0.02096910 2 1-2
## 8 1 2 0 0 0 NA 3 1-2
## 9 1 3 0 0 1 NA 2 1-3
## 10 1 3 1 0 1 NA 3 1-3
## 11 1 3 0 0 0 NA 4 1-3
## 12 1 3 2 1 1 0.00000000 1 1-3
## 13 1 4 3 0 1 0.06665715 1 1-4
## 14 1 4 0 0 0 NA 2 1-4
## 15 1 4 0 0 0 NA 3 1-4
## 16 1 4 0 0 0 NA 4 1-4
## 17 1 5 1 0 1 NA 1 1-5
## 18 1 5 0 0 0 NA 2 1-5
## 19 1 5 2 1 1 0.00000000 3 1-5
## 20 1 5 0 0 0 NA 4 1-5
## 21 1 6 0 0 0 NA 3 1-6
## 22 1 6 2 1 1 0.05478127 4 1-6
## 23 1 6 0 0 0 NA 1 1-6
## 24 1 6 0 0 0 NA 2 1-6
## 25 1 7 0 0 1 NA 4 1-7
## 26 1 7 3 0 1 0.00000000 1 1-7
## 27 1 7 0 0 0 NA 2 1-7
## 28 1 7 0 0 0 NA 3 1-7
## 29 1 8 0 0 1 NA 1 1-8
## 30 1 8 3 0 1 0.04312340 2 1-8
## 31 1 8 0 0 0 NA 3 1-8
## 32 1 8 0 0 0 NA 4 1-8
## 33 1 9 0 0 0 NA 2 1-9
## 34 1 9 2 1 1 0.04975899 3 1-9
## 35 1 9 0 0 0 NA 4 1-9
## 36 1 9 0 0 0 NA 1 1-9
## 37 1 10 0 0 1 NA 3 1-10
## 38 1 10 0 0 1 NA 4 1-10
## 39 1 10 1 2 2 0.00000000 1 1-10
## 40 1 10 2 0 1 NA 2 1-10
## 41 1 11 3 0 1 0.00000000 1 1-11
## 42 1 11 0 0 0 NA 2 1-11
## 43 1 11 0 0 0 NA 3 1-11
## 44 1 11 0 0 0 NA 4 1-11
## 45 1 12 3 0 1 0.00000000 1 1-12
## 46 1 12 0 0 0 NA 2 1-12
## 47 1 12 0 0 0 NA 3 1-12
## 48 1 12 0 0 0 NA 4 1-12
Old metrics dataset subset showing the first match:
OldMetrics[OldMetrics$Match==1,] %>%
print
## X Match Round Number_Pass Number_Discard Pizza_Player player ma.ro
## 1 0 1 1 1 1 0 2 1-1
## 2 1 1 1 1 1 0 3 1-1
## 3 2 1 1 0 2 1 4 1-1
## 4 3 1 1 1 0 0 1 1-1
## 5 4 1 2 1 2 0 4 1-2
## 6 5 1 2 1 2 0 1 1-2
## 7 6 1 2 0 3 1 2 1-2
## 8 7 1 2 1 0 0 3 1-2
## 9 8 1 3 1 1 0 2 1-3
## 10 9 1 3 1 2 0 3 1-3
## 11 10 1 3 1 0 0 4 1-3
## 12 11 1 3 0 2 1 1 1-3
## 13 12 1 4 0 3 1 1 1-4
## 14 13 1 4 1 0 0 2 1-4
## 15 14 1 4 1 0 0 3 1-4
## 16 15 1 4 1 0 0 4 1-4
## 17 16 1 5 1 3 0 1 1-5
## 18 17 1 5 1 0 0 2 1-5
## 19 18 1 5 0 3 1 3 1-5
## 20 19 1 5 1 0 0 4 1-5
## 21 20 1 6 1 0 0 3 1-6
## 22 21 1 6 0 2 1 4 1-6
## 23 22 1 6 1 0 0 1 1-6
## 24 23 1 6 1 0 0 2 1-6
## 25 24 1 7 1 2 0 4 1-7
## 26 25 1 7 0 2 1 1 1-7
## 27 26 1 7 1 0 0 2 1-7
## 28 27 1 7 1 0 0 3 1-7
## 29 28 1 8 1 1 0 1 1-8
## 30 29 1 8 0 2 1 2 1-8
## 31 30 1 8 1 0 0 3 1-8
## 32 31 1 8 1 0 0 4 1-8
## 33 32 1 9 1 0 0 2 1-9
## 34 33 1 9 0 2 1 3 1-9
## 35 34 1 9 1 0 0 4 1-9
## 36 35 1 9 1 0 0 1 1-9
## 37 36 1 10 1 1 0 3 1-10
## 38 37 1 10 1 1 0 4 1-10
## 39 38 1 10 0 2 1 1 1-10
## 40 39 1 10 1 1 0 2 1-10
## 41 40 1 11 0 1 1 1 1-11
## 42 41 1 11 1 0 0 2 1-11
## 43 42 1 11 1 0 0 3 1-11
## 44 43 1 11 1 0 0 4 1-11
## 45 44 1 12 0 1 1 1 1-12
## 46 45 1 12 1 0 0 2 1-12
## 47 46 1 12 1 0 0 3 1-12
## 48 47 1 12 1 0 0 4 1-12
Main differences:
Everything else remains mostly the same.
corMat <- NewMetrics[NewMetrics$Player==1,] %>%
select(Attack,Defense,Vitality,Eccentricity) %>%
cor(use="pairwise") %>%
round(2)
corMat_new_long <- corMat
heatmap.2(1-abs(corMat),
Rowv = F,
Colv = F,
dendrogram="none",
symm=T,
scale="none",
revC=F,
cellnote=matrix(gsub("0.",".",corMat,fixed=T),ncol=ncol(corMat),nrow=ncol(corMat)),
trace = "none",
notecol = "black",
notecex=1,
key=F,
keysize=1,
margins = c(6,6),
col=hcl.colors(100,"mint"),
cexRow = 1,
cexCol = 1,
offsetRow = 0.01,
offsetCol = 0.01,
main="Correlation of indexes within player 1"
)
for (i in 1:6){
j <- combn(4,2)[,i]
corMat <- cor(
NewMetrics[NewMetrics$Player==j[1],c("Attack","Defense","Vitality","Eccentricity")],
NewMetrics[NewMetrics$Player==j[2],c("Attack","Defense","Vitality","Eccentricity")],
use="pairwise") %>%
data.frame %>%
`rownames<-`(paste(c("Atk","Def","Vit","Ecc"),j[1])) %>%
`colnames<-`(paste(c("Atk","Def","Vit","Ecc"),j[2])) %>%
as.matrix %>%
round(2)
heatmap.2(1-abs(corMat),
Rowv = F,
Colv = F,
dendrogram="none",
symm=T,
scale="none",
revC=F,
cellnote=matrix(gsub("0.",".",corMat,fixed=T),ncol=ncol(corMat),nrow=ncol(corMat)),
trace = "none",
notecol = "black",
notecex=1,
key=F,
keysize=1,
margins = c(6,6),
col=hcl.colors(100,"mint"),
cexRow = 1,
cexCol = 1,
offsetRow = 0.01,
offsetCol = 0.01,
main=paste("Correlation between player",j[1],"and",j[2])
)
}
## Warning in cor(NewMetrics[NewMetrics$Player == j[1], c("Attack", "Defense", :
## la deviazione standard è zero
## Warning in cor(NewMetrics[NewMetrics$Player == j[1], c("Attack", "Defense", :
## la deviazione standard è zero
## Warning in cor(NewMetrics[NewMetrics$Player == j[1], c("Attack", "Defense", :
## la deviazione standard è zero
corMat <- OldMetrics[OldMetrics$player==1,] %>%
select(Number_Pass,Number_Discard,Pizza_Player) %>%
cor(use="pairwise") %>%
round(2)
corMat_old_long <- corMat
heatmap.2(1-abs(corMat),
Rowv = F,
Colv = F,
dendrogram="none",
symm=T,
scale="none",
revC=F,
cellnote=matrix(gsub("0.",".",corMat,fixed=T),ncol=ncol(corMat),nrow=ncol(corMat)),
trace = "none",
notecol = "black",
notecex=1,
key=F,
keysize=1,
margins = c(6,6),
col=hcl.colors(100,"mint"),
cexRow = 1,
cexCol = 1,
offsetRow = 0.01,
offsetCol = 0.01,
main="Correlation of indexes within player 1"
)
for (i in 1:6){
j <- combn(4,2)[,i]
corMat <- cor(
OldMetrics[OldMetrics$player==j[1],c("Number_Pass","Number_Discard","Pizza_Player")],
OldMetrics[OldMetrics$player==j[2],c("Number_Pass","Number_Discard","Pizza_Player")],
use="pairwise") %>%
data.frame %>%
`rownames<-`(paste(c("Pass","Disc","Pizza"),j[1])) %>%
`colnames<-`(paste(c("Pass","Disc","Pizza"),j[2])) %>%
as.matrix %>%
round(2)
heatmap.2(1-abs(corMat),
Rowv = F,
Colv = F,
dendrogram="none",
symm=T,
scale="none",
revC=F,
cellnote=matrix(gsub("0.",".",corMat,fixed=T),ncol=ncol(corMat),nrow=ncol(corMat)),
trace = "none",
notecol = "black",
notecex=1,
key=F,
keysize=1,
margins = c(6,6),
col=hcl.colors(100,"mint"),
cexRow = 1,
cexCol = 1,
offsetRow = 0.01,
offsetCol = 0.01,
main=paste("Correlation between player",j[1],"and",j[2])
)
}
corMat <- cor(
cbind(OldMetrics[,c("Number_Pass","Number_Discard","Pizza_Player")]," "=rep(NA,nrow(OldMetrics))),
NewMetrics[,c("Attack","Defense","Vitality","Eccentricity")],
use="pairwise") %>%
round(2)
## Warning in cor(cbind(OldMetrics[, c("Number_Pass", "Number_Discard",
## "Pizza_Player")], : la deviazione standard è zero
heatmap.2(1-abs(corMat),
Rowv = F,
Colv = F,
dendrogram="none",
symm=T,
scale="none",
revC=F,
cellnote=matrix(gsub("0.",".",corMat,fixed=T),ncol=ncol(corMat),nrow=ncol(corMat)),
trace = "none",
notecol = "black",
notecex=1,
key=F,
keysize=1,
margins = c(6,6),
col=hcl.colors(100,"mint"),
cexRow = 1,
cexCol = 1,
offsetRow = 0.01,
offsetCol = 0.01,
main="Correlation of indexes within player 1"
)
corMat <- cor(
cbind(OldMetrics[,c("Number_Pass","Number_Discard","Pizza_Player")],NewMetrics[,c("Attack","Defense","Vitality","Eccentricity")]),
use="pairwise") %>%
round(2)
## Warning in cor(cbind(OldMetrics[, c("Number_Pass", "Number_Discard",
## "Pizza_Player")], : la deviazione standard è zero
corMat_Large <- corMat
heatmap.2(1-abs(corMat),
Rowv = F,
Colv = F,
dendrogram="none",
symm=T,
scale="none",
revC=F,
cellnote=matrix(gsub("0.",".",corMat,fixed=T),ncol=ncol(corMat),nrow=ncol(corMat)),
trace = "none",
notecol = "black",
notecex=1,
key=F,
keysize=1,
margins = c(6,6),
col=hcl.colors(100,"mint"),
cexRow = 1,
cexCol = 1,
offsetRow = 0.01,
offsetCol = 0.01,
main="Correlation of indexes within player 1"
)
Difference between the within player 1 correlation matrix of the random agent and the largest value agent for the two types of indicators. The new indexes show a greater difference, potentially meaning that they better discriminate between different players. But let’s wait for the cluster analysis to draw conclusions.
corDiff_new <- corMat_new_rnd - corMat_new_long
print(corDiff_new)
## Attack Defense Vitality Eccentricity
## Attack 0.00 0.22 0.25 0.06
## Defense 0.22 0.00 -0.12 -0.05
## Vitality 0.25 -0.12 0.00 0.03
## Eccentricity 0.06 -0.05 0.03 0.00
corDiff_old <- corMat_old_rnd - corMat_old_long
print(corDiff_old)
## Number_Pass Number_Discard Pizza_Player
## Number_Pass 0.00 -0.13 -0.02
## Number_Discard -0.13 0.00 0.12
## Pizza_Player -0.02 0.12 0.00
The following are the time plots showing the behaviour of the index within one game. Each color is a different player (player one, the largest value player, is the darkest). The first 20 games have been plotted.
Frankly I don’t see any pattern :)
####TIME SERIES ANALYSIS####
####Time serie within a game####
for(a in c("Vitality","Attack","Defense")){
for(i in 1:20){
NewMetrics %>%
filter(NewMetrics$Player==1,NewMetrics$Match==i) %>%
select(all_of(a)) %>%
ts %>%
plot(lwd=2,col="aquamarine4",main=paste(a,"Match",i))
NewMetrics %>%
filter(NewMetrics$Player==2,NewMetrics$Match==i) %>%
select(all_of(a)) %>%
ts %>%
lines(lwd=2,col="aquamarine3")
NewMetrics%>%
filter(NewMetrics$Player==3,NewMetrics$Match==i) %>%
select(all_of(a)) %>%
ts %>%
lines(lwd=2,col="aquamarine2")
NewMetrics %>%
filter(NewMetrics$Player==4,NewMetrics$Match==i) %>%
select(all_of(a)) %>%
ts %>%
lines(lwd=2,col="aquamarine1")
}
}
The autocorrelograms show that both a high vitality and attack positively and significantly predict respective ly a high vitality and attack in the next round within the same player (there seems to be also a negative correlation after lag two for a few turns, but it’s very small, it may suggest some regular fluctuations, maybe if I had a high attack now the game is designed in such a way that it’s more probable that my attack will decrease further down the line. However, the effect size is negligible.) This is not depentend on the strategy of the player, at least for the two currently analysed. The other metrics have no impact on future turns.
Let me know if it could be interesting to explore this effect between players.
####Autocorrelogram####
for(a in c("Vitality","Attack","Defense","Eccentricity")){
NewMetrics[NewMetrics$Player==1,] %>%
select(a) %>%
na.omit %>%
ts %>%
acf(main=paste(a,"Largest Value"))
NewMetrics[NewMetrics$Player==2,] %>%
select(a) %>%
na.omit %>%
ts %>%
acf(main=paste(a,"Random"))
}
## Warning: Using an external vector in selections was deprecated in tidyselect 1.1.0.
## ℹ Please use `all_of()` or `any_of()` instead.
## # Was:
## data %>% select(a)
##
## # Now:
## data %>% select(all_of(a))
##
## See <https://tidyselect.r-lib.org/reference/faq-external-vector.html>.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.