ARCHETYPAL ANALYSIS IN R

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

ARCHETYPAL ANALYSIS IN R

euthymios kasvikis
To whom it may concern
I am a postgraduate student in Aristotle University of Thessaloniki and a
recent user of R also writing my thesis statement on a Sport Analytics tool
based on Pr.Eugster's work on Archetypal Analysis.
The problem is that after importing the data-set i want to work with, i
cannot "run" Pr Eugster's script which he wrote for his own analysis on NBA
Statistics.I am sending you not only the code but also the data-set i use.
How could i adjust this code on my data-set?
Thank you in advance for your patience and cooperation.

@demo Archetypal basketball players based on player statistics;
#'   analysis from the manuscript "Archetypal athletes" by Eugster
#'   (2011)

library("SportsAnalytics")
library("archetypes")
library("RColorBrewer")

col_pal <- brewer.pal(7, "Set1")
col_black <- rgb(0, 0, 0, 0.2)



### Data: ############################################################

data("NBAPlayerStatistics0910")

dat <- subset(NBAPlayerStatistics0910,
              select = -c(Ejections, FlagrantFouls))

mat <- as.matrix(subset(dat, select = -c(League, Name, Team, Position)))


pcplot(mat, col = col_black, las = 2)



### Archetypes: ######################################################

set.seed(4321)
as <- stepArchetypes(mat, k = 1:10)

rss(as)
screeplot(as)


a4 <- bestModel(as[[4]])


### Archetypal basketball players:

parameters(a4)
barplot(a4, mat, percentiles = TRUE)



### Player interpretation: ###########################################

players <- function(which) {
  players <- list()
  players$which <- which
  players$mat <- mat[which, ]
  players$coef <- coef(a4, "alphas")[which, ]
  players$dat <- dat[which, ]

  players
}


### Archetypal players:

which <- apply(coef(a4, "alphas"), 2, which.max)
atypes <- players(which)

cbind(subset(atypes$dat, select = c(Name, Team, Position)),
      atypes$coef)



### Good players:

good_players <- function(atype, threshold) {
  which <- which(coef(a4, "alphas")[, atype] > threshold)

  good_coef <- coef(a4, "alphas")[which, ]
  good_dat <- subset(dat[which, ], select = c(Name, Team, Position))
  good_dat <- cbind(good_dat, good_coef)
  good_dat <- good_dat[order(-good_coef[, atype]), ]

  good_dat
}


good_threshold <- 0.95

players <- lapply(2:4, good_players, good_threshold)
players

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

DE 2001.txt (34K) Download Attachment