※ 当サイトは、アフィリエイト広告を利用しています。

【NBA2011-12 レギュラー・シーズン】NBAチームとプレイヤーから見るリーグ全体の特徴と傾向

記事内に広告が含まれています。
スポンサーリンク
スポンサーリンク

※参考<統計ソフトRに入力するコマンド>

統計ソフトRのインストール手順をまとめた記事も作成していますので、よろしければご参考ください。

library(BasketballAnalyzeR)
library(gridExtra)
Tbox1112 <- read.csv(file="Tbox_1112.csv")
Obox1112 <- read.csv(file="Obox_1112.csv")
Tadd1112 <- read.csv(file="Tadd_1112.csv")
Pbox1112 <- read.csv(file="Pbox_1112.csv")
dts.PbP.1112 <- read.csv(file="PbP_1112.csv")
PbP1112 <- PbPmanipulation(dts.PbP.1112)

# Possessions, PACE, Offensive/Defensive Ratings, Four Factors
fourfactors1112 <- fourfactors(Tbox1112, Obox1112)
Playoff <- Tadd1112$Playoff
fourfactors1112PO <- data.frame(fourfactors1112, Playoff)
fourfactors1112PO

# Scatter plot of PACE, Offensive/Defensive Ratings, Four Factors
ggplot(data=fourfactors1112PO, aes(x=PACE.Off, y=PACE.Def, color = Playoff, label=Team)) +
       geom_point() +
       ggrepel::geom_text_repel(aes(label = Team))+
       geom_vline(xintercept =mean(fourfactors1112PO$PACE.Off))+
       geom_hline(yintercept =mean(fourfactors1112PO$PACE.Def))+
       labs(title = "PACE - NBA teams (NBA 2011 - 2012 Regular Season)")+
       labs(x = "Pace (Possessions per minute) of the Team") +
       labs(y = "Pace (Possessions per minute) of the Opponents")

ggplot(data=fourfactors1112PO, aes(x=ORtg, y=DRtg, color = Playoff, label=Team)) +
      geom_point() +
      ggrepel::geom_text_repel(aes(label = Team))+
      geom_vline(xintercept =mean(fourfactors1112PO$ORtg))+
      geom_hline(yintercept =mean(fourfactors1112PO$DRtg))+
      labs(title = "ORtg and DRtg - NBA teams (NBA 2011 - 2012 Regular Season)")+
      labs(x = "Offensive Rating of the Team (ORtg)") +
      labs(y = "Offensive Rating of the Opponents (DRtg)")

ggplot(data=fourfactors1112PO, aes(x=F1.Off, y=F1.Def, color = Playoff, label=Team)) +
      geom_point() +
      ggrepel::geom_text_repel(aes(label = Team))+
      geom_vline(xintercept =mean(fourfactors1112PO$F1.Off))+
      geom_hline(yintercept =mean(fourfactors1112PO$F1.Def))+
      labs(title = "Factor 1: eFG% - NBA teams (NBA 2011 - 2012 Regular Season)")+
      labs(x = "eFG% (Offense)") +
      labs(y = "eFG% (Defense)")

ggplot(data=fourfactors1112PO, aes(x=F2.Off, y=F2.Def, color = Playoff, label=Team)) +
      geom_point() +
      ggrepel::geom_text_repel(aes(label = Team))+
      geom_vline(xintercept =mean(fourfactors1112PO$F2.Off))+
      geom_hline(yintercept =mean(fourfactors1112PO$F2.Def))+
      labs(title = "Factor 2: TO Ratio - NBA teams (NBA 2011 - 2012 Regular Season)")+
      labs(x = "TO Ratio (Offense)") +
      labs(y = "TO Ratio (Defense)")

ggplot(data=fourfactors1112PO, aes(x=F3.Off, y=F3.Def, color = Playoff, label=Team)) +
      geom_point() +
      ggrepel::geom_text_repel(aes(label = Team))+
      geom_vline(xintercept =mean(fourfactors1112PO$F3.Off))+
      geom_hline(yintercept =mean(fourfactors1112PO$F3.Def))+
      labs(title = "Factor 3: REB% - NBA teams (NBA 2011 - 2012 Regular Season)")+
      labs(x = "REB% (Offense)") +
      labs(y = "REB% (Defense)")

ggplot(data=fourfactors1112PO, aes(x=F4.Off, y=F4.Def, color = Playoff, label=Team)) +
       geom_point() +
       ggrepel::geom_text_repel(aes(label = Team))+
       geom_vline(xintercept =mean(fourfactors1112PO$F4.Off))+
       geom_hline(yintercept =mean(fourfactors1112PO$F4.Def))+
       labs(title = "Factor 4: FT Rate - NBA teams (NBA 2011 - 2012 Regular Season)")+
       labs(x = "FT Rate (Offense)") +
       labs(y = "FT Rate (Defense)")

# Correlation matrix
data1112c <- subset(Pbox1112, MIN>=500*0.8)
attach(data1112c)
X <- data.frame(P2M, P3M, FTM, REB=(OREB+DREB), AST, STL, BLK, TOV)/MIN
detach(data1112c)
corrmatrix <- corranalysis(X[,1:8], threshold=0.4)
plot(corrmatrix)

attach(fourfactors1112)
Y <- data.frame(PACE.Off, ORtg, eFGp.Off=F1.Off, TOR.Off=F2.Off, REBp.Off=F3.Off, FTR.Off=F4.Off, PACE.Def, DRtg, eFGp.Def=F1.Def, TOR.Def=F2.Def, REBp.Def=F3.Def, FTR.Def=F4.Def)
detach(fourfactors1112)
corrmatrixY <- corranalysis(Y[,1:12], threshold=0.4)
plot(corrmatrixY)

# Bubble plot of NBA teams
attach(Tbox1112)
X2 <- data.frame(T=Team, P2p, P3p, FTp, AS=P2A+P3A+FTA)
detach(Tbox1112)
labs1 <- c("2-point shots (% made)", "3-point shots (% made)", "free throws (% made)", "Total shots attempted")
bubbleplot(X2, id="T", x="P2p", y="P3p", col="FTp", size="AS", labels=labs1, title="Bubble plot of NBA teams: Shooting percentage and shots attempted (NBA 2011 - 2012 Regular season)", text.size=3.5)

attach(Tbox1112)
Y2 <- data.frame(T=Team, DREB=DREB/GP, STL=STL/GP, BLK=BLK/GP, PM=PM/GP)
detach(Tbox1112)
labs2 <- c("Defensive Rebounds per Game", "Blocks per Game", "Plus-Minus per Game", "Steals per Game")
bubbleplot(Y2, id="T", x="DREB", y="BLK", col="PM", size="STL", labels=labs2, title="Bubble plot of NBA teams: Defensive stats and Plus-Minus (NBA 2011 - 2012 Regular season)", text.size=3.5)

# Radar chart of NBA teams
attach(Tbox1112)
T <- data.frame(P2M,P3M, FTM, REB=OREB+DREB, AST, STL, BLK)/MIN
detach(Tbox1112)
radialprofile(data=T, title=Tbox1112$Team, std=TRUE)
listplots <- radialprofile(data=T, title=Tbox1112$Team, std=TRUE)
grid.arrange(grobs=listplots[1:15], ncol=5)
grid.arrange(grobs=listplots[16:30], ncol=5)

# Non-hierarchical clustering - K-means
FF1112 <- fourfactors(Tbox1112, Obox1112)
OD.Rtg <- FF1112$ORtg/FF1112$DRtg
F1.r <- FF1112$F1.Off/FF1112$F1.Def
F2.r <- FF1112$F2.Def/FF1112$F2.Off
F3.Off <- FF1112$F3.Off
F3.Def <- FF1112$F3.Def
P3M <- Tbox1112$P3M
STL.r <- Tbox1112$STL/Obox1112$STL
data1112k <- data.frame(OD.Rtg, F1.r, F2.r, F3.Off, F3.Def, P3M, STL.r)
set.seed(29)
kclu1 <- kclustering(data1112k)
plot(kclu1)
set.seed(29)
kclu2 <- kclustering(data1112k, labels=Tbox1112$Team, k=5)
plot(kclu2)
kclu2

kclu2.PO <- table(kclu2$Subjects$Cluster, Tadd1112$Playoff)
kclu2.W <- tapply(Tbox1112$W, kclu2$Subjects$Cluster, mean)
Xbar <- data.frame(cluster=c(1:5), No=kclu2.PO[,1], Yes=kclu2.PO[,2], W=kclu2.W)
barline(data=Xbar, id="cluster", bars=c("Yes", "No"), labels.bars=c("Playoff: YES", "Playoff: NO"), line="W", label.line="average wins", decreasing=FALSE)

cluster <- as.factor(kclu2$Subjects$Cluster)
Xbubble <- data.frame(Team=Tbox1112$Team, PTS=Tbox1112$PTS,  PTS.Opp=Obox1112$PTS, cluster,  OD.Rtg=data1112k$OD.Rtg)
labs <- c("PTS", "PTS.Opp", "cluster", "OD.Rtg")
bubbleplot(Xbubble, id="Team", x="PTS", y="PTS.Opp",   col="cluster", size="OD.Rtg", labels=labs, title="Bubble plot of NBA teams: PTS, Opponent PTS, Cluster and OD.Rtg (NBA 2011 - 2012 Regular season)", text.size=3.0)
remove(P3M)

# Gini index with respect to PTS and AST
no.teams <- nrow(Tbox1112)
GINI_PTS <- array(0, no.teams)
for (k in 1:no.teams) { 
       Teamk <- Tbox1112$Team[k] 
       Pbox1112.sel <- subset(Pbox1112, Team==Teamk) 
       index1 <- inequality(Pbox1112.sel$PTS, npl=8) 
       GINI_PTS[k] <- index1$Gini
       }

GINI_AST <- array(0, no.teams)
for (k in 1:no.teams) { 
       Teamk <- Tbox1112$Team[k] 
       Pbox1112.sel <- subset(Pbox1112, Team==Teamk) 
       index2 <- inequality(Pbox1112.sel$AST, npl=6) 
       GINI_AST[k] <- index2$Gini
       }

dts <- data.frame(Team=Tbox1112$Team, GINI_PTS, GINI_AST, PTS=Tbox1112$PTS, AST=Tbox1112$AST, Playoff=Tadd1112$Playoff)
ggplot(data=dts, aes(x=GINI_PTS, y=GINI_AST, color = Playoff, label=Tbox1112$Team)) +
      geom_point() +
      ggrepel::geom_text_repel(aes(label = Tbox1112$Team))+
      geom_vline(xintercept =mean(dts$GINI_PTS))+
      geom_hline(yintercept =mean(dts$GINI_AST))+
      labs(title = "Scatter plot of NBA teams: Gini index for PTS and AST (NBA 2011 - 2012 Regular season)")+
      labs(x = "GINI_PTS") +
      labs(y = "GINI_AST")

# Shot chart of all teams
PbP1112rs <- subset(PbP1112, data_set=="2011-12 Regular Season")
PbP1112rs$xx <- PbP1112rs$original_x/-10
PbP1112rs$yy <- PbP1112rs$original_y/10-41.75
shotchart(data=PbP1112rs, x="xx", y="yy", z="playlength", num.sect=5, type="sectors", scatter=FALSE, result="result")
shotchart(data=PbP1112rs, x="xx", y="yy", type="density-hexbin", nbins=50, palette="bwr")

# Density estimation of field shots of all teams
data1112d <- subset(PbP1112, data_set=="2011-12 Regular Season" & result!="" & shot_distance!="")
set.seed(1)
data1112r <- data1112d[sample(nrow(data1112d), 50000, replace = FALSE, prob = NULL),]
densityplot(data=data1112r, shot.type="field", var="shot_distance", best.score=FALSE, title="Density estimation of field shots of all teams, with respect to shot distance (NBA 2011 - 2012 Regular Season), sample: 50000 shots.")

# MDS Map of NBA Players
attach(Pbox1112)
data1112m <- data.frame(P2M, P3M, FTM, REB=(OREB+DREB), AST, STL, BLK)/MIN
detach(Pbox1112)
data1112m <- subset(data1112m, Pbox1112$MIN>=1500*0.8)
id <- Pbox1112$Player[Pbox1112$MIN>=1500*0.8]
mds <- MDSmap(data1112m)
selp <- which(id=="Al Jefferson" | id=="Ryan Anderson" | id=="Kevin Love" | id=="Marcus Camby" | id=="Steve Nash" | id=="Chris Paul" | id=="Serge Ibaka")
plot(mds, labels=id, subset=selp, col.subset="tomato")
plot(mds, labels=id, subset=selp, col.subset="tomato", zoom=c(-2,2,-2,2))
plot(mds, z.var=c("P2M", "P3M", "FTM", "REB", "AST", "STL", "BLK"), contour=TRUE, palette=topo.colors)

# Hierarchical clustering - Ward
attach(Pbox1112)
data1112w <- data.frame(PTS, P2M, P3M, REB=(OREB+DREB), AST, TOV, STL, BLK)/MIN
detach(Pbox1112)
data1112w <- subset(data1112w, Pbox1112$MIN>=1800*0.8)
ID <- Pbox1112$Player[Pbox1112$MIN>=1800*0.8]
hclu1 <- hclustering(data1112w)
plot(hclu1)
hclu2 <- hclustering(data1112w, labels=ID, k=8)
plot(hclu2, profiles=TRUE)
plot(hclu2, rect=TRUE, colored.branches=TRUE, cex.labels=0.2)

⇐ 2010-11 |🏀| 2012-13 ⇒

※データ分析を実践する際に参考にしている書籍『Basketball Data Science: With Applications in R』の紹介記事も書いていますので、よろしければ下記よりご確認ください。

スポンサーリンク
スポンサーリンク
スポンサーリンク
** データ分析を実践する際に参考にしている書籍です **

Paola Zuccolotto and Marica Manisera (2020), Basketball Data Science – with Applications in R. Chapman and Hall/CRC. ISBN 9781138600799.

Summary

X(旧Twitter)アカウントあります。コメント等があればhttps://x.com/basketrashtalkへお願いします。

Kaneshiroをフォローする
タイトルとURLをコピーしました