Load ggplot2 library and read in data. The for loop checks to make sure that the home games and away games both sum to 41 for each team. This is because we manually collected the data, and it just a small test for errors.
set.seed(200)
library(ggplot2)
nba_data <- read.csv("/Users/Max/Desktop/nbadata.csv", row.names = 1, header = TRUE)
for (i in 1:nrow(nba_data)) {
home = (nba_data[i,"home.wins"] + nba_data[i,"home.losses"] == 41)
road = (nba_data[i,"road.wins"] + nba_data[i,"road.losses"] == 41)
if ((home & road) == F){
print(i)
}
}
Establish factors and show some tables to ensure the data is entered correctly.
nba_data$conference = as.factor(nba_data$conference)
nba_data$division = as.factor(nba_data$division)
table(nba_data$conference)
##
## eastern western
## 15 15
table(nba_data$division)
##
## atlantic central northwest pacific southeast southwest
## 5 5 5 5 5 5
Some histograms of the data.
hist(nba_data$home.wins)
hist(nba_data$road.wins)
ggplot(nba_data, aes(x=home.wins, fill=conference)) + geom_density(alpha=.8)
ggplot(nba_data, aes(x=road.wins, fill=conference)) + geom_density(alpha=.8)
nba_data$home.ratio = nba_data$home.wins / 41
nba_data$road.ratio = nba_data$road.wins / 41
with(nba_data, t.test(home.ratio, road.ratio, paired=TRUE))
##
## Paired t-test
##
## data: home.ratio and road.ratio
## t = 9.1434, df = 29, p-value = 4.834e-10
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## 0.116132 0.183055
## sample estimates:
## mean of the differences
## 0.1495935
nba_data
## conference division home.wins home.losses
## atlanta_hawks eastern southeast 35 6
## cleveland_cavaliers eastern central 31 10
## chicago_bulls eastern central 27 14
## toronto_raptors eastern atlantic 27 14
## washington_wizards eastern southeast 29 12
## milwaulkee_bucks eastern central 23 18
## boston_celtics eastern atlantic 21 20
## brooklyn_nets eastern atlantic 19 22
## indiana_pacers eastern central 23 18
## miami_heat eastern southeast 20 21
## charlotte_hornets eastern southeast 19 22
## detroit_pistons eastern central 18 23
## orlando_magic eastern southeast 13 28
## philadelphia_76ers eastern atlantic 12 29
## new_york_knicks eastern atlantic 10 31
## golden_state_warriors western pacific 39 2
## los_angeles_clippers western pacific 30 11
## phoenix_suns western pacific 22 19
## sacramento_kings western pacific 18 23
## los_angeles_lakers western pacific 12 29
## houston_rockets western southwest 30 11
## memphis_grizzlies western southwest 31 10
## san_antonio_spurs western southwest 33 8
## dallas_mavericks western southwest 27 14
## new_orleans_pelicans western southwest 28 13
## portland_trail_blazers western northwest 32 9
## oklahoma_city_thunder western northwest 29 12
## utah_jazz western northwest 21 20
## denver_nuggets western northwest 19 22
## minnesota_timberwolves western northwest 9 32
## road.wins road.losses home.ratio road.ratio
## atlanta_hawks 25 16 0.8536585 0.6097561
## cleveland_cavaliers 22 19 0.7560976 0.5365854
## chicago_bulls 23 18 0.6585366 0.5609756
## toronto_raptors 22 19 0.6585366 0.5365854
## washington_wizards 17 24 0.7073171 0.4146341
## milwaulkee_bucks 18 23 0.5609756 0.4390244
## boston_celtics 19 22 0.5121951 0.4634146
## brooklyn_nets 19 22 0.4634146 0.4634146
## indiana_pacers 15 26 0.5609756 0.3658537
## miami_heat 17 24 0.4878049 0.4146341
## charlotte_hornets 14 27 0.4634146 0.3414634
## detroit_pistons 14 27 0.4390244 0.3414634
## orlando_magic 12 29 0.3170732 0.2926829
## philadelphia_76ers 6 35 0.2926829 0.1463415
## new_york_knicks 7 34 0.2439024 0.1707317
## golden_state_warriors 28 13 0.9512195 0.6829268
## los_angeles_clippers 26 15 0.7317073 0.6341463
## phoenix_suns 17 24 0.5365854 0.4146341
## sacramento_kings 11 30 0.4390244 0.2682927
## los_angeles_lakers 9 32 0.2926829 0.2195122
## houston_rockets 26 15 0.7317073 0.6341463
## memphis_grizzlies 24 17 0.7560976 0.5853659
## san_antonio_spurs 22 19 0.8048780 0.5365854
## dallas_mavericks 23 18 0.6585366 0.5609756
## new_orleans_pelicans 17 24 0.6829268 0.4146341
## portland_trail_blazers 19 22 0.7804878 0.4634146
## oklahoma_city_thunder 16 25 0.7073171 0.3902439
## utah_jazz 17 24 0.5121951 0.4146341
## denver_nuggets 11 30 0.4634146 0.2682927
## minnesota_timberwolves 7 34 0.2195122 0.1707317