teamsalary <-read.csv("C:/Users/Brian Faith/Desktop/Northwestern/MSDS 401 Q2/R Data/nba_teams.csv")
str(teamsalary)
## 'data.frame': 120 obs. of 10 variables:
## $ season : int 2017 2018 2019 2020 2017 2018 2019 2020 2017 2018 ...
## $ conf : chr "East" "East" "East" "East" ...
## $ team : chr "Atlanta" "Atlanta" "Atlanta" "Atlanta" ...
## $ value_rank : int 24 24 24 24 5 5 5 5 7 7 ...
## $ payroll : num 99993 79180 85600 118804 115285 ...
## $ tax_space : num 19273 44553 47027 13823 3981 ...
## $ win_pct : num 0.293 0.354 0.299 0.569 0.671 0.598 0.672 0.5 0.341 0.512 ...
## $ wins : int 24 29 20 41 55 49 43 36 28 42 ...
## $ cost_per_win: num 4166 2730 4280 2898 2096 ...
## $ index_lg_avg: int 88 127 86 114 176 136 134 89 108 123 ...
season <- as.factor(teamsalary$season)
team <- teamsalary$team
payroll <- teamsalary$payroll
tax_space <- teamsalary$tax_space
win_pct <- teamsalary$win_pct
wins <- teamsalary$wins
cost_per_win <- payroll/wins
index <- teamsalary$index_lg_avg
s2020 <- season == "2020"
s2019 <- season == "2019"
s2018 <- season == "2018"
s2017 <- season == "2017"
plot(payroll, win_pct, xlab = "Payroll ($)", ylab = "Win Pct",
col = c("orange", "green", "red", "blue")[season], pch = 20,
main = "NBA Team Salary by Win Pct 2017-2020")
legend(160000, .4,legend = c("2017", "2018", "2019", "2020"), cex= .75,
fill = c("orange", "green", "red", "blue"))
abline(lm(win_pct ~ payroll, data = teamsalary), col = "black", lty = 3)

cor.test(payroll, win_pct, method = "pearson")
##
## Pearson's product-moment correlation
##
## data: payroll and win_pct
## t = 5.0259, df = 118, p-value = 1.803e-06
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.2602540 0.5572104
## sample estimates:
## cor
## 0.4199073
barplot(index,
col = c("orange", "green", "red", "blue")[season],
main = "Cost Per Win Index", xlab = "Team Payroll Efficiency by Season",
ylab = "Index to League Average")
legend(x = "topright",legend = c("2017", "2018", "2019", "2020"), cex= .75,
fill = c("orange", "green", "red", "blue"))
abline(h=100, col= "black", lty = 3)

nolacomps <- subset(teamsalary, team == "Milwaukee" | team == "Utah" | team == "Denver")
nolacompindex <- nolacomps$index_lg_avg
nolacompteams <- nolacomps$team
barplot(nolacompindex,
col = c("orange", "green", "red", "blue")[season],
main = "Small Market Payroll Effiency",
xlab = "Team Payroll Efficiency by Season", ylab = "Index to League Average")
legend(x = "topright",legend = c("2017", "2018", "2019", "2020"), cex= .75,
fill = c("orange", "green", "red", "blue"))
abline(h=100, col= "black", lty = 3)
text(2.5, 165, "Denver", col = "dodgerblue")
text(7, 165, "MIlwaukee", col = "darkgreen")
text(12, 165, "Utah", col = "purple")

nola_index <- index [team == "New Orleans"]
barplot(nola_index,
col = c("orange", "green", "red", "blue")[season],
main = "New Orleans Payroll Efficiency by Season",
xlab = "Season", ylab = "Index",
names.arg = c("2017", "2018", "2019", "2020"))
abline(h=100, col= "black", lty = 3)
