basketball_train = read.csv("C:/Users/duway/Downloads/NBA_train.csv")
str(basketball_train)
'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 ...

How many observations do we have in the training dataset?

dim(basketball_train)
[1] 835  20

we have 835 rows(observations) and 20 columns in the training dataset

Is there any chance that a team winning 38 games can make it to the playoffs? Why?

# How many wins to make the playoffs?
table(basketball_train$W, basketball_train$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

A team winning 38 games based on historical data made it to the postseason 7 times.

What is the number of wins that can guarantee for any team a presence in the playoffs based on historical data?

#What is the number of wins that can guarantee for any team a presence in the playoffs based on historical data?
table(basketball_train$W, basketball_train$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

A Team needs to win at least 47 games to guarantee a playoff spot.

Can you determine (visually) if there is any relationship between the points difference (PTSdiff) and the number of wins (W)?Explain.

# compute points difference
basketball_train$PTSdiff = basketball_train$PTS - basketball_train$oppPTS
plot(basketball_train$PTSdiff, basketball_train$W, xlab = "Points Difference", ylab = "Wins", main = "Points Difference vs Wins")

There is a positive linear relationship between points difference and the number of wins. The more points a team scores compared to their opponent, the more wins they are likely to have.

Here we want to determine what aspects of the game affect the number of wins of a team(WingsReg model). Is the predictor variable points difference (PTSdiff) significant at a 5% significance level?

# Fit a linear regression model
WingsReg = lm(W ~ PTSdiff, data = basketball_train)
summary(WingsReg)

Call:
lm(formula = W ~ PTSdiff, data = basketball_train)

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

The p-value for PTSdiff is less than 0.05, indicating that it is a significant predictor of the number of wins at a 5% significance level.

We also built a linear model to predict the number of points as a function of some aspects of the game. Is the number of blocks (BLK) significant at a 5% significance level?

# Linear regression model for points scored
PointsReg = lm(PTS ~ X2PA + X3PA + FTA + AST + ORB + DRB + TOV + STL + BLK, data=basketball_train)
summary(PointsReg)

Call:
lm(formula = PTS ~ X2PA + X3PA + FTA + AST + ORB + DRB + TOV + 
    STL + BLK, data = basketball_train)

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 summary of the PointsReg model, the p-value for BLK is not asignificant predictor of points scored at a 5% significance level. The p-value is greater than 0.05, indicating that the number of blocks does not have a statistically significant effect on the number of points scored.

What has been the maximum number of points in a season?

max(basketball_train$PTS)
[1] 10371

The maximum number of points in a season is 10371.

What is the meaning of the RMSE(Root mean squared error) in the PointsReg model? Are you satisfied with this value? # the RMSE is a measure of how well the model predicts the number of points scored. It represents the average distance between the predicted and actual values. A lower RMSE indicates a better fit of the model to the data.

#What is the meaning of the RMSE(Root mean squared error) in the PointsReg model? Are you satisfied with this value?
PointsReg = lm(PTS ~ BLK, data = basketball_train)
PointsReg

Call:
lm(formula = PTS ~ BLK, data = basketball_train)

Coefficients:
(Intercept)          BLK  
   7919.434        1.074  
  

How well did your predictions work on the testing dataset? Report the new R2 and RMSE.

# Sum of Squared Errors
PointsReg$residuals
           1            2            3            4            5 
  38.5722713  142.8720040  -92.8957180   -8.3913473 -258.4705615 
           6            7            8            9           10 
 171.4608325  150.4081623  169.3811429   40.7756197  -75.3256614 
          11           12           13           14           15 
 444.9088743   94.3864704 -205.6809050  113.5969040   64.1993998 
          16           17           18           19           20 
 -76.5711999  249.4888007   28.0363236  329.4487991   96.3248342 
          21           22           23           24           25 
 349.2067913 -284.3765225  196.1611379  198.2493104  445.4100295 
          26           27           28           29           30 
  93.8946072 -316.2962802 -166.1909668   -5.8446359  211.2301997 
          31           32           33           34           35 
 155.7426615  -23.9248929  -77.9070033  218.9449693  164.1368602 
          36           37           38           39           40 
-177.6479438   66.9205988  162.7892553   23.5961895   93.9839603 
          41           42           43           44           45 
 185.7015113  -50.2507837  -90.1181969  139.6866673 -231.1772776 
          46           47           48           49           50 
 111.2200135  185.9069491  210.6753018  -47.9420913 -257.8213675 
          51           52           53           54           55 
 225.7399197   70.4925628  432.6468031  187.4169561  -34.3947653 
          56           57           58           59           60 
 112.9305359  334.4717296  222.4169937   17.6755711  165.4512882 
          61           62           63           64           65 
 207.9970351   56.8277093  214.6051983  -23.0235142  341.7509536 
          66           67           68           69           70 
 -48.3807695  304.9203623  -36.7878762  -31.0357805   61.8847883 
          71           72           73           74           75 
-153.0322403  121.7423324  -61.1581185  -47.9906548 -120.3599484 
          76           77           78           79           80 
 245.7621368 -264.3876116  161.1110819   87.3192423  426.2098591 
          81           82           83           84           85 
  -4.7790973  126.8613801  -97.5009340  329.9773912  -16.2338716 
          86           87           88           89           90 
   7.8513505  191.9280982   87.0090318 -142.5397602 -216.2264974 
          91           92           93           94           95 
-199.6293933   71.0810742  257.3751407 -227.1203824  -61.4866232 
          96           97           98           99          100 
  71.3329444 -233.2637272  -34.7860771   84.9503466  108.6553543 
         101          102          103          104          105 
 -84.8168235  -90.0423121  341.2144522   52.8507112   47.8978397 
         106          107          108          109          110 
 181.0574099  160.7203318  237.0174702  314.9609845   51.9650831 
         111          112          113          114          115 
 300.2035074 -148.0931149  -13.3592416 -161.6184704   82.1172789 
         116          117          118          119          120 
 277.6080699  233.4334153 -225.7299932   69.0259972   37.3407430 
         121          122          123          124          125 
  18.2709681  121.8125335  217.9464858  -74.8210467   36.2611001 
         126          127          128          129          130 
 356.2366230  439.4127892  111.0266627   72.1377278   -6.1141295 
         131          132          133          134          135 
 331.6249450 -158.3642350   94.9048994  151.3242943 -284.7768411 
         136          137          138          139          140 
-184.0287416 -103.9972773   54.1758237  139.3176593  125.3796164 
         141          142          143          144          145 
 -71.4407602   83.4742245 -131.6383234  -33.5752771   98.9460909 
         146          147          148          149          150 
 -59.8760139 -116.6711077 -110.4055752  290.8888709   38.5758792 
         151          152          153          154          155 
  -6.8265554 -284.8106013  149.5419209 -185.9270381  -13.5712897 
         156          157          158          159          160 
 -90.2301662   21.0080300   14.5295957 -346.4091267  -54.7198161 
         161          162          163          164          165 
  87.6823846  203.7903006  -30.7131853 -153.9699795  194.6791232 
         166          167          168          169          170 
-357.4466727  133.8696823  -21.6271760 -220.4987354 -153.7269937 
         171          172          173          174          175 
-383.7168614  212.2104185 -100.3118791  -30.5085767  -57.7910608 
         176          177          178          179          180 
 205.9463003 -124.1358862  -61.2169391  -93.9538879 -135.6180284 
         181          182          183          184          185 
  69.1245169 -435.5355494  -47.8153585  115.1051439  222.5411686 
         186          187          188          189          190 
 104.6516380    7.8335700  178.0759383 -185.3383423  122.0537263 
         191          192          193          194          195 
 -29.4729351   27.1344203  189.2078833 -429.5919872   57.2397301 
         196          197          198          199          200 
-170.2701567  -14.0836520   21.0147294   49.6548689 -127.4633821 
         201          202          203          204          205 
 -87.4084020  -77.6940715 -155.2913076    8.4930328 -232.7210528 
         206          207          208          209          210 
  35.3384277  151.1394532  119.4563308 -416.3088878  134.8599211 
         211          212          213          214          215 
  33.3825347   48.4541197 -269.8021487  214.9045443   88.1318416 
         216          217          218          219          220 
 -24.0318730  188.2281015 -249.1537666  157.9872056 -146.6803006 
         221          222          223          224          225 
  72.9077663   31.1747176  337.2185582   69.7227713   -2.7440511 
         226          227          228          229          230 
 -55.2845827  -84.6255409 -151.4858821  234.7432200 -165.3909069 
         231          232          233          234          235 
-172.9288404  386.6402387   34.4884530 -368.0387956  304.8349400 
         236          237          238          239          240 
-173.0591889  168.9365987 -327.6509605   95.0370278  -75.5698743 
         241          242          243          244          245 
 -74.9702316  290.0371682  -21.8628806   72.5362398 -144.3565453 
         246          247          248          249          250 
 -44.7765529 -155.4752429 -114.0232742   82.8841506 -306.5759686 
         251          252          253          254          255 
 256.9630856   75.4312937 -108.9852622 -160.6985087   -1.0708625 
         256          257          258          259          260 
 389.4834173   48.4039145 -173.2376267  102.4859575  564.7127452 
         261          262          263          264          265 
-135.6781765  435.5847710 -238.8763852   93.4120332 -346.4790813 
         266          267          268          269          270 
  84.2266238  124.2627684  157.9013909   90.9742388 -319.7738668 
         271          272          273          274          275 
 111.6330940 -136.0189613  179.6895020 -139.8481361  -60.2214721 
         276          277          278          279          280 
  21.1448936 -102.4930752   87.4261255   -2.2833983  -33.1839059 
         281          282          283          284          285 
-313.4181662   -9.7903234  365.0041757 -170.9089658 -203.2682115 
         286          287          288          289          290 
 -59.0783300  344.4592952 -177.2934555  278.4424923   31.1539516 
         291          292          293          294          295 
 -19.4217087  146.9309508   49.6437593  323.4485389   47.1034178 
         296          297          298          299          300 
   3.9718411 -111.0589062  -40.0036081  187.1994351  134.5701059 
         301          302          303          304          305 
-130.3795390  227.3624370   16.4481298  -91.2556101  215.9887998 
         306          307          308          309          310 
  70.7747666   50.5357552  -86.7616664   66.3006293  348.5847817 
         311          312          313          314          315 
  69.7928527 -144.9174008   48.2485248  262.5189212  -11.0182067 
         316          317          318          319          320 
 276.2567984   40.2609782 -235.0009787   91.8230888  -36.7029055 
         321          322          323          324          325 
  66.1862316  127.1446887   34.6306466  -89.1508242  -38.0350890 
         326          327          328          329          330 
  74.6959695  -24.6713632 -139.6322463  120.5781319 -256.3194253 
         331          332          333          334          335 
  35.3325803 -238.1863124  204.2701943 -231.4333870 -242.0178081 
         336          337          338          339          340 
  27.3589769  442.7697537  -90.3428846 -252.6536092   31.2460678 
         341          342          343          344          345 
 -24.0030042 -113.6697991   74.2030422  -63.3601223   13.1314540 
         346          347          348          349          350 
 -58.4065092   16.5093336  -26.4233092  -49.9197611  102.5295504 
         351          352          353          354          355 
-276.0762358 -171.2605451  235.4118705 -295.3696087 -259.1915277 
         356          357          358          359          360 
-209.8493128  -60.3803252   40.8738668 -162.3559100   -3.1584146 
         361          362          363          364          365 
-252.6683460 -359.6072976  219.8480950  107.9177034 -228.4285961 
         366          367          368          369          370 
  77.5838841   77.6092501  176.9728823   21.0277939  225.7947949 
         371          372          373          374          375 
  90.6177409  -95.0387148  243.8004275   63.7765295 -135.7112041 
         376          377          378          379          380 
 127.9942080  208.5134149 -226.2507886  -27.4427262  215.5791874 
         381          382          383          384          385 
  70.0554598 -220.3324085 -252.5213694 -117.0224660   36.9146043 
         386          387          388          389          390 
 188.5932206  -12.6241171   24.1401960   39.4113815  130.8261623 
         391          392          393          394          395 
 194.8028770  140.1603242  100.4917058  367.8120506  -77.1138759 
         396          397          398          399          400 
 190.1907177  430.4505906  243.1092461 -220.7690501 -135.3500281 
         401          402          403          404          405 
 182.9169784   58.1314347  -10.3705665  134.0505987  333.4363828 
         406          407          408          409          410 
 110.9704334   37.1431301  188.8559358  -88.4445131 -165.3268990 
         411          412          413          414          415 
 148.8624801   -4.7914163 -114.6045335  -90.1562962  -65.1353805 
         416          417          418          419          420 
   9.9207366  -20.2393315  147.7163583  153.4474395   95.5889698 
         421          422          423          424          425 
-329.6439893  323.3019593  345.3838501 -148.5288812  166.9648145 
         426          427          428          429          430 
 277.3541861  162.6383840  -78.9033000 -176.7932426  365.3962572 
         431          432          433          434          435 
 132.7242544   85.6582953  -19.3417988   95.4767236 -102.8199452 
         436          437          438          439          440 
 111.8183778  299.2808339 -124.0889739  -37.3805041  118.5055640 
         441          442          443          444          445 
  38.2173450 -122.8141423  -84.3447659  154.5643586   42.6355711 
         446          447          448          449          450 
  54.7178397  102.9846564   32.6861086  112.7943954 -163.3563028 
         451          452          453          454          455 
 150.7521084  217.5877806  -96.7133626   13.7243484  -33.1690450 
         456          457          458          459          460 
-112.2550008  -15.7083565 -224.4198990   18.2593593 -393.0403979 
         461          462          463          464          465 
  49.2945267   52.0947949   43.2496203 -149.1223107   75.6856970 
         466          467          468          469          470 
 170.8878792 -257.6364448   51.6854016   11.8121415 -176.9048352 
         471          472          473          474          475 
-149.5317630  -64.1990241  -71.3105611 -317.9190063  -65.8451642 
         476          477          478          479          480 
  97.8497015 -103.1692986    3.0848318 -104.6823532 -234.7534874 
         481          482          483          484          485 
  50.5295490  -75.4835788 -526.1468848 -393.9784124 -360.8366411 
         486          487          488          489          490 
 116.7193515 -321.3756304  -28.1090479 -508.3250405  -39.9958738 
         491          492          493          494          495 
  67.9854387  -97.4641720 -268.8364479  -26.0249946  188.1881640 
         496          497          498          499          500 
-127.9366821  -86.3440758  133.8144538   29.4480488 -292.9821609 
         501          502          503          504          505 
-124.9408024  101.3655240 -186.5181083  -63.5389375 -212.2015589 
         506          507          508          509          510 
-323.1476886 -125.6610320   56.9083106  -39.0559074   -1.9339391 
         511          512          513          514          515 
-319.9727619 -433.1243358 -431.1346590  -95.8909016  120.6089792 
         516          517          518          519          520 
-409.7409083 -352.9341830 -527.3988939  110.6694955 -193.5043557 
         521          522          523          524          525 
 -92.6385367 -143.5858243 -189.7838251  172.1977457  -80.8020663 
         526          527          528          529          530 
-342.9141699  124.8700974 -226.9524006  -73.5173798 -388.4868649 
         531          532          533          534          535 
  82.9536394  -96.7444961 -114.0835553   60.0566113 -332.3804023 
         536          537          538          539          540 
-175.5276633 -338.7116370 -148.1422366  -45.2258816 -270.5159099 
         541          542          543          544          545 
-159.8389177 -420.4637398 -133.0466450  183.8988039 -267.0297916 
         546          547          548          549          550 
  -5.2562902 -228.0471046  -11.6818058 -255.6786897   -7.7244412 
         551          552          553          554          555 
-115.5357863 -298.4118693 -122.2961876   90.2924072  111.3930340 
         556          557          558          559          560 
-245.4519945 -164.6445508  -29.3651223  -41.9781581   33.4260937 
         561          562          563          564          565 
  15.1663563  -29.4557965   44.0659204  247.9836928  -57.4318280 
         566          567          568          569          570 
-238.6989443   -8.7249850   30.9454288 -343.6175905 -207.4418486 
         571          572          573          574          575 
-306.4223254  157.4538406 -502.4785715 -126.1415717   48.8616098 
         576          577          578          579          580 
 143.9835801 -344.7694076 -116.5012114 -142.7898454 -127.9612584 
         581          582          583          584          585 
-226.7659179   67.1679765  -94.0443422 -326.2414346  -84.6517620 
         586          587          588          589          590 
   4.5942017  -89.9757406  -97.0958454  -34.6927947   40.9701699 
         591          592          593          594          595 
 -88.3066869  126.5679875 -128.7529512 -166.6757304 -208.2444446 
         596          597          598          599          600 
-105.4053449  -69.9961388 -104.0297252 -475.1678378 -290.6421238 
         601          602          603          604          605 
 195.4801727 -116.0865727 -136.0505114 -118.3811054  125.8235124 
         606          607          608          609          610 
-145.2484421 -144.5655628 -435.6270621 -230.6201428 -112.7403208 
         611          612          613          614          615 
-243.8883351   13.9124625 -392.1393056 -233.5727670   88.6125994 
         616          617          618          619          620 
-203.7574893 -207.3393547   36.7326516   71.7237279 -110.6124268 
         621          622          623          624          625 
-151.5524839   95.2365977 -227.3589026  -98.5962165 -210.8715081 
         626          627          628          629          630 
 -53.6787512   33.2644764 -380.2334407 -217.0512157 -135.7283167 
         631          632          633          634          635 
 208.5947156 -198.2473902 -147.6362401 -282.5390059  -55.4726214 
         636          637          638          639          640 
   3.0618526 -118.7764165  -15.9756605    1.5396468    2.2068206 
         641          642          643          644          645 
 -78.5559489   20.5194552 -376.9064555 -367.5790965   78.4730898 
         646          647          648          649          650 
  88.0528050 -178.9859105  283.6342652   18.0639226    1.4275017 
         651          652          653          654          655 
 -22.1910648  334.1581029  -44.6704981 -166.2133428 -112.8182784 
         656          657          658          659          660 
 175.7515262   60.9355144 -331.2815975 -175.1322112   34.9727118 
         661          662          663          664          665 
 430.8913232 -260.7815266  -99.5985786 -306.5331420 -144.2463445 
         666          667          668          669          670 
 -71.9561309   40.4095734   -9.9170555    9.7141807   72.8730721 
         671          672          673          674          675 
 -61.2840291  -51.9936086 -452.8596863  -81.9437393   69.2906290 
         676          677          678          679          680 
 254.7395766  -22.9459505  215.8931262  -16.9537293 -107.9068394 
         681          682          683          684          685 
 202.3017464  287.5765859  180.7757394 -305.5932029   56.2240459 
         686          687          688          689          690 
   4.5320328  -44.0648823 -278.0391307  -13.3280981 -112.7276708 
         691          692          693          694          695 
 422.1750569 -131.0023955   51.4971549  -86.9745423   28.8396258 
         696          697          698          699          700 
-107.9302127  -55.3683153  -16.7225380   60.3453436    3.3520616 
         701          702          703          704          705 
 140.9429255  -17.9219329 -296.8381962  136.2394242  106.7244264 
         706          707          708          709          710 
 168.2861008   26.7860625  339.8954937  187.8922770 -202.6392008 
         711          712          713          714          715 
 148.7995083  268.8921528    0.6597544 -119.2916116  -23.0549542 
         716          717          718          719          720 
 -28.1758366  206.7679556 -138.5838793 -210.7824121  -29.6626073 
         721          722          723          724          725 
 210.3268820 -212.8798945   88.1962039  129.1032851   11.9530477 
         726          727          728          729          730 
-166.3796048 -372.3297260   67.5130804    1.7122210 -179.0745146 
         731          732          733          734          735 
 -28.4404659  151.2765881 -425.3360446  344.3671825  -47.2592021 
         736          737          738          739          740 
 136.9801455   63.4427397  203.2044716   27.7908779  251.4279736 
         741          742          743          744          745 
  84.5817590 -155.6577645  150.3787715  138.7921016  198.4699948 
         746          747          748          749          750 
 101.8590582  345.8144412   35.1336113  169.1641149  354.9998851 
         751          752          753          754          755 
 251.7571721   47.8412497   77.9677328   66.2799291  216.7990909 
         756          757          758          759          760 
 155.1577399 -131.2437994  230.2449071  218.7156645  116.0349148 
         761          762          763          764          765 
 -78.5937100  -23.1321308   99.7713990  280.2227149   40.8527845 
         766          767          768          769          770 
  19.4188914   72.9388151  120.7266716  439.1035137  456.0100354 
         771          772          773          774          775 
  47.3239201  186.1096824   31.7505381  -54.0912550   73.0035369 
         776          777          778          779          780 
 234.4761589   27.9146721  -21.6493313  -75.0167664  148.4251726 
         781          782          783          784          785 
 106.3308316   76.0196340   37.3592068   56.5562663  -41.8917486 
         786          787          788          789          790 
-200.7598142  -55.5159544  109.1518868  321.3239680  219.8866600 
         791          792          793          794          795 
 -73.6034103    3.1961900 -171.1408177  190.8979178  101.1845265 
         796          797          798          799          800 
 253.1734885  263.7840087  199.5924560  463.8379676  219.1540922 
         801          802          803          804          805 
  52.3032317  140.7498122  195.8267787  -55.3103142  153.8564182 
         806          807          808          809          810 
  61.1275837   92.8158603 -108.8302808   73.3423661 -360.6001538 
         811          812          813          814          815 
 134.1518035   73.3435884  141.0017271  272.8259956  -33.1611977 
         816          817          818          819          820 
  19.7818711 -149.9998706  190.0065593  261.3992751  308.7602526 
         821          822          823          824          825 
-135.4172110  108.2677094 -171.3410196  102.4439076  156.0829202 
         826          827          828          829          830 
 210.0521687  109.4908936  -20.5354175   59.2845716  175.9235274 
         831          832          833          834          835 
  30.6531825  262.6728011   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(basketball_train))
RMSE
[1] 184.4049
# Average number of points in a season
mean(basketball_train$PTS)
[1] 8370.24
# Remove insignifcant variables
summary(PointsReg)

Call:
lm(formula = PTS ~ X2PA + X3PA + FTA + AST + ORB + DRB + TOV + 
    STL + BLK, data = basketball_train)

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
PointsReg2 = lm(PTS ~ X2PA + X3PA + FTA + AST + ORB + DRB + STL + BLK, data=basketball_train)
summary(PointsReg2)

Call:
lm(formula = PTS ~ X2PA + X3PA + FTA + AST + ORB + DRB + STL + 
    BLK, data = basketball_train)

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) -2.077e+03  1.931e+02 -10.755   <2e-16 ***
X2PA         1.044e+00  2.951e-02  35.366   <2e-16 ***
X3PA         1.263e+00  3.703e-02  34.099   <2e-16 ***
FTA          1.125e+00  3.308e-02  34.023   <2e-16 ***
AST          8.861e-01  4.393e-02  20.173   <2e-16 ***
ORB         -9.581e-01  7.758e-02 -12.350   <2e-16 ***
DRB          3.892e-02  6.154e-02   0.632   0.5273    
STL         -2.068e-01  8.984e-02  -2.301   0.0216 *  
BLK         -5.863e-02  8.749e-02  -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=basketball_train)
summary(PointsReg3)

Call:
lm(formula = PTS ~ X2PA + X3PA + FTA + AST + ORB + STL + BLK, 
    data = basketball_train)

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) -2.015e+03  1.670e+02 -12.068  < 2e-16 ***
X2PA         1.048e+00  2.852e-02  36.753  < 2e-16 ***
X3PA         1.271e+00  3.475e-02  36.568  < 2e-16 ***
FTA          1.128e+00  3.270e-02  34.506  < 2e-16 ***
AST          8.909e-01  4.326e-02  20.597  < 2e-16 ***
ORB         -9.702e-01  7.519e-02 -12.903  < 2e-16 ***
STL         -2.276e-01  8.356e-02  -2.724  0.00659 ** 
BLK         -3.882e-02  8.165e-02  -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=basketball_train)
summary(PointsReg4)

Call:
lm(formula = PTS ~ X2PA + X3PA + FTA + AST + ORB + STL, data = basketball_train)

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) -2.033e+03  1.629e+02 -12.475  < 2e-16 ***
X2PA         1.050e+00  2.829e-02  37.117  < 2e-16 ***
X3PA         1.273e+00  3.441e-02  37.001  < 2e-16 ***
FTA          1.127e+00  3.260e-02  34.581  < 2e-16 ***
AST          8.884e-01  4.292e-02  20.701  < 2e-16 ***
ORB         -9.743e-01  7.465e-02 -13.051  < 2e-16 ***
STL         -2.268e-01  8.350e-02  -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 for new model
SSE_4 = sum(PointsReg4$residuals^2)
RMSE_4 = sqrt(SSE_4/nrow(basketball_train))
SSE_4
[1] 28421465
RMSE_4
[1] 184.493

basketball_test = read.csv("C:/Users/duway/Downloads/NBA_test.csv")
# Make predictions on test set
PointsPredictions = predict(PointsReg4, newdata=basketball_test)
# Compute out-of-sample R^2
SSE = sum((PointsPredictions - basketball_test$PTS)^2)
SST = sum((mean(basketball_train$PTS) - basketball_test$PTS)^2)
R2 = 1 - SSE/SST
R2
[1] 0.8127142

0.812 means the features we have chosen explain 81.2% of the variance in the test dataset. This is a good value, indicating that the model is able to explain a significant portion of the variability in the number of points scored.

# Compute the RMSE
RMSE = sqrt(SSE/nrow(basketball_test))
RMSE 
[1] 196.3723

based on the RMSE value 196 means that the prediction value is off by 196 in terms of points scored every season this RMSE is a very good model to work with.

Activity 13

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.

# Fit a linear regression model
WingsReg = lm(W ~ PTSdiff, data = basketball_train)
summary(WingsReg)

Call:
lm(formula = W ~ PTSdiff, data = basketball_train)

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
# Calculate expected points difference for a team with 49 wins
 
WingsReg = lm(W ~ PTSdiff, data = basketball_train)
PTSdiff = (49 - WingsReg$coefficients[1]) / WingsReg$coefficients[2]
PTSdiff
(Intercept) 
   245.5017 
#49=41+0.326*(x)
x_1= (49-41)/0.0326
x_1
[1] 245.3988

The expected points difference for a team to make it to the postseason is 245.39 points. This means that a team with 49 wins is expected to have a points difference of 245.39 points in order to make it to the playoffs.

LS0tDQp0aXRsZTogIkFjdGl2aXR5IDEyIg0Kb3V0cHV0OiBodG1sX25vdG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