library(MASS)
fantasy <- read.csv("~/Desktop/Book1.csv", header = TRUE)
fantasy <- (fantasy[-41,])
fantasy <- (fantasy[,-1])
fantasy$Wins.1 = colnames("Wins")
fantasy
## Wins Runs HR RBI SB AVG K Saves ERA WHIP YEAR
## 1 120 1174 343 1110 144 0.2744 1464 198 3.320 1.148 16
## 2 106 1133 342 1086 90 0.2736 1744 115 3.518 1.185 16
## 3 104 976 324 1122 113 0.2778 1776 88 3.303 1.181 16
## 4 102 1114 273 1075 159 0.2856 1362 76 3.058 1.105 16
## 5 92 1059 365 1102 117 0.2592 1741 79 3.692 1.244 16
## 6 92 1023 291 1071 160 0.2686 1364 83 4.070 1.304 16
## 7 84 1097 300 1037 147 0.2784 1187 102 4.136 1.284 16
## 8 86 1098 281 971 114 0.2733 1257 102 4.237 1.291 16
## 9 116 1088 282 1037 148 0.2768 1477 107 3.441 1.184 15
## 10 120 1041 302 994 171 0.2768 1924 73 2.985 1.096 15
## 11 104 1072 296 1085 145 0.2756 1804 125 3.654 1.225 15
## 12 103 960 247 986 158 0.2690 1658 112 3.347 1.222 15
## 13 95 1068 337 1030 95 0.2630 1803 47 3.214 1.123 15
## 14 87 963 220 876 155 0.2704 1408 87 3.716 1.247 15
## 15 86 938 243 946 93 0.2618 1150 170 3.685 1.180 15
## 16 83 975 251 954 118 0.2666 612 214 2.285 1.004 15
## 17 123 1106 274 1029 209 0.2791 1628 144 3.133 1.153 14
## 18 100 1043 240 932 131 0.2552 1742 103 3.455 1.191 14
## 19 112 1013 279 1055 94 0.2668 1780 102 3.100 1.159 14
## 20 106 1025 233 943 143 0.2739 1503 75 3.246 1.186 14
## 21 100 973 195 807 218 0.2810 1565 104 3.606 1.205 14
## 22 99 942 231 986 127 0.2776 1486 79 2.861 1.098 14
## 23 74 976 233 965 132 0.2605 1359 107 3.536 1.274 14
## 24 71 862 211 853 119 0.2592 1239 81 3.724 1.203 14
## 25 121 1066 289 1110 159 0.2783 1737 91 3.229 1.157 13
## 26 111 1060 285 1080 118 0.2803 1523 115 3.516 1.206 13
## 27 112 1047 241 959 150 0.2712 1522 100 3.425 1.184 13
## 28 102 1049 254 1011 136 0.2730 1512 114 3.545 1.197 13
## 29 95 953 235 876 191 0.2587 1418 77 2.893 1.147 13
## 30 84 945 247 886 150 0.2774 1360 43 3.555 1.201 13
## 31 63 915 193 792 137 0.2875 1245 54 3.633 1.245 13
## 32 62 882 212 874 94 0.2675 1185 65 3.822 1.291 13
## 33 112 1171 373 1127 137 0.2792 1809 116 3.400 1.163 17
## 34 109 1150 279 999 216 0.2683 1712 89 3.804 1.235 17
## 35 101 1100 346 1088 120 0.2675 1673 106 3.868 1.223 17
## 36 99 1110 356 1126 105 0.2692 1665 51 4.298 1.295 17
## 37 88 1096 314 986 125 0.2730 1640 113 3.809 1.260 17
## 38 85 1043 287 1067 104 0.2796 1486 88 3.291 1.130 17
## 39 85 1093 303 1074 141 0.2729 687 136 3.640 1.231 17
## 40 78 1022 321 949 134 0.2685 1403 113 3.840 1.291 17
Sort data by year
fantasy2017 <- subset(fantasy,fantasy$YEAR=='17')
fantasy2016 <- subset(fantasy,fantasy$YEAR=='16')
fantasy2015 <- subset(fantasy,fantasy$YEAR=='15')
fantasy2014 <- subset(fantasy,fantasy$YEAR=='14')
fantasy2013 <- subset(fantasy,fantasy$YEAR=='13')
Mean of Wins by Year
mean(fantasy2013$Wins)
## [1] 93.75
mean(fantasy2014$Wins)
## [1] 98.125
mean(fantasy2015$Wins)
## [1] 99.25
mean(fantasy2016$Wins)
## [1] 98.25
mean(fantasy2017$Wins)
## [1] 94.625
plot(fantasy$YEAR, fantasy$Wins)
mean(fantasy$Wins)
## [1] 96.8
abline(96.8,0)

Wins are getting clumped together, which means league is getting more competitivie
2017 By Category
mean(fantasy2017$Wins)
## [1] 94.625
mean(fantasy2017$Runs)
## [1] 1098.125
mean(fantasy2017$HR)
## [1] 322.375
mean(fantasy2017$RBI)
## [1] 1052
mean(fantasy2017$SB)
## [1] 135.25
mean(fantasy2017$AVG)
## [1] 0.272275
mean(fantasy2017$K)
## [1] 1509.375
mean(fantasy2017$Wins)
## [1] 94.625
mean(fantasy2017$Saves)
## [1] 101.5
mean(fantasy2017$ERA)
## [1] 3.74375
mean(fantasy2017$WHIP)
## [1] 1.2285
Linear Model Since 2013
fantasyOut <- lm(Wins~Runs+HR+RBI+SB+AVG+K+Saves+ERA+WHIP, data = fantasy)
summary(fantasyOut)
##
## Call:
## lm(formula = Wins ~ Runs + HR + RBI + SB + AVG + K + Saves +
## ERA + WHIP, data = fantasy)
##
## Residuals:
## Min 1Q Median 3Q Max
## -15.8854 -3.2035 0.1387 3.5561 11.5536
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 7.795859 60.344952 0.129 0.89807
## Runs 0.049875 0.029033 1.718 0.09613 .
## HR -0.124609 0.051816 -2.405 0.02255 *
## RBI 0.085183 0.025089 3.395 0.00195 **
## SB 0.131624 0.044980 2.926 0.00648 **
## AVG 5.516339 164.134067 0.034 0.97341
## K 0.029467 0.005059 5.825 2.28e-06 ***
## Saves 0.084602 0.039972 2.117 0.04271 *
## ERA 2.914612 8.072454 0.361 0.72059
## WHIP -79.747604 47.435595 -1.681 0.10311
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 6.805 on 30 degrees of freedom
## Multiple R-squared: 0.851, Adjusted R-squared: 0.8063
## F-statistic: 19.04 on 9 and 30 DF, p-value: 4.272e-10
plot(fantasyOut$residuals,fantasyOut$fitted.values)
abline(mean(fantasyOut$fitted.values),0)

rstudentized <- studres(fantasyOut)
qqnorm(rstudentized)
abline(0,1)

AVG p-value is .97, very insignificant
Residuals look random and qqplot is normal, so assumptions are met