# Load the dataset
NBA = read.csv("NBA_train.csv")
# Output the string
str(NBA)
## 'data.frame': 835 obs. of 20 variables:
## $ SeasonEnd: int 1980 1980 1980 1980 1980 1980 1980 1980 1980 1980 ...
## $ Team : Factor w/ 37 levels "Atlanta Hawks",..: 1 2 5 6 8 9 10 11 12 13 ...
## $ Playoffs : int 1 1 0 0 0 0 0 1 0 1 ...
## $ W : int 50 61 30 37 30 16 24 41 37 47 ...
## $ PTS : int 8573 9303 8813 9360 8878 8933 8493 9084 9119 8860 ...
## $ oppPTS : int 8334 8664 9035 9332 9240 9609 8853 9070 9176 8603 ...
## $ FG : int 3261 3617 3362 3811 3462 3643 3527 3599 3639 3582 ...
## $ FGA : int 7027 7387 6943 8041 7470 7596 7318 7496 7689 7489 ...
## $ X2P : int 3248 3455 3292 3775 3379 3586 3500 3495 3551 3557 ...
## $ X2PA : int 6952 6965 6668 7854 7215 7377 7197 7117 7375 7375 ...
## $ X3P : int 13 162 70 36 83 57 27 104 88 25 ...
## $ X3PA : int 75 422 275 187 255 219 121 379 314 114 ...
## $ FT : int 2038 1907 2019 1702 1871 1590 1412 1782 1753 1671 ...
## $ FTA : int 2645 2449 2592 2205 2539 2149 1914 2326 2333 2250 ...
## $ ORB : int 1369 1227 1115 1307 1311 1226 1155 1394 1398 1187 ...
## $ DRB : int 2406 2457 2465 2381 2524 2415 2437 2217 2326 2429 ...
## $ AST : int 1913 2198 2152 2108 2079 1950 2028 2149 2148 2123 ...
## $ STL : int 782 809 704 764 746 783 779 782 900 863 ...
## $ BLK : int 539 308 392 342 404 562 339 373 530 356 ...
## $ TOV : int 1495 1539 1684 1370 1533 1742 1492 1565 1517 1439 ...# Tabulate the amount of wins to make the playoffs
a = table(NBA$W, NBA$Playoffs)
kable(a, caption = "Wins")| 0 | 1 | |
|---|---|---|
| 11 | 2 | 0 |
| 12 | 2 | 0 |
| 13 | 2 | 0 |
| 14 | 2 | 0 |
| 15 | 10 | 0 |
| 16 | 2 | 0 |
| 17 | 11 | 0 |
| 18 | 5 | 0 |
| 19 | 10 | 0 |
| 20 | 10 | 0 |
| 21 | 12 | 0 |
| 22 | 11 | 0 |
| 23 | 11 | 0 |
| 24 | 18 | 0 |
| 25 | 11 | 0 |
| 26 | 17 | 0 |
| 27 | 10 | 0 |
| 28 | 18 | 0 |
| 29 | 12 | 0 |
| 30 | 19 | 1 |
| 31 | 15 | 1 |
| 32 | 12 | 0 |
| 33 | 17 | 0 |
| 34 | 16 | 0 |
| 35 | 13 | 3 |
| 36 | 17 | 4 |
| 37 | 15 | 4 |
| 38 | 8 | 7 |
| 39 | 10 | 10 |
| 40 | 9 | 13 |
| 41 | 11 | 26 |
| 42 | 8 | 29 |
| 43 | 2 | 18 |
| 44 | 2 | 27 |
| 45 | 3 | 22 |
| 46 | 1 | 15 |
| 47 | 0 | 28 |
| 48 | 1 | 14 |
| 49 | 0 | 17 |
| 50 | 0 | 32 |
| 51 | 0 | 12 |
| 52 | 0 | 20 |
| 53 | 0 | 17 |
| 54 | 0 | 18 |
| 55 | 0 | 24 |
| 56 | 0 | 16 |
| 57 | 0 | 23 |
| 58 | 0 | 13 |
| 59 | 0 | 14 |
| 60 | 0 | 8 |
| 61 | 0 | 10 |
| 62 | 0 | 13 |
| 63 | 0 | 7 |
| 64 | 0 | 3 |
| 65 | 0 | 3 |
| 66 | 0 | 2 |
| 67 | 0 | 4 |
| 69 | 0 | 1 |
| 72 | 0 | 1 |
# Compute Point Differences
NBA$PTSdiff = NBA$PTS - NBA$oppPTS# Scatterplot
plot(NBA$PTSdiff, NBA$W)# Linear Regression model
WinsReg = lm(W ~ PTSdiff, data=NBA)
# Output summary
summary(WinsReg)
##
## Call:
## lm(formula = W ~ PTSdiff, data = NBA)
##
## Residuals:
## Min 1Q Median 3Q Max
## -9.7393 -2.1018 -0.0672 2.0265 10.6026
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 41.0000000 0.1059358 387.0 <2e-16 ***
## PTSdiff 0.0325863 0.0002793 116.7 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 3.061 on 833 degrees of freedom
## Multiple R-squared: 0.9423, Adjusted R-squared: 0.9423
## F-statistic: 1.361e+04 on 1 and 833 DF, p-value: < 2.2e-16# Linear Regression model
PointsReg = lm(PTS ~ X2PA + X3PA + FTA + AST + ORB + DRB + TOV + STL + BLK, data=NBA)
# Output the summary
summary(PointsReg)
##
## Call:
## lm(formula = PTS ~ X2PA + X3PA + FTA + AST + ORB + DRB + TOV +
## STL + BLK, data = NBA)
##
## Residuals:
## Min 1Q Median 3Q Max
## -527.40 -119.83 7.83 120.67 564.71
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -2050.81081 203.48660 -10.078 <2e-16 ***
## X2PA 1.04288 0.02957 35.274 <2e-16 ***
## X3PA 1.25859 0.03843 32.747 <2e-16 ***
## FTA 1.12802 0.03373 33.440 <2e-16 ***
## AST 0.88577 0.04396 20.150 <2e-16 ***
## ORB -0.95539 0.07792 -12.261 <2e-16 ***
## DRB 0.03883 0.06157 0.631 0.5285
## TOV -0.02475 0.06118 -0.405 0.6859
## STL -0.19918 0.09181 -2.169 0.0303 *
## BLK -0.05576 0.08782 -0.635 0.5256
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 185.5 on 825 degrees of freedom
## Multiple R-squared: 0.8992, Adjusted R-squared: 0.8981
## F-statistic: 817.3 on 9 and 825 DF, p-value: < 2.2e-16# Calculate SSE
PointsReg$residuals
## 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
## 38.5722713 142.8720040 -92.8957180 -8.3913473 -258.4705615 171.4608325 150.4081623 169.3811429 40.7756197 -75.3256614 444.9088743 94.3864704 -205.6809050 113.5969040 64.1993998
## 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
## -76.5711999 249.4888007 28.0363236 329.4487991 96.3248342 349.2067913 -284.3765225 196.1611379 198.2493104 445.4100295 93.8946072 -316.2962802 -166.1909668 -5.8446359 211.2301997
## 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
## 155.7426615 -23.9248929 -77.9070033 218.9449693 164.1368602 -177.6479438 66.9205988 162.7892553 23.5961895 93.9839603 185.7015113 -50.2507837 -90.1181969 139.6866673 -231.1772776
## 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
## 111.2200135 185.9069491 210.6753018 -47.9420913 -257.8213675 225.7399197 70.4925628 432.6468031 187.4169561 -34.3947653 112.9305359 334.4717296 222.4169937 17.6755711 165.4512882
## 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
## 207.9970351 56.8277093 214.6051983 -23.0235142 341.7509536 -48.3807695 304.9203623 -36.7878762 -31.0357805 61.8847883 -153.0322403 121.7423324 -61.1581185 -47.9906548 -120.3599484
## 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
## 245.7621368 -264.3876116 161.1110819 87.3192423 426.2098591 -4.7790973 126.8613801 -97.5009340 329.9773912 -16.2338716 7.8513505 191.9280982 87.0090318 -142.5397602 -216.2264974
## 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
## -199.6293933 71.0810742 257.3751407 -227.1203824 -61.4866232 71.3329444 -233.2637272 -34.7860771 84.9503466 108.6553543 -84.8168235 -90.0423121 341.2144522 52.8507112 47.8978397
## 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
## 181.0574099 160.7203318 237.0174702 314.9609845 51.9650831 300.2035074 -148.0931149 -13.3592416 -161.6184704 82.1172789 277.6080699 233.4334153 -225.7299932 69.0259972 37.3407430
## 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
## 18.2709681 121.8125335 217.9464858 -74.8210467 36.2611001 356.2366230 439.4127892 111.0266627 72.1377278 -6.1141295 331.6249450 -158.3642350 94.9048994 151.3242943 -284.7768411
## 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
## -184.0287416 -103.9972773 54.1758237 139.3176593 125.3796164 -71.4407602 83.4742245 -131.6383234 -33.5752771 98.9460909 -59.8760139 -116.6711077 -110.4055752 290.8888709 38.5758792
## 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
## -6.8265554 -284.8106013 149.5419209 -185.9270381 -13.5712897 -90.2301662 21.0080300 14.5295957 -346.4091267 -54.7198161 87.6823846 203.7903006 -30.7131853 -153.9699795 194.6791232
## 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
## -357.4466727 133.8696823 -21.6271760 -220.4987354 -153.7269937 -383.7168614 212.2104185 -100.3118791 -30.5085767 -57.7910608 205.9463003 -124.1358862 -61.2169391 -93.9538879 -135.6180284
## 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
## 69.1245169 -435.5355494 -47.8153585 115.1051439 222.5411686 104.6516380 7.8335700 178.0759383 -185.3383423 122.0537263 -29.4729351 27.1344203 189.2078833 -429.5919872 57.2397301
## 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
## -170.2701567 -14.0836520 21.0147294 49.6548689 -127.4633821 -87.4084020 -77.6940715 -155.2913076 8.4930328 -232.7210528 35.3384277 151.1394532 119.4563308 -416.3088878 134.8599211
## 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
## 33.3825347 48.4541197 -269.8021487 214.9045443 88.1318416 -24.0318730 188.2281015 -249.1537666 157.9872056 -146.6803006 72.9077663 31.1747176 337.2185582 69.7227713 -2.7440511
## 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
## -55.2845827 -84.6255409 -151.4858821 234.7432200 -165.3909069 -172.9288404 386.6402387 34.4884530 -368.0387956 304.8349400 -173.0591889 168.9365987 -327.6509605 95.0370278 -75.5698743
## 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
## -74.9702316 290.0371682 -21.8628806 72.5362398 -144.3565453 -44.7765529 -155.4752429 -114.0232742 82.8841506 -306.5759686 256.9630856 75.4312937 -108.9852622 -160.6985087 -1.0708625
## 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
## 389.4834173 48.4039145 -173.2376267 102.4859575 564.7127452 -135.6781765 435.5847710 -238.8763852 93.4120332 -346.4790813 84.2266238 124.2627684 157.9013909 90.9742388 -319.7738668
## 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
## 111.6330940 -136.0189613 179.6895020 -139.8481361 -60.2214721 21.1448936 -102.4930752 87.4261255 -2.2833983 -33.1839059 -313.4181662 -9.7903234 365.0041757 -170.9089658 -203.2682115
## 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
## -59.0783300 344.4592952 -177.2934555 278.4424923 31.1539516 -19.4217087 146.9309508 49.6437593 323.4485389 47.1034178 3.9718411 -111.0589062 -40.0036081 187.1994351 134.5701059
## 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
## -130.3795390 227.3624370 16.4481298 -91.2556101 215.9887998 70.7747666 50.5357552 -86.7616664 66.3006293 348.5847817 69.7928527 -144.9174008 48.2485248 262.5189212 -11.0182067
## 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
## 276.2567984 40.2609782 -235.0009787 91.8230888 -36.7029055 66.1862316 127.1446887 34.6306466 -89.1508242 -38.0350890 74.6959695 -24.6713632 -139.6322463 120.5781319 -256.3194253
## 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345
## 35.3325803 -238.1863124 204.2701943 -231.4333870 -242.0178081 27.3589769 442.7697537 -90.3428846 -252.6536092 31.2460678 -24.0030042 -113.6697991 74.2030422 -63.3601223 13.1314540
## 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
## -58.4065092 16.5093336 -26.4233092 -49.9197611 102.5295504 -276.0762358 -171.2605451 235.4118705 -295.3696087 -259.1915277 -209.8493128 -60.3803252 40.8738668 -162.3559100 -3.1584146
## 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
## -252.6683460 -359.6072976 219.8480950 107.9177034 -228.4285961 77.5838841 77.6092501 176.9728823 21.0277939 225.7947949 90.6177409 -95.0387148 243.8004275 63.7765295 -135.7112041
## 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390
## 127.9942080 208.5134149 -226.2507886 -27.4427262 215.5791874 70.0554598 -220.3324085 -252.5213694 -117.0224660 36.9146043 188.5932206 -12.6241171 24.1401960 39.4113815 130.8261623
## 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405
## 194.8028770 140.1603242 100.4917058 367.8120506 -77.1138759 190.1907177 430.4505906 243.1092461 -220.7690501 -135.3500281 182.9169784 58.1314347 -10.3705665 134.0505987 333.4363828
## 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420
## 110.9704334 37.1431301 188.8559358 -88.4445131 -165.3268990 148.8624801 -4.7914163 -114.6045335 -90.1562962 -65.1353805 9.9207366 -20.2393315 147.7163583 153.4474395 95.5889698
## 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435
## -329.6439893 323.3019593 345.3838501 -148.5288812 166.9648145 277.3541861 162.6383840 -78.9033000 -176.7932426 365.3962572 132.7242544 85.6582953 -19.3417988 95.4767236 -102.8199452
## 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450
## 111.8183778 299.2808339 -124.0889739 -37.3805041 118.5055640 38.2173450 -122.8141423 -84.3447659 154.5643586 42.6355711 54.7178397 102.9846564 32.6861086 112.7943954 -163.3563028
## 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465
## 150.7521084 217.5877806 -96.7133626 13.7243484 -33.1690450 -112.2550008 -15.7083565 -224.4198990 18.2593593 -393.0403979 49.2945267 52.0947949 43.2496203 -149.1223107 75.6856970
## 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480
## 170.8878792 -257.6364448 51.6854016 11.8121415 -176.9048352 -149.5317630 -64.1990241 -71.3105611 -317.9190063 -65.8451642 97.8497015 -103.1692986 3.0848318 -104.6823532 -234.7534874
## 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495
## 50.5295490 -75.4835788 -526.1468848 -393.9784124 -360.8366411 116.7193515 -321.3756304 -28.1090479 -508.3250405 -39.9958738 67.9854387 -97.4641720 -268.8364479 -26.0249946 188.1881640
## 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510
## -127.9366821 -86.3440758 133.8144538 29.4480488 -292.9821609 -124.9408024 101.3655240 -186.5181083 -63.5389375 -212.2015589 -323.1476886 -125.6610320 56.9083106 -39.0559074 -1.9339391
## 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525
## -319.9727619 -433.1243358 -431.1346590 -95.8909016 120.6089792 -409.7409083 -352.9341830 -527.3988939 110.6694955 -193.5043557 -92.6385367 -143.5858243 -189.7838251 172.1977457 -80.8020663
## 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540
## -342.9141699 124.8700974 -226.9524006 -73.5173798 -388.4868649 82.9536394 -96.7444961 -114.0835553 60.0566113 -332.3804023 -175.5276633 -338.7116370 -148.1422366 -45.2258816 -270.5159099
## 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555
## -159.8389177 -420.4637398 -133.0466450 183.8988039 -267.0297916 -5.2562902 -228.0471046 -11.6818058 -255.6786897 -7.7244412 -115.5357863 -298.4118693 -122.2961876 90.2924072 111.3930340
## 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570
## -245.4519945 -164.6445508 -29.3651223 -41.9781581 33.4260937 15.1663563 -29.4557965 44.0659204 247.9836928 -57.4318280 -238.6989443 -8.7249850 30.9454288 -343.6175905 -207.4418486
## 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585
## -306.4223254 157.4538406 -502.4785715 -126.1415717 48.8616098 143.9835801 -344.7694076 -116.5012114 -142.7898454 -127.9612584 -226.7659179 67.1679765 -94.0443422 -326.2414346 -84.6517620
## 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600
## 4.5942017 -89.9757406 -97.0958454 -34.6927947 40.9701699 -88.3066869 126.5679875 -128.7529512 -166.6757304 -208.2444446 -105.4053449 -69.9961388 -104.0297252 -475.1678378 -290.6421238
## 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615
## 195.4801727 -116.0865727 -136.0505114 -118.3811054 125.8235124 -145.2484421 -144.5655628 -435.6270621 -230.6201428 -112.7403208 -243.8883351 13.9124625 -392.1393056 -233.5727670 88.6125994
## 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630
## -203.7574893 -207.3393547 36.7326516 71.7237279 -110.6124268 -151.5524839 95.2365977 -227.3589026 -98.5962165 -210.8715081 -53.6787512 33.2644764 -380.2334407 -217.0512157 -135.7283167
## 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645
## 208.5947156 -198.2473902 -147.6362401 -282.5390059 -55.4726214 3.0618526 -118.7764165 -15.9756605 1.5396468 2.2068206 -78.5559489 20.5194552 -376.9064555 -367.5790965 78.4730898
## 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660
## 88.0528050 -178.9859105 283.6342652 18.0639226 1.4275017 -22.1910648 334.1581029 -44.6704981 -166.2133428 -112.8182784 175.7515262 60.9355144 -331.2815975 -175.1322112 34.9727118
## 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675
## 430.8913232 -260.7815266 -99.5985786 -306.5331420 -144.2463445 -71.9561309 40.4095734 -9.9170555 9.7141807 72.8730721 -61.2840291 -51.9936086 -452.8596863 -81.9437393 69.2906290
## 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690
## 254.7395766 -22.9459505 215.8931262 -16.9537293 -107.9068394 202.3017464 287.5765859 180.7757394 -305.5932029 56.2240459 4.5320328 -44.0648823 -278.0391307 -13.3280981 -112.7276708
## 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705
## 422.1750569 -131.0023955 51.4971549 -86.9745423 28.8396258 -107.9302127 -55.3683153 -16.7225380 60.3453436 3.3520616 140.9429255 -17.9219329 -296.8381962 136.2394242 106.7244264
## 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720
## 168.2861008 26.7860625 339.8954937 187.8922770 -202.6392008 148.7995083 268.8921528 0.6597544 -119.2916116 -23.0549542 -28.1758366 206.7679556 -138.5838793 -210.7824121 -29.6626073
## 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735
## 210.3268820 -212.8798945 88.1962039 129.1032851 11.9530477 -166.3796048 -372.3297260 67.5130804 1.7122210 -179.0745146 -28.4404659 151.2765881 -425.3360446 344.3671825 -47.2592021
## 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750
## 136.9801455 63.4427397 203.2044716 27.7908779 251.4279736 84.5817590 -155.6577645 150.3787715 138.7921016 198.4699948 101.8590582 345.8144412 35.1336113 169.1641149 354.9998851
## 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765
## 251.7571721 47.8412497 77.9677328 66.2799291 216.7990909 155.1577399 -131.2437994 230.2449071 218.7156645 116.0349148 -78.5937100 -23.1321308 99.7713990 280.2227149 40.8527845
## 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780
## 19.4188914 72.9388151 120.7266716 439.1035137 456.0100354 47.3239201 186.1096824 31.7505381 -54.0912550 73.0035369 234.4761589 27.9146721 -21.6493313 -75.0167664 148.4251726
## 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795
## 106.3308316 76.0196340 37.3592068 56.5562663 -41.8917486 -200.7598142 -55.5159544 109.1518868 321.3239680 219.8866600 -73.6034103 3.1961900 -171.1408177 190.8979178 101.1845265
## 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810
## 253.1734885 263.7840087 199.5924560 463.8379676 219.1540922 52.3032317 140.7498122 195.8267787 -55.3103142 153.8564182 61.1275837 92.8158603 -108.8302808 73.3423661 -360.6001538
## 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825
## 134.1518035 73.3435884 141.0017271 272.8259956 -33.1611977 19.7818711 -149.9998706 190.0065593 261.3992751 308.7602526 -135.4172110 108.2677094 -171.3410196 102.4439076 156.0829202
## 826 827 828 829 830 831 832 833 834 835
## 210.0521687 109.4908936 -20.5354175 59.2845716 175.9235274 30.6531825 262.6728011 70.0671862 -17.5789419 -8.3393046
SSE = sum(PointsReg$residuals^2)
SSE
## [1] 28394314# Calculate RMSE
RMSE = sqrt(SSE/nrow(NBA))
RMSE
## [1] 184.4049# Calculate mean number of points in a season
mean(NBA$PTS)
## [1] 8370.24# Remove insigificant variables and output the summaries of those models
summary(PointsReg)
##
## Call:
## lm(formula = PTS ~ X2PA + X3PA + FTA + AST + ORB + DRB + TOV +
## STL + BLK, data = NBA)
##
## Residuals:
## Min 1Q Median 3Q Max
## -527.40 -119.83 7.83 120.67 564.71
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -2050.81081 203.48660 -10.078 <2e-16 ***
## X2PA 1.04288 0.02957 35.274 <2e-16 ***
## X3PA 1.25859 0.03843 32.747 <2e-16 ***
## FTA 1.12802 0.03373 33.440 <2e-16 ***
## AST 0.88577 0.04396 20.150 <2e-16 ***
## ORB -0.95539 0.07792 -12.261 <2e-16 ***
## DRB 0.03883 0.06157 0.631 0.5285
## TOV -0.02475 0.06118 -0.405 0.6859
## STL -0.19918 0.09181 -2.169 0.0303 *
## BLK -0.05576 0.08782 -0.635 0.5256
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 185.5 on 825 degrees of freedom
## Multiple R-squared: 0.8992, Adjusted R-squared: 0.8981
## F-statistic: 817.3 on 9 and 825 DF, p-value: < 2.2e-16
PointsReg2 = lm(PTS ~ X2PA + X3PA + FTA + AST + ORB + DRB + STL + BLK, data=NBA)
summary(PointsReg2)
##
## Call:
## lm(formula = PTS ~ X2PA + X3PA + FTA + AST + ORB + DRB + STL +
## BLK, data = NBA)
##
## Residuals:
## Min 1Q Median 3Q Max
## -526.79 -121.09 6.37 120.74 565.94
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -2076.67816 193.08441 -10.755 <2e-16 ***
## X2PA 1.04353 0.02951 35.366 <2e-16 ***
## X3PA 1.26273 0.03703 34.099 <2e-16 ***
## FTA 1.12537 0.03308 34.023 <2e-16 ***
## AST 0.88615 0.04393 20.173 <2e-16 ***
## ORB -0.95815 0.07758 -12.350 <2e-16 ***
## DRB 0.03892 0.06154 0.632 0.5273
## STL -0.20676 0.08984 -2.301 0.0216 *
## BLK -0.05863 0.08749 -0.670 0.5029
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 185.4 on 826 degrees of freedom
## Multiple R-squared: 0.8991, Adjusted R-squared: 0.8982
## F-statistic: 920.4 on 8 and 826 DF, p-value: < 2.2e-16
PointsReg3 = lm(PTS ~ X2PA + X3PA + FTA + AST + ORB + STL + BLK, data=NBA)
summary(PointsReg3)
##
## Call:
## lm(formula = PTS ~ X2PA + X3PA + FTA + AST + ORB + STL + BLK,
## data = NBA)
##
## Residuals:
## Min 1Q Median 3Q Max
## -523.79 -121.64 6.07 120.81 573.64
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -2015.46304 167.00875 -12.068 < 2e-16 ***
## X2PA 1.04828 0.02852 36.753 < 2e-16 ***
## X3PA 1.27079 0.03475 36.568 < 2e-16 ***
## FTA 1.12846 0.03270 34.506 < 2e-16 ***
## AST 0.89093 0.04326 20.597 < 2e-16 ***
## ORB -0.97018 0.07519 -12.903 < 2e-16 ***
## STL -0.22758 0.08356 -2.724 0.00659 **
## BLK -0.03882 0.08165 -0.475 0.63462
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 185.4 on 827 degrees of freedom
## Multiple R-squared: 0.8991, Adjusted R-squared: 0.8982
## F-statistic: 1053 on 7 and 827 DF, p-value: < 2.2e-16
PointsReg4 = lm(PTS ~ X2PA + X3PA + FTA + AST + ORB + STL, data=NBA)
summary(PointsReg4)
##
## Call:
## lm(formula = PTS ~ X2PA + X3PA + FTA + AST + ORB + STL, data = NBA)
##
## Residuals:
## Min 1Q Median 3Q Max
## -523.33 -122.02 6.93 120.68 568.26
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -2032.71640 162.94178 -12.475 < 2e-16 ***
## X2PA 1.04997 0.02829 37.117 < 2e-16 ***
## X3PA 1.27306 0.03441 37.001 < 2e-16 ***
## FTA 1.12731 0.03260 34.581 < 2e-16 ***
## AST 0.88844 0.04292 20.701 < 2e-16 ***
## ORB -0.97430 0.07465 -13.051 < 2e-16 ***
## STL -0.22684 0.08350 -2.717 0.00673 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 185.3 on 828 degrees of freedom
## Multiple R-squared: 0.8991, Adjusted R-squared: 0.8983
## F-statistic: 1229 on 6 and 828 DF, p-value: < 2.2e-16# Compute SSE and RMSE
SSE_4 = sum(PointsReg4$residuals^2)
RMSE_4 = sqrt(SSE_4/nrow(NBA))
SSE_4
## [1] 28421465
RMSE_4
## [1] 184.493# Load in the test set
NBA_test = read.csv("NBA_test.csv")# MAke predictions using the linear regression model on the test set
PointsPredictions = predict(PointsReg4, newdata=NBA_test)# Calculate out-of-sample R^2
SSE = sum((PointsPredictions - NBA_test$PTS)^2)
SST = sum((mean(NBA$PTS) - NBA_test$PTS)^2)
R2 = 1 - SSE/SST
R2
## [1] 0.8127142# Calculate the RMSE
RMSE = sqrt(SSE/nrow(NBA_test))
RMSE
## [1] 196.3723