#SPORTIVE EXAMPLE:
#Database:
if(nzchar(system.file(package = "SportsAnalytics"))){
data("NBAPlayerStatistics0910", package = "SportsAnalytics")
}
mat <- NBAPlayerStatistics0910[,c("TotalMinutesPlayed","FieldGoalsMade")]
rownames(mat) <- NULL
#Calculating archetypes by using the archetype algorithm:
#Data preprocessing:
preproc <- accommodation(mat,stand=TRUE,percAccomm=1)
#For reproducing results, seed for randomness:
set.seed(4321)
#Run archetype algorithm repeatedly from 1 to 15 archetypes:
lass15 <- stepArchetypesMod(data=preproc,k=1:15,verbose=FALSE,nrep=20)
screeplot(lass15)
#Calculating real archetypes:
i <- 3 #number of archetypoids.
res <- archetypoids(i,preproc,huge=200,step=FALSE,ArchObj=lass15,nearest=TRUE,sequ=TRUE)
arquets <- NBAPlayerStatistics0910[res[[1]],c("Name","TotalMinutesPlayed","FieldGoalsMade")]
res_which <- archetypoids(i,preproc,huge=200,step=FALSE,ArchObj=lass15,nearest=FALSE,sequ=TRUE)
arquets_eug <- NBAPlayerStatistics0910[res_which[[1]],
c("Name","TotalMinutesPlayed","FieldGoalsMade")]
col_pal <- RColorBrewer::brewer.pal(7, "Set1")
col_black <- rgb(0, 0, 0, 0.2)
plot(mat, pch = 1, col = col_black, xlim = c(0,3500), main = "NBA archetypal basketball
players \n obtained in Eugster (2012) \n and with our proposal",
xlab = "Total minutes played", ylab = "Field goals made")
points(mat[as.numeric(rownames(arquets)),], pch = 4, col = col_pal[1])
points(mat[as.numeric(rownames(arquets_eug)),], pch = 4, col = col_pal[1])
text(mat[as.numeric(rownames(arquets_eug)),][2,1],
mat[as.numeric(rownames(arquets_eug)),][2,2],
labels = arquets_eug[2,"Name"], pos = 4, col = "blue")
plotrix::textbox(c(50,800), 50, "Travis Diener")
plotrix::textbox(c(2800,3500), 780, "Kevin Durant", col = "blue")
plotrix::textbox(c(2800,3500), 270, "Jason Kidd", col = "blue")
legend("topleft",c("archetypes of Eugster","archetypes of our proposal"),
lty= c(1,NA), pch = c(NA,22), col = c("blue","black"))
#If a specific number of archetypes is computed only:
i=3
set.seed(4321)
lass3 <- stepArchetypesMod(data=preproc,k=i,verbose=FALSE,nrep=3)
res3 <- archetypoids(i,preproc,huge=200,step=FALSE,ArchObj=lass3,nearest=TRUE,sequ=FALSE,aux=2)
arquets3 <- NBAPlayerStatistics0910[res3[[1]],c("Name","TotalMinutesPlayed","FieldGoalsMade")]
#COCKPIT DESIGN PROBLEM:
m <- dataUSAF
#Variable selection:
sel <- c(48,40,39,33,34,36)
#Changing to inches:
mpulg <- m[,sel] / (10 * 2.54)
#Data preprocessing:
preproc <- accommodation(mpulg,TRUE,0.95,TRUE)
#For reproducing results, seed for randomness:
set.seed(2010)
#Run archetype algorithm repeatedly from 1 to numArch archetypes:
numArch <- 10 ; nrep <- 20
lass <- stepArchetypesMod(data=preproc$data,k=1:numArch,verbose=FALSE,nrep=nrep)
screeplot(lass)
i <- 3 #number of archetypoids.
res <- archetypoids(i,preproc$data,huge=200,step=FALSE,ArchObj=lass,nearest=TRUE,sequ=TRUE)
res_which <- archetypoids(i,preproc$data,huge=200,step=FALSE,ArchObj=lass,nearest=FALSE,sequ=TRUE)
Run the code above in your browser using DataLab