Bosco M Morales
Special Topics in Data Analytics
Spring 2025
# Get working directory
getwd()
[1] "/cloud/project"
# Read in the data
nba = read.csv("NBA_train.csv")
str(nba)
'data.frame': 835 obs. of 20 variables:
$ SeasonEnd: int 1980 1980 1980 1980 1980 1980 1980 1980 1980 1980 ...
$ Team : chr "Atlanta Hawks" "Boston Celtics" "Chicago Bulls" "Cleveland Cavaliers" ...
$ 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 ...
View(nba)
There are 835 observations in the training data set.
# From Video #2
# How many wins to make it to the playoffs?
View(table(nba$W,nba$Playoffs))
# From Video #2
# How many wins to make it to the playoffs?
table(nba$W,nba$Playoffs)
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
Yes. There is a chance for a team winning 38 games to make to the playoffs According to our data a team who has won 38 games made it to the playoffs 7 out of 15 times. Just a bit less than half the time.
Given historical data, winning at least 40 games could guarantee for any team making it to the playoffs
Yes, there is a linear relationship. Please see scatter plot below
# Compute Points Difference
nba$PTSdiff = nba$PTS - nba$oppPTS
# Check for linear relationship
plot(nba$PTSdiff, nba$W)
WinsReg = lm(W ~ PTSdiff, data=nba)
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) 4.100e+01 1.059e-01 387.0 <2e-16 ***
PTSdiff 3.259e-02 2.793e-04 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
41 + 0.03259 (diffPTS)
Yes, because the p-value for PTSdiff is reported as < 2e-16, which is much smaller than 0.05. The predictor variable points difference (PTSdiff) is statistically significant at the 5% significance level. Also, the triple asterisks next to the p-value also indicate high statistical significance.
# Linear Regression model for points scored
PointsReg = lm(PTS ~ X2PA + X3PA + FTA + AST + ORB + DRB + TOV + STL + BLK, data=nba)
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) -2.051e+03 2.035e+02 -10.078 <2e-16 ***
X2PA 1.043e+00 2.957e-02 35.274 <2e-16 ***
X3PA 1.259e+00 3.843e-02 32.747 <2e-16 ***
FTA 1.128e+00 3.373e-02 33.440 <2e-16 ***
AST 8.858e-01 4.396e-02 20.150 <2e-16 ***
ORB -9.554e-01 7.792e-02 -12.261 <2e-16 ***
DRB 3.883e-02 6.157e-02 0.631 0.5285
TOV -2.475e-02 6.118e-02 -0.405 0.6859
STL -1.992e-01 9.181e-02 -2.169 0.0303 *
BLK -5.576e-02 8.782e-02 -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
According to the model ran for this activity (PointsReg) the number of blocks (BLK) is not significant given that p > 0.05. See model results above.
summary(nba$PTS)
Min. 1st Qu. Median Mean 3rd Qu. Max.
6901 7934 8312 8370 8784 10371
The maximum number of points in a season is 10371
# Residuals
PointsReg$residuals
1 2 3 4 5 6 7 8 9 10 11 12 13
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
14 15 16 17 18 19 20 21 22 23 24 25 26
113.5969040 64.1993998 -76.5711999 249.4888007 28.0363236 329.4487991 96.3248342 349.2067913 -284.3765225 196.1611379 198.2493104 445.4100295 93.8946072
27 28 29 30 31 32 33 34 35 36 37 38 39
-316.2962802 -166.1909668 -5.8446359 211.2301997 155.7426615 -23.9248929 -77.9070033 218.9449693 164.1368602 -177.6479438 66.9205988 162.7892553 23.5961895
40 41 42 43 44 45 46 47 48 49 50 51 52
93.9839603 185.7015113 -50.2507837 -90.1181969 139.6866673 -231.1772776 111.2200135 185.9069491 210.6753018 -47.9420913 -257.8213675 225.7399197 70.4925628
53 54 55 56 57 58 59 60 61 62 63 64 65
432.6468031 187.4169561 -34.3947653 112.9305359 334.4717296 222.4169937 17.6755711 165.4512882 207.9970351 56.8277093 214.6051983 -23.0235142 341.7509536
66 67 68 69 70 71 72 73 74 75 76 77 78
-48.3807695 304.9203623 -36.7878762 -31.0357805 61.8847883 -153.0322403 121.7423324 -61.1581185 -47.9906548 -120.3599484 245.7621368 -264.3876116 161.1110819
79 80 81 82 83 84 85 86 87 88 89 90 91
87.3192423 426.2098591 -4.7790973 126.8613801 -97.5009340 329.9773912 -16.2338716 7.8513505 191.9280982 87.0090318 -142.5397602 -216.2264974 -199.6293933
92 93 94 95 96 97 98 99 100 101 102 103 104
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
105 106 107 108 109 110 111 112 113 114 115 116 117
47.8978397 181.0574099 160.7203318 237.0174702 314.9609845 51.9650831 300.2035074 -148.0931149 -13.3592416 -161.6184704 82.1172789 277.6080699 233.4334153
118 119 120 121 122 123 124 125 126 127 128 129 130
-225.7299932 69.0259972 37.3407430 18.2709681 121.8125335 217.9464858 -74.8210467 36.2611001 356.2366230 439.4127892 111.0266627 72.1377278 -6.1141295
131 132 133 134 135 136 137 138 139 140 141 142 143
331.6249450 -158.3642350 94.9048994 151.3242943 -284.7768411 -184.0287416 -103.9972773 54.1758237 139.3176593 125.3796164 -71.4407602 83.4742245 -131.6383234
144 145 146 147 148 149 150 151 152 153 154 155 156
-33.5752771 98.9460909 -59.8760139 -116.6711077 -110.4055752 290.8888709 38.5758792 -6.8265554 -284.8106013 149.5419209 -185.9270381 -13.5712897 -90.2301662
157 158 159 160 161 162 163 164 165 166 167 168 169
21.0080300 14.5295957 -346.4091267 -54.7198161 87.6823846 203.7903006 -30.7131853 -153.9699795 194.6791232 -357.4466727 133.8696823 -21.6271760 -220.4987354
170 171 172 173 174 175 176 177 178 179 180 181 182
-153.7269937 -383.7168614 212.2104185 -100.3118791 -30.5085767 -57.7910608 205.9463003 -124.1358862 -61.2169391 -93.9538879 -135.6180284 69.1245169 -435.5355494
183 184 185 186 187 188 189 190 191 192 193 194 195
-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
-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
209 210 211 212 213 214 215 216 217 218 219 220 221
-416.3088878 134.8599211 33.3825347 48.4541197 -269.8021487 214.9045443 88.1318416 -24.0318730 188.2281015 -249.1537666 157.9872056 -146.6803006 72.9077663
222 223 224 225 226 227 228 229 230 231 232 233 234
31.1747176 337.2185582 69.7227713 -2.7440511 -55.2845827 -84.6255409 -151.4858821 234.7432200 -165.3909069 -172.9288404 386.6402387 34.4884530 -368.0387956
235 236 237 238 239 240 241 242 243 244 245 246 247
304.8349400 -173.0591889 168.9365987 -327.6509605 95.0370278 -75.5698743 -74.9702316 290.0371682 -21.8628806 72.5362398 -144.3565453 -44.7765529 -155.4752429
248 249 250 251 252 253 254 255 256 257 258 259 260
-114.0232742 82.8841506 -306.5759686 256.9630856 75.4312937 -108.9852622 -160.6985087 -1.0708625 389.4834173 48.4039145 -173.2376267 102.4859575 564.7127452
261 262 263 264 265 266 267 268 269 270 271 272 273
-135.6781765 435.5847710 -238.8763852 93.4120332 -346.4790813 84.2266238 124.2627684 157.9013909 90.9742388 -319.7738668 111.6330940 -136.0189613 179.6895020
274 275 276 277 278 279 280 281 282 283 284 285 286
-139.8481361 -60.2214721 21.1448936 -102.4930752 87.4261255 -2.2833983 -33.1839059 -313.4181662 -9.7903234 365.0041757 -170.9089658 -203.2682115 -59.0783300
287 288 289 290 291 292 293 294 295 296 297 298 299
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
300 301 302 303 304 305 306 307 308 309 310 311 312
134.5701059 -130.3795390 227.3624370 16.4481298 -91.2556101 215.9887998 70.7747666 50.5357552 -86.7616664 66.3006293 348.5847817 69.7928527 -144.9174008
313 314 315 316 317 318 319 320 321 322 323 324 325
48.2485248 262.5189212 -11.0182067 276.2567984 40.2609782 -235.0009787 91.8230888 -36.7029055 66.1862316 127.1446887 34.6306466 -89.1508242 -38.0350890
326 327 328 329 330 331 332 333 334 335 336 337 338
74.6959695 -24.6713632 -139.6322463 120.5781319 -256.3194253 35.3325803 -238.1863124 204.2701943 -231.4333870 -242.0178081 27.3589769 442.7697537 -90.3428846
339 340 341 342 343 344 345 346 347 348 349 350 351
-252.6536092 31.2460678 -24.0030042 -113.6697991 74.2030422 -63.3601223 13.1314540 -58.4065092 16.5093336 -26.4233092 -49.9197611 102.5295504 -276.0762358
352 353 354 355 356 357 358 359 360 361 362 363 364
-171.2605451 235.4118705 -295.3696087 -259.1915277 -209.8493128 -60.3803252 40.8738668 -162.3559100 -3.1584146 -252.6683460 -359.6072976 219.8480950 107.9177034
365 366 367 368 369 370 371 372 373 374 375 376 377
-228.4285961 77.5838841 77.6092501 176.9728823 21.0277939 225.7947949 90.6177409 -95.0387148 243.8004275 63.7765295 -135.7112041 127.9942080 208.5134149
378 379 380 381 382 383 384 385 386 387 388 389 390
-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
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
404 405 406 407 408 409 410 411 412 413 414 415 416
134.0505987 333.4363828 110.9704334 37.1431301 188.8559358 -88.4445131 -165.3268990 148.8624801 -4.7914163 -114.6045335 -90.1562962 -65.1353805 9.9207366
417 418 419 420 421 422 423 424 425 426 427 428 429
-20.2393315 147.7163583 153.4474395 95.5889698 -329.6439893 323.3019593 345.3838501 -148.5288812 166.9648145 277.3541861 162.6383840 -78.9033000 -176.7932426
430 431 432 433 434 435 436 437 438 439 440 441 442
365.3962572 132.7242544 85.6582953 -19.3417988 95.4767236 -102.8199452 111.8183778 299.2808339 -124.0889739 -37.3805041 118.5055640 38.2173450 -122.8141423
443 444 445 446 447 448 449 450 451 452 453 454 455
-84.3447659 154.5643586 42.6355711 54.7178397 102.9846564 32.6861086 112.7943954 -163.3563028 150.7521084 217.5877806 -96.7133626 13.7243484 -33.1690450
456 457 458 459 460 461 462 463 464 465 466 467 468
-112.2550008 -15.7083565 -224.4198990 18.2593593 -393.0403979 49.2945267 52.0947949 43.2496203 -149.1223107 75.6856970 170.8878792 -257.6364448 51.6854016
469 470 471 472 473 474 475 476 477 478 479 480 481
11.8121415 -176.9048352 -149.5317630 -64.1990241 -71.3105611 -317.9190063 -65.8451642 97.8497015 -103.1692986 3.0848318 -104.6823532 -234.7534874 50.5295490
482 483 484 485 486 487 488 489 490 491 492 493 494
-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
495 496 497 498 499 500 501 502 503 504 505 506 507
188.1881640 -127.9366821 -86.3440758 133.8144538 29.4480488 -292.9821609 -124.9408024 101.3655240 -186.5181083 -63.5389375 -212.2015589 -323.1476886 -125.6610320
508 509 510 511 512 513 514 515 516 517 518 519 520
56.9083106 -39.0559074 -1.9339391 -319.9727619 -433.1243358 -431.1346590 -95.8909016 120.6089792 -409.7409083 -352.9341830 -527.3988939 110.6694955 -193.5043557
521 522 523 524 525 526 527 528 529 530 531 532 533
-92.6385367 -143.5858243 -189.7838251 172.1977457 -80.8020663 -342.9141699 124.8700974 -226.9524006 -73.5173798 -388.4868649 82.9536394 -96.7444961 -114.0835553
534 535 536 537 538 539 540 541 542 543 544 545 546
60.0566113 -332.3804023 -175.5276633 -338.7116370 -148.1422366 -45.2258816 -270.5159099 -159.8389177 -420.4637398 -133.0466450 183.8988039 -267.0297916 -5.2562902
547 548 549 550 551 552 553 554 555 556 557 558 559
-228.0471046 -11.6818058 -255.6786897 -7.7244412 -115.5357863 -298.4118693 -122.2961876 90.2924072 111.3930340 -245.4519945 -164.6445508 -29.3651223 -41.9781581
560 561 562 563 564 565 566 567 568 569 570 571 572
33.4260937 15.1663563 -29.4557965 44.0659204 247.9836928 -57.4318280 -238.6989443 -8.7249850 30.9454288 -343.6175905 -207.4418486 -306.4223254 157.4538406
573 574 575 576 577 578 579 580 581 582 583 584 585
-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
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
599 600 601 602 603 604 605 606 607 608 609 610 611
-475.1678378 -290.6421238 195.4801727 -116.0865727 -136.0505114 -118.3811054 125.8235124 -145.2484421 -144.5655628 -435.6270621 -230.6201428 -112.7403208 -243.8883351
612 613 614 615 616 617 618 619 620 621 622 623 624
13.9124625 -392.1393056 -233.5727670 88.6125994 -203.7574893 -207.3393547 36.7326516 71.7237279 -110.6124268 -151.5524839 95.2365977 -227.3589026 -98.5962165
625 626 627 628 629 630 631 632 633 634 635 636 637
-210.8715081 -53.6787512 33.2644764 -380.2334407 -217.0512157 -135.7283167 208.5947156 -198.2473902 -147.6362401 -282.5390059 -55.4726214 3.0618526 -118.7764165
638 639 640 641 642 643 644 645 646 647 648 649 650
-15.9756605 1.5396468 2.2068206 -78.5559489 20.5194552 -376.9064555 -367.5790965 78.4730898 88.0528050 -178.9859105 283.6342652 18.0639226 1.4275017
651 652 653 654 655 656 657 658 659 660 661 662 663
-22.1910648 334.1581029 -44.6704981 -166.2133428 -112.8182784 175.7515262 60.9355144 -331.2815975 -175.1322112 34.9727118 430.8913232 -260.7815266 -99.5985786
664 665 666 667 668 669 670 671 672 673 674 675 676
-306.5331420 -144.2463445 -71.9561309 40.4095734 -9.9170555 9.7141807 72.8730721 -61.2840291 -51.9936086 -452.8596863 -81.9437393 69.2906290 254.7395766
677 678 679 680 681 682 683 684 685 686 687 688 689
-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
690 691 692 693 694 695 696 697 698 699 700 701 702
-112.7276708 422.1750569 -131.0023955 51.4971549 -86.9745423 28.8396258 -107.9302127 -55.3683153 -16.7225380 60.3453436 3.3520616 140.9429255 -17.9219329
703 704 705 706 707 708 709 710 711 712 713 714 715
-296.8381962 136.2394242 106.7244264 168.2861008 26.7860625 339.8954937 187.8922770 -202.6392008 148.7995083 268.8921528 0.6597544 -119.2916116 -23.0549542
716 717 718 719 720 721 722 723 724 725 726 727 728
-28.1758366 206.7679556 -138.5838793 -210.7824121 -29.6626073 210.3268820 -212.8798945 88.1962039 129.1032851 11.9530477 -166.3796048 -372.3297260 67.5130804
729 730 731 732 733 734 735 736 737 738 739 740 741
1.7122210 -179.0745146 -28.4404659 151.2765881 -425.3360446 344.3671825 -47.2592021 136.9801455 63.4427397 203.2044716 27.7908779 251.4279736 84.5817590
742 743 744 745 746 747 748 749 750 751 752 753 754
-155.6577645 150.3787715 138.7921016 198.4699948 101.8590582 345.8144412 35.1336113 169.1641149 354.9998851 251.7571721 47.8412497 77.9677328 66.2799291
755 756 757 758 759 760 761 762 763 764 765 766 767
216.7990909 155.1577399 -131.2437994 230.2449071 218.7156645 116.0349148 -78.5937100 -23.1321308 99.7713990 280.2227149 40.8527845 19.4188914 72.9388151
768 769 770 771 772 773 774 775 776 777 778 779 780
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
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
794 795 796 797 798 799 800 801 802 803 804 805 806
190.8979178 101.1845265 253.1734885 263.7840087 199.5924560 463.8379676 219.1540922 52.3032317 140.7498122 195.8267787 -55.3103142 153.8564182 61.1275837
807 808 809 810 811 812 813 814 815 816 817 818 819
92.8158603 -108.8302808 73.3423661 -360.6001538 134.1518035 73.3435884 141.0017271 272.8259956 -33.1611977 19.7818711 -149.9998706 190.0065593 261.3992751
820 821 822 823 824 825 826 827 828 829 830 831 832
308.7602526 -135.4172110 108.2677094 -171.3410196 102.4439076 156.0829202 210.0521687 109.4908936 -20.5354175 59.2845716 175.9235274 30.6531825 262.6728011
833 834 835
70.0671862 -17.5789419 -8.3393046
# Sum of Squared Errors
SSE = sum(PointsReg$residuals^2)
SSE
[1] 28394314
# Root Mean Squared Error
RMSE = sqrt(SSE / nrow(nba))
RMSE
[1] 184.4049
Meaning of RMSE (184.4): The model’s prediction of team wins is, on average, based on a season-long point differential error of 184 points, or about 2.2 points per game.
Are we satisfied Yes — this level of error is quite reasonable and suggests your model is doing a good job.
# Average Number of Points in a Season
mean(nba$PTS)
# Remove Insignificant Variables
summary(PointsReg)
# Linear Regression model two for wins
PointsRegTwo = lm (PTS ~ X2PA + X3PA + FTA +AST + ORB + DRB + STL + BLK, data=nba)
summary(PointsRegTwo)
# Linear Regression model three for wins
PointsRegThree = lm(PTS ~ X2PA + X3PA + FTA + AST + ORB + STL+ BLK, data=nba)
summary(PointsRegThree)
# Linear Regression model four for wins
PointsRegFour = lm(PTS ~ X2PA + X3PA + FTA + AST + ORB + STL, data=nba)
summary(PointsRegFour)
# Compute SSE and RMSE for Model Four
SSE_4 = sum(PointsRegFour$residuals^2)
RMSE_4 = sqrt(SSE_4/nrow(nba))
# Sum of Squared Error for Model 4
SSE_4
[1] 28421465
# RMSE for Model 4
RMSE_4
[1] 184.493
Video 4
# Read in Test data
nba_test = read.csv("NBA_test.csv")
# Make predictions on test set
PointsPredictions = predict(PointsRegFour, newdata = nba_test)
# Compute out-of-sample R^2
SSE_test = sum ((PointsPredictions - nba_test$PTS)^2)
SST = sum((mean(nba$PTS) - nba_test$PTS)^2)
R2 = 1 - (SSE_test / SST)
R2
[1] 0.8127142
# Compute the RMSE
RMSE_test = sqrt( SSE_test /nrow(nba_test))
RMSE_test
[1] 196.3723
The predictions on the testing dataset worked reasonably well but were less accurate than on the training data. The Root Mean Squared Error (RMSE) was approximately 196.37, meaning that the predicted number of wins based on the season-long point differential was off by about 196 points across the season. When broken down across 82 games, this equates to an average error of approximately 2.4 points per game (196.37 ÷ 82), which is still within an acceptable range in sports analytics.
The R-squared (R²) value of 0.8127 indicates that the model explains about 81.27% of the variability in season wins. While this is lower than the training R² of 94.23%, it still shows a strong predictive relationship and suggests that the model generalizes fairly well to new data — though with slightly less precision than it had on the training set.
Our data shows that a team with 49 wins has never missed the playoffs. What is the expected points difference for a team to make it to the postseason? Use the lecture solution file and more specifically the WingsReg model.
# Given the linear equation.. we need to solve for
# 49 = 41 + 0.03259 (diffPTS)
# diffPTS = (-41 + 49) / 0.03259
diffPTS_49 = (-41 + 49) / 0.0326
diffPTS_49
[1] 245.3988
The expected points difference for a team to make it to the postseason given 49 wins is 245.
Consider the following vectors representing the number of three-pointers made and attempted by a basketball player in five games: Three-Pointers Made: c(4, 5, 3, 6, 7) Three-Pointers Attempted: c(9, 10, 8, 11, 12) Calculate the three-point shooting percentage for each game and select the correct average three-point shooting percentage for the five games.
three_pointers_made <- c(4,5,3,6,7)
three_pointers_attempted <- c(9,10,8,11,12)
# Calculate the shooting percentage for each game
shooting_percentage <- (three_pointers_made / three_pointers_attempted) * 100
# Print individual game percentages
print(round(shooting_percentage),2)
[1] 44 50 38 55 58
mean(round(shooting_percentage, 2))
[1] 48.964
The correct average three-point shooting percentage for the five games is 48.964%