Problem 2: NFL Data

Consider the first three variables, listed below, in the data concerning the performance of the 28 National Footbal Leagues in 1976.

Y = games won (per 14-game season)

x1 = rushing yards (per 14-game season)

x2 = passing yards (per 14-game season)

library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.3     v purrr   0.3.4
## v tibble  3.0.6     v dplyr   1.0.3
## v tidyr   1.1.2     v stringr 1.4.0
## v readr   1.4.0     v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(dplyr)
library(tidyr)
# Load Data ( make sure URL is on one line)
nfl<-read.csv("https://raw.githubusercontent.com/kitadasmalley/sp21_MATH376LMT/main/data/nlf1976.csv", header = TRUE)

b) Make a 3D scatterplot with the least squares fitted plane.

library(scatterplot3d)

nfl3d<-scatterplot3d(x=nfl$x1, y=nfl$x2, z=nfl$y, 
                    pch=16, angle = 60)

nfl3d$plane3d(mlr)

c) Report the hat matrix H and I-H. Verify whether H(I-H) = 0. (It’s okay to round)

response_matrix<-nfl$y

design_matrix<-matrix(c(rep(1, dim(nfl)[1]), nfl$x1, nfl$x2), nrow=dim(nfl)[1])

hat_matrix<-design_matrix%*%solve(t(design_matrix)%*%design_matrix)%*%t(design_matrix)

I<-diag(dim(nfl)[1])

hat_matrix
##             [,1]         [,2]         [,3]          [,4]         [,5]
##  [1,] 0.03872158  0.020353402  0.043703757  0.0192077090  0.045201201
##  [2,] 0.02035340  0.116329612 -0.024537978  0.1156249931 -0.032478890
##  [3,] 0.04370376 -0.024537978  0.232453827  0.0316058863  0.239069414
##  [4,] 0.01920771  0.115624993  0.031605886  0.1353163755  0.023983866
##  [5,] 0.04520120 -0.032478890  0.239069414  0.0239838658  0.246470264
##  [6,] 0.01873486  0.117474169  0.035459619  0.1390688923  0.027678934
##  [7,] 0.03106173  0.049701759  0.111613292  0.0812375029  0.110622830
##  [8,] 0.02280440  0.100527261  0.011609002  0.1088826723  0.005333847
##  [9,] 0.05093199 -0.031932552 -0.014879599 -0.0684251661 -0.008669878
## [10,] 0.04168949 -0.005235669  0.145735253  0.0242365221  0.150125209
## [11,] 0.04932543 -0.039373068  0.122095665 -0.0276228687  0.129627791
## [12,] 0.03436545  0.042603165  0.032138186  0.0431195135  0.031466660
## [13,] 0.03350357  0.042678654  0.068907645  0.0566950850  0.068393874
## [14,] 0.03414575  0.047820574 -0.005413327  0.0359541548 -0.006749741
## [15,] 0.03541174  0.034872312  0.056461418  0.0422550755  0.056634598
## [16,] 0.04423755  0.001353802 -0.024467813 -0.0298242231 -0.021468335
## [17,] 0.03707341  0.042982217 -0.088951139 -0.0007934651 -0.090201904
## [18,] 0.01882873  0.127095972 -0.055476026  0.1179050949 -0.064580147
## [19,] 0.03273391  0.050693393  0.030001576  0.0525724981  0.028550672
## [20,] 0.03886945  0.027430513 -0.026607252  0.0023854029 -0.026098599
## [21,] 0.04286926  0.004097741  0.010217971 -0.0136362497  0.013111951
## [22,] 0.04679578 -0.016453301  0.025116485 -0.0341768298  0.030032749
## [23,] 0.04915999 -0.031976317  0.062513375 -0.0401074883  0.069074423
## [24,] 0.02068338  0.107748522  0.038586033  0.1279095400  0.031744779
## [25,] 0.02962772  0.068299495  0.006041361  0.0660648345  0.002807738
## [26,] 0.04595712 -0.024186192  0.131363766 -0.0050096556  0.137492419
## [27,] 0.02489412  0.106830569 -0.136094852  0.0627082956 -0.143632332
## [28,] 0.04910753 -0.018344158 -0.058265546 -0.0671379676 -0.053543393
##                [,6]         [,7]         [,8]         [,9]        [,10]
##  [1,]  0.0187348617  0.031061733  0.022804403  0.050931992  0.041689490
##  [2,]  0.1174741692  0.049701759  0.100527261 -0.031932552 -0.005235669
##  [3,]  0.0354596193  0.111613292  0.011609002 -0.014879599  0.145735253
##  [4,]  0.1390688923  0.081237503  0.108882672 -0.068425166  0.024236522
##  [5,]  0.0276789345  0.110622830  0.005333847 -0.008669878  0.150125209
##  [6,]  0.1430445283  0.084538641  0.111209280 -0.073467951  0.026038023
##  [7,]  0.0845386412  0.087294587  0.060812388 -0.033600806  0.073812964
##  [8,]  0.1112092800  0.060812388  0.091726441 -0.034898966  0.015530835
##  [9,] -0.0734679507 -0.033600806 -0.034898966  0.159924906  0.017125304
## [10,]  0.0260380233  0.073812964  0.015530835  0.017125304  0.098087236
## [11,] -0.0283008612  0.039910749 -0.019800002  0.078545482  0.089696977
## [12,]  0.0433318100  0.037804756  0.041505079  0.028884996  0.033038220
## [13,]  0.0581800753  0.058779592  0.047473242  0.004267272  0.052277327
## [14,]  0.0351247067  0.019554897  0.040301434  0.046945037  0.012771943
## [15,]  0.0429300839  0.047019513  0.038264586  0.023006848  0.046673180
## [16,] -0.0335757708 -0.019121984 -0.005684668  0.121798272  0.008220949
## [17,] -0.0047418214 -0.030893728  0.022430574  0.109116712 -0.030393342
## [18,]  0.1192111938  0.038539857  0.105511056 -0.025703770 -0.022687627
## [19,]  0.0531053175  0.041434138  0.048636685  0.019489121  0.030975471
## [20,] -0.0001691798 -0.004721377  0.018063732  0.088347759  0.004057351
## [21,] -0.0160569747  0.002265041  0.002414552  0.095000886  0.026057843
## [22,] -0.0370848853 -0.001563397 -0.014182062  0.112553574  0.036255555
## [23,] -0.0424813615  0.010426001 -0.022524305  0.108380154  0.057643753
## [24,]  0.1315191147  0.080493149  0.102725533 -0.062544710  0.028809795
## [25,]  0.0666287237  0.038340702  0.061058899  0.011917293  0.016377910
## [26,] -0.0046276745  0.054282302 -0.004282485  0.052053680  0.092776002
## [27,]  0.0602444183 -0.019487130  0.073855800  0.055154947 -0.062524261
## [28,] -0.0730159137 -0.050157972 -0.029304812  0.170679162 -0.007172212
##              [,11]      [,12]        [,13]        [,14]      [,15]        [,16]
##  [1,]  0.049325430 0.03436545  0.033503566  0.034145749 0.03541174  0.044237546
##  [2,] -0.039373068 0.04260317  0.042678654  0.047820574 0.03487231  0.001353802
##  [3,]  0.122095665 0.03213819  0.068907645 -0.005413327 0.05646142 -0.024467813
##  [4,] -0.027622869 0.04311951  0.056695085  0.035954155 0.04225508 -0.029824223
##  [5,]  0.129627791 0.03146666  0.068393874 -0.006749741 0.05663460 -0.021468335
##  [6,] -0.028300861 0.04333181  0.058180075  0.035124707 0.04293008 -0.033575771
##  [7,]  0.039910749 0.03780476  0.058779592  0.019554897 0.04701951 -0.019121984
##  [8,] -0.019800002 0.04150508  0.047473242  0.040301434 0.03826459 -0.005684668
##  [9,]  0.078545482 0.02888500  0.004267272  0.046945037 0.02300685  0.121798272
## [10,]  0.089696977 0.03303822  0.052277327  0.012771943 0.04667318  0.008220949
## [11,]  0.111688805 0.02961149  0.036886792  0.018039332 0.04051140  0.050591555
## [12,]  0.029611493 0.03631927  0.036707479  0.036416260 0.03585089  0.031887946
## [13,]  0.036886792 0.03670748  0.046035016  0.028640538 0.04073358  0.011012984
## [14,]  0.018039332 0.03641626  0.028640538  0.044315698 0.03133380  0.048710568
## [15,]  0.040511402 0.03585089  0.040733583  0.031333804 0.03839091  0.024686824
## [16,]  0.050591555 0.03188795  0.011012984  0.048710568 0.02468682  0.098956750
## [17,]  0.005161411 0.03509932  0.006162956  0.062018358 0.01982684  0.100100422
## [18,] -0.053967237 0.04328589  0.037814753  0.054277886 0.03172426  0.009720901
## [19,]  0.022855965 0.03705114  0.038396073  0.036804391 0.03628491  0.026226641
## [20,]  0.029763847 0.03429616  0.017657325  0.048957748 0.02671531  0.078022111
## [21,]  0.055363580 0.03250326  0.020548455  0.041354452 0.02952981  0.076994942
## [22,]  0.074413351 0.03074231  0.018656255  0.038365801 0.02968326  0.086015526
## [23,]  0.094017199 0.02968322  0.023844184  0.030580162 0.03326605  0.078032406
## [24,] -0.020068438 0.04245777  0.056291345  0.034540146 0.04248231 -0.027085805
## [25,]  0.004302624 0.03844368  0.037183135  0.041732370 0.03466866  0.024835794
## [26,]  0.101656141 0.03112301  0.043417633  0.015960018 0.04308705  0.032448594
## [27,] -0.054193657 0.04056137  0.011824827  0.071484715 0.01923648  0.072560006
## [28,]  0.059260544 0.02970169 -0.002969666  0.056012324 0.01845831  0.134814059
##               [,17]        [,18]      [,19]         [,20]        [,21]
##  [1,]  0.0370734074  0.018828731 0.03273391  0.0388694512  0.042869258
##  [2,]  0.0429822165  0.127095972 0.05069339  0.0274305131  0.004097741
##  [3,] -0.0889511386 -0.055476026 0.03000158 -0.0266072517  0.010217971
##  [4,] -0.0007934651  0.117905095 0.05257250  0.0023854029 -0.013636250
##  [5,] -0.0902019043 -0.064580147 0.02855067 -0.0260985986  0.013111951
##  [6,] -0.0047418214  0.119211194 0.05310532 -0.0001691798 -0.016056975
##  [7,] -0.0308937277  0.038539857 0.04143414 -0.0047213775  0.002265041
##  [8,]  0.0224305740  0.105511056 0.04863669  0.0180637318  0.002414552
##  [9,]  0.1091167118 -0.025703770 0.01948912  0.0883477595  0.095000886
## [10,] -0.0303933419 -0.022687627 0.03097547  0.0040573508  0.026057843
## [11,]  0.0051614107 -0.053967237 0.02285596  0.0297638473  0.055363580
## [12,]  0.0350993153  0.043285887 0.03705114  0.0342961623  0.032503259
## [13,]  0.0061629563  0.037814753 0.03839607  0.0176573254  0.020548455
## [14,]  0.0620183578  0.054277886 0.03680439  0.0489577484  0.041354452
## [15,]  0.0198268372  0.031724259 0.03628491  0.0267153091  0.029529810
## [16,]  0.1001004216  0.009720901 0.02622664  0.0780221114  0.076994942
## [17,]  0.1300805346  0.061944136 0.03275560  0.0888148916  0.071474795
## [18,]  0.0619441358  0.142754289 0.05186659  0.0366621903  0.007288065
## [19,]  0.0327555954  0.051866589 0.03869570  0.0316989973  0.028064168
## [20,]  0.0888148916  0.036662190 0.03169900  0.0675068637  0.061149386
## [21,]  0.0714747952  0.007288065 0.02806417  0.0611493859  0.064022505
## [22,]  0.0699846601 -0.015937990 0.02422891  0.0634695329  0.072231846
## [23,]  0.0483117525 -0.037426368 0.02227682  0.0534152853  0.069966743
## [24,] -0.0023627988  0.108811743 0.05114848  0.0027010431 -0.010901193
## [25,]  0.0428321544  0.073453853 0.04157672  0.0347678834  0.024656985
## [26,] -0.0096747090 -0.039863322 0.02642301  0.0188915364  0.042730507
## [27,]  0.1353834635  0.134232541 0.04464008  0.0819935313  0.046247299
## [28,]  0.1364587151 -0.005286509 0.02081303  0.1019585532  0.100432380
##              [,22]        [,23]        [,24]       [,25]        [,26]
##  [1,]  0.046795785  0.049159990  0.020683375 0.029627722  0.045957125
##  [2,] -0.016453301 -0.031976317  0.107748522 0.068299495 -0.024186192
##  [3,]  0.025116485  0.062513375  0.038586033 0.006041361  0.131363766
##  [4,] -0.034176830 -0.040107488  0.127909540 0.066064835 -0.005009656
##  [5,]  0.030032749  0.069074423  0.031744779 0.002807738  0.137492419
##  [6,] -0.037084885 -0.042481362  0.131519115 0.066628724 -0.004627675
##  [7,] -0.001563397  0.010426001  0.080493149 0.038340702  0.054282302
##  [8,] -0.014182062 -0.022524305  0.102725533 0.061058899 -0.004282485
##  [9,]  0.112553574  0.108380154 -0.062544710 0.011917293  0.052053680
## [10,]  0.036255555  0.057643753  0.028809795 0.016377910  0.092776002
## [11,]  0.074413351  0.094017199 -0.020068438 0.004302624  0.101656141
## [12,]  0.030742312  0.029683218  0.042457773 0.038443677  0.031123015
## [13,]  0.018656255  0.023844184  0.056291345 0.037183135  0.043417633
## [14,]  0.038365801  0.030580162  0.034540146 0.041732370  0.015960018
## [15,]  0.029683262  0.033266054  0.042482314 0.034668656  0.043087051
## [16,]  0.086015526  0.078032406 -0.027085805 0.024835794  0.032448594
## [17,]  0.069984660  0.048311752 -0.002362799 0.042832154 -0.009674709
## [18,] -0.015937990 -0.037426368  0.108811743 0.073453853 -0.039863322
## [19,]  0.024228909  0.022276821  0.051148484 0.041576717  0.026423007
## [20,]  0.063469533  0.053415285  0.002701043 0.034767883  0.018891536
## [21,]  0.072231846  0.069966743 -0.010901193 0.024656985  0.042730507
## [22,]  0.085681611  0.087295290 -0.029437172 0.016366305  0.057846015
## [23,]  0.087295290  0.096283976 -0.033665279 0.009187479  0.078031381
## [24,] -0.029437172 -0.033665279  0.121280149 0.062842789  0.001209535
## [25,]  0.016366305  0.009187479  0.062842789 0.049071888  0.009718390
## [26,]  0.057846015  0.078031381  0.001209535 0.009718390  0.097286845
## [27,]  0.028478725 -0.005390526  0.054904854 0.068619827 -0.056923180
## [28,]  0.114622088  0.102182001 -0.062824620 0.018574793  0.030812257
##              [,27]        [,28]
##  [1,]  0.024894119  0.049107526
##  [2,]  0.106830569 -0.018344158
##  [3,] -0.136094852 -0.058265546
##  [4,]  0.062708296 -0.067137968
##  [5,] -0.143632332 -0.053543393
##  [6,]  0.060244418 -0.073015914
##  [7,] -0.019487130 -0.050157972
##  [8,]  0.073855800 -0.029304812
##  [9,]  0.055154947  0.170679162
## [10,] -0.062524261 -0.007172212
## [11,] -0.054193657  0.059260544
## [12,]  0.040561374  0.029701695
## [13,]  0.011824827 -0.002969666
## [14,]  0.071484715  0.056012324
## [15,]  0.019236478  0.018458305
## [16,]  0.072560006  0.134814059
## [17,]  0.135383464  0.136458715
## [18,]  0.134232541 -0.005286509
## [19,]  0.044640084  0.020813034
## [20,]  0.081993531  0.101958553
## [21,]  0.046247299  0.100432380
## [22,]  0.028478725  0.114622088
## [23,] -0.005390526  0.102182001
## [24,]  0.054904854 -0.062824620
## [25,]  0.068619827  0.018574793
## [26,] -0.056923180  0.030812257
## [27,]  0.191257285  0.093132778
## [28,]  0.093132778  0.191002555
I-hat_matrix
##              [,1]         [,2]         [,3]          [,4]         [,5]
##  [1,]  0.96127842 -0.020353402 -0.043703757 -0.0192077090 -0.045201201
##  [2,] -0.02035340  0.883670388  0.024537978 -0.1156249931  0.032478890
##  [3,] -0.04370376  0.024537978  0.767546173 -0.0316058863 -0.239069414
##  [4,] -0.01920771 -0.115624993 -0.031605886  0.8646836245 -0.023983866
##  [5,] -0.04520120  0.032478890 -0.239069414 -0.0239838658  0.753529736
##  [6,] -0.01873486 -0.117474169 -0.035459619 -0.1390688923 -0.027678934
##  [7,] -0.03106173 -0.049701759 -0.111613292 -0.0812375029 -0.110622830
##  [8,] -0.02280440 -0.100527261 -0.011609002 -0.1088826723 -0.005333847
##  [9,] -0.05093199  0.031932552  0.014879599  0.0684251661  0.008669878
## [10,] -0.04168949  0.005235669 -0.145735253 -0.0242365221 -0.150125209
## [11,] -0.04932543  0.039373068 -0.122095665  0.0276228687 -0.129627791
## [12,] -0.03436545 -0.042603165 -0.032138186 -0.0431195135 -0.031466660
## [13,] -0.03350357 -0.042678654 -0.068907645 -0.0566950850 -0.068393874
## [14,] -0.03414575 -0.047820574  0.005413327 -0.0359541548  0.006749741
## [15,] -0.03541174 -0.034872312 -0.056461418 -0.0422550755 -0.056634598
## [16,] -0.04423755 -0.001353802  0.024467813  0.0298242231  0.021468335
## [17,] -0.03707341 -0.042982217  0.088951139  0.0007934651  0.090201904
## [18,] -0.01882873 -0.127095972  0.055476026 -0.1179050949  0.064580147
## [19,] -0.03273391 -0.050693393 -0.030001576 -0.0525724981 -0.028550672
## [20,] -0.03886945 -0.027430513  0.026607252 -0.0023854029  0.026098599
## [21,] -0.04286926 -0.004097741 -0.010217971  0.0136362497 -0.013111951
## [22,] -0.04679578  0.016453301 -0.025116485  0.0341768298 -0.030032749
## [23,] -0.04915999  0.031976317 -0.062513375  0.0401074883 -0.069074423
## [24,] -0.02068338 -0.107748522 -0.038586033 -0.1279095400 -0.031744779
## [25,] -0.02962772 -0.068299495 -0.006041361 -0.0660648345 -0.002807738
## [26,] -0.04595712  0.024186192 -0.131363766  0.0050096556 -0.137492419
## [27,] -0.02489412 -0.106830569  0.136094852 -0.0627082956  0.143632332
## [28,] -0.04910753  0.018344158  0.058265546  0.0671379676  0.053543393
##                [,6]         [,7]         [,8]         [,9]        [,10]
##  [1,] -0.0187348617 -0.031061733 -0.022804403 -0.050931992 -0.041689490
##  [2,] -0.1174741692 -0.049701759 -0.100527261  0.031932552  0.005235669
##  [3,] -0.0354596193 -0.111613292 -0.011609002  0.014879599 -0.145735253
##  [4,] -0.1390688923 -0.081237503 -0.108882672  0.068425166 -0.024236522
##  [5,] -0.0276789345 -0.110622830 -0.005333847  0.008669878 -0.150125209
##  [6,]  0.8569554717 -0.084538641 -0.111209280  0.073467951 -0.026038023
##  [7,] -0.0845386412  0.912705413 -0.060812388  0.033600806 -0.073812964
##  [8,] -0.1112092800 -0.060812388  0.908273559  0.034898966 -0.015530835
##  [9,]  0.0734679507  0.033600806  0.034898966  0.840075094 -0.017125304
## [10,] -0.0260380233 -0.073812964 -0.015530835 -0.017125304  0.901912764
## [11,]  0.0283008612 -0.039910749  0.019800002 -0.078545482 -0.089696977
## [12,] -0.0433318100 -0.037804756 -0.041505079 -0.028884996 -0.033038220
## [13,] -0.0581800753 -0.058779592 -0.047473242 -0.004267272 -0.052277327
## [14,] -0.0351247067 -0.019554897 -0.040301434 -0.046945037 -0.012771943
## [15,] -0.0429300839 -0.047019513 -0.038264586 -0.023006848 -0.046673180
## [16,]  0.0335757708  0.019121984  0.005684668 -0.121798272 -0.008220949
## [17,]  0.0047418214  0.030893728 -0.022430574 -0.109116712  0.030393342
## [18,] -0.1192111938 -0.038539857 -0.105511056  0.025703770  0.022687627
## [19,] -0.0531053175 -0.041434138 -0.048636685 -0.019489121 -0.030975471
## [20,]  0.0001691798  0.004721377 -0.018063732 -0.088347759 -0.004057351
## [21,]  0.0160569747 -0.002265041 -0.002414552 -0.095000886 -0.026057843
## [22,]  0.0370848853  0.001563397  0.014182062 -0.112553574 -0.036255555
## [23,]  0.0424813615 -0.010426001  0.022524305 -0.108380154 -0.057643753
## [24,] -0.1315191147 -0.080493149 -0.102725533  0.062544710 -0.028809795
## [25,] -0.0666287237 -0.038340702 -0.061058899 -0.011917293 -0.016377910
## [26,]  0.0046276745 -0.054282302  0.004282485 -0.052053680 -0.092776002
## [27,] -0.0602444183  0.019487130 -0.073855800 -0.055154947  0.062524261
## [28,]  0.0730159137  0.050157972  0.029304812 -0.170679162  0.007172212
##              [,11]       [,12]        [,13]        [,14]       [,15]
##  [1,] -0.049325430 -0.03436545 -0.033503566 -0.034145749 -0.03541174
##  [2,]  0.039373068 -0.04260317 -0.042678654 -0.047820574 -0.03487231
##  [3,] -0.122095665 -0.03213819 -0.068907645  0.005413327 -0.05646142
##  [4,]  0.027622869 -0.04311951 -0.056695085 -0.035954155 -0.04225508
##  [5,] -0.129627791 -0.03146666 -0.068393874  0.006749741 -0.05663460
##  [6,]  0.028300861 -0.04333181 -0.058180075 -0.035124707 -0.04293008
##  [7,] -0.039910749 -0.03780476 -0.058779592 -0.019554897 -0.04701951
##  [8,]  0.019800002 -0.04150508 -0.047473242 -0.040301434 -0.03826459
##  [9,] -0.078545482 -0.02888500 -0.004267272 -0.046945037 -0.02300685
## [10,] -0.089696977 -0.03303822 -0.052277327 -0.012771943 -0.04667318
## [11,]  0.888311195 -0.02961149 -0.036886792 -0.018039332 -0.04051140
## [12,] -0.029611493  0.96368073 -0.036707479 -0.036416260 -0.03585089
## [13,] -0.036886792 -0.03670748  0.953964984 -0.028640538 -0.04073358
## [14,] -0.018039332 -0.03641626 -0.028640538  0.955684302 -0.03133380
## [15,] -0.040511402 -0.03585089 -0.040733583 -0.031333804  0.96160909
## [16,] -0.050591555 -0.03188795 -0.011012984 -0.048710568 -0.02468682
## [17,] -0.005161411 -0.03509932 -0.006162956 -0.062018358 -0.01982684
## [18,]  0.053967237 -0.04328589 -0.037814753 -0.054277886 -0.03172426
## [19,] -0.022855965 -0.03705114 -0.038396073 -0.036804391 -0.03628491
## [20,] -0.029763847 -0.03429616 -0.017657325 -0.048957748 -0.02671531
## [21,] -0.055363580 -0.03250326 -0.020548455 -0.041354452 -0.02952981
## [22,] -0.074413351 -0.03074231 -0.018656255 -0.038365801 -0.02968326
## [23,] -0.094017199 -0.02968322 -0.023844184 -0.030580162 -0.03326605
## [24,]  0.020068438 -0.04245777 -0.056291345 -0.034540146 -0.04248231
## [25,] -0.004302624 -0.03844368 -0.037183135 -0.041732370 -0.03466866
## [26,] -0.101656141 -0.03112301 -0.043417633 -0.015960018 -0.04308705
## [27,]  0.054193657 -0.04056137 -0.011824827 -0.071484715 -0.01923648
## [28,] -0.059260544 -0.02970169  0.002969666 -0.056012324 -0.01845831
##              [,16]         [,17]        [,18]       [,19]         [,20]
##  [1,] -0.044237546 -0.0370734074 -0.018828731 -0.03273391 -0.0388694512
##  [2,] -0.001353802 -0.0429822165 -0.127095972 -0.05069339 -0.0274305131
##  [3,]  0.024467813  0.0889511386  0.055476026 -0.03000158  0.0266072517
##  [4,]  0.029824223  0.0007934651 -0.117905095 -0.05257250 -0.0023854029
##  [5,]  0.021468335  0.0902019043  0.064580147 -0.02855067  0.0260985986
##  [6,]  0.033575771  0.0047418214 -0.119211194 -0.05310532  0.0001691798
##  [7,]  0.019121984  0.0308937277 -0.038539857 -0.04143414  0.0047213775
##  [8,]  0.005684668 -0.0224305740 -0.105511056 -0.04863669 -0.0180637318
##  [9,] -0.121798272 -0.1091167118  0.025703770 -0.01948912 -0.0883477595
## [10,] -0.008220949  0.0303933419  0.022687627 -0.03097547 -0.0040573508
## [11,] -0.050591555 -0.0051614107  0.053967237 -0.02285596 -0.0297638473
## [12,] -0.031887946 -0.0350993153 -0.043285887 -0.03705114 -0.0342961623
## [13,] -0.011012984 -0.0061629563 -0.037814753 -0.03839607 -0.0176573254
## [14,] -0.048710568 -0.0620183578 -0.054277886 -0.03680439 -0.0489577484
## [15,] -0.024686824 -0.0198268372 -0.031724259 -0.03628491 -0.0267153091
## [16,]  0.901043250 -0.1001004216 -0.009720901 -0.02622664 -0.0780221114
## [17,] -0.100100422  0.8699194654 -0.061944136 -0.03275560 -0.0888148916
## [18,] -0.009720901 -0.0619441358  0.857245711 -0.05186659 -0.0366621903
## [19,] -0.026226641 -0.0327555954 -0.051866589  0.96130430 -0.0316989973
## [20,] -0.078022111 -0.0888148916 -0.036662190 -0.03169900  0.9324931363
## [21,] -0.076994942 -0.0714747952 -0.007288065 -0.02806417 -0.0611493859
## [22,] -0.086015526 -0.0699846601  0.015937990 -0.02422891 -0.0634695329
## [23,] -0.078032406 -0.0483117525  0.037426368 -0.02227682 -0.0534152853
## [24,]  0.027085805  0.0023627988 -0.108811743 -0.05114848 -0.0027010431
## [25,] -0.024835794 -0.0428321544 -0.073453853 -0.04157672 -0.0347678834
## [26,] -0.032448594  0.0096747090  0.039863322 -0.02642301 -0.0188915364
## [27,] -0.072560006 -0.1353834635 -0.134232541 -0.04464008 -0.0819935313
## [28,] -0.134814059 -0.1364587151  0.005286509 -0.02081303 -0.1019585532
##              [,21]        [,22]        [,23]        [,24]        [,25]
##  [1,] -0.042869258 -0.046795785 -0.049159990 -0.020683375 -0.029627722
##  [2,] -0.004097741  0.016453301  0.031976317 -0.107748522 -0.068299495
##  [3,] -0.010217971 -0.025116485 -0.062513375 -0.038586033 -0.006041361
##  [4,]  0.013636250  0.034176830  0.040107488 -0.127909540 -0.066064835
##  [5,] -0.013111951 -0.030032749 -0.069074423 -0.031744779 -0.002807738
##  [6,]  0.016056975  0.037084885  0.042481362 -0.131519115 -0.066628724
##  [7,] -0.002265041  0.001563397 -0.010426001 -0.080493149 -0.038340702
##  [8,] -0.002414552  0.014182062  0.022524305 -0.102725533 -0.061058899
##  [9,] -0.095000886 -0.112553574 -0.108380154  0.062544710 -0.011917293
## [10,] -0.026057843 -0.036255555 -0.057643753 -0.028809795 -0.016377910
## [11,] -0.055363580 -0.074413351 -0.094017199  0.020068438 -0.004302624
## [12,] -0.032503259 -0.030742312 -0.029683218 -0.042457773 -0.038443677
## [13,] -0.020548455 -0.018656255 -0.023844184 -0.056291345 -0.037183135
## [14,] -0.041354452 -0.038365801 -0.030580162 -0.034540146 -0.041732370
## [15,] -0.029529810 -0.029683262 -0.033266054 -0.042482314 -0.034668656
## [16,] -0.076994942 -0.086015526 -0.078032406  0.027085805 -0.024835794
## [17,] -0.071474795 -0.069984660 -0.048311752  0.002362799 -0.042832154
## [18,] -0.007288065  0.015937990  0.037426368 -0.108811743 -0.073453853
## [19,] -0.028064168 -0.024228909 -0.022276821 -0.051148484 -0.041576717
## [20,] -0.061149386 -0.063469533 -0.053415285 -0.002701043 -0.034767883
## [21,]  0.935977495 -0.072231846 -0.069966743  0.010901193 -0.024656985
## [22,] -0.072231846  0.914318389 -0.087295290  0.029437172 -0.016366305
## [23,] -0.069966743 -0.087295290  0.903716024  0.033665279 -0.009187479
## [24,]  0.010901193  0.029437172  0.033665279  0.878719851 -0.062842789
## [25,] -0.024656985 -0.016366305 -0.009187479 -0.062842789  0.950928112
## [26,] -0.042730507 -0.057846015 -0.078031381 -0.001209535 -0.009718390
## [27,] -0.046247299 -0.028478725  0.005390526 -0.054904854 -0.068619827
## [28,] -0.100432380 -0.114622088 -0.102182001  0.062824620 -0.018574793
##              [,26]        [,27]        [,28]
##  [1,] -0.045957125 -0.024894119 -0.049107526
##  [2,]  0.024186192 -0.106830569  0.018344158
##  [3,] -0.131363766  0.136094852  0.058265546
##  [4,]  0.005009656 -0.062708296  0.067137968
##  [5,] -0.137492419  0.143632332  0.053543393
##  [6,]  0.004627675 -0.060244418  0.073015914
##  [7,] -0.054282302  0.019487130  0.050157972
##  [8,]  0.004282485 -0.073855800  0.029304812
##  [9,] -0.052053680 -0.055154947 -0.170679162
## [10,] -0.092776002  0.062524261  0.007172212
## [11,] -0.101656141  0.054193657 -0.059260544
## [12,] -0.031123015 -0.040561374 -0.029701695
## [13,] -0.043417633 -0.011824827  0.002969666
## [14,] -0.015960018 -0.071484715 -0.056012324
## [15,] -0.043087051 -0.019236478 -0.018458305
## [16,] -0.032448594 -0.072560006 -0.134814059
## [17,]  0.009674709 -0.135383464 -0.136458715
## [18,]  0.039863322 -0.134232541  0.005286509
## [19,] -0.026423007 -0.044640084 -0.020813034
## [20,] -0.018891536 -0.081993531 -0.101958553
## [21,] -0.042730507 -0.046247299 -0.100432380
## [22,] -0.057846015 -0.028478725 -0.114622088
## [23,] -0.078031381  0.005390526 -0.102182001
## [24,] -0.001209535 -0.054904854  0.062824620
## [25,] -0.009718390 -0.068619827 -0.018574793
## [26,]  0.902713155  0.056923180 -0.030812257
## [27,]  0.056923180  0.808742715 -0.093132778
## [28,] -0.030812257 -0.093132778  0.808997445
round(hat_matrix%*%(I-hat_matrix), 2)
##       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
##  [1,]    0    0    0    0    0    0    0    0    0     0     0     0     0
##  [2,]    0    0    0    0    0    0    0    0    0     0     0     0     0
##  [3,]    0    0    0    0    0    0    0    0    0     0     0     0     0
##  [4,]    0    0    0    0    0    0    0    0    0     0     0     0     0
##  [5,]    0    0    0    0    0    0    0    0    0     0     0     0     0
##  [6,]    0    0    0    0    0    0    0    0    0     0     0     0     0
##  [7,]    0    0    0    0    0    0    0    0    0     0     0     0     0
##  [8,]    0    0    0    0    0    0    0    0    0     0     0     0     0
##  [9,]    0    0    0    0    0    0    0    0    0     0     0     0     0
## [10,]    0    0    0    0    0    0    0    0    0     0     0     0     0
## [11,]    0    0    0    0    0    0    0    0    0     0     0     0     0
## [12,]    0    0    0    0    0    0    0    0    0     0     0     0     0
## [13,]    0    0    0    0    0    0    0    0    0     0     0     0     0
## [14,]    0    0    0    0    0    0    0    0    0     0     0     0     0
## [15,]    0    0    0    0    0    0    0    0    0     0     0     0     0
## [16,]    0    0    0    0    0    0    0    0    0     0     0     0     0
## [17,]    0    0    0    0    0    0    0    0    0     0     0     0     0
## [18,]    0    0    0    0    0    0    0    0    0     0     0     0     0
## [19,]    0    0    0    0    0    0    0    0    0     0     0     0     0
## [20,]    0    0    0    0    0    0    0    0    0     0     0     0     0
## [21,]    0    0    0    0    0    0    0    0    0     0     0     0     0
## [22,]    0    0    0    0    0    0    0    0    0     0     0     0     0
## [23,]    0    0    0    0    0    0    0    0    0     0     0     0     0
## [24,]    0    0    0    0    0    0    0    0    0     0     0     0     0
## [25,]    0    0    0    0    0    0    0    0    0     0     0     0     0
## [26,]    0    0    0    0    0    0    0    0    0     0     0     0     0
## [27,]    0    0    0    0    0    0    0    0    0     0     0     0     0
## [28,]    0    0    0    0    0    0    0    0    0     0     0     0     0
##       [,14] [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] [,24] [,25]
##  [1,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [2,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [3,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [4,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [5,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [6,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [7,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [8,]     0     0     0     0     0     0     0     0     0     0     0     0
##  [9,]     0     0     0     0     0     0     0     0     0     0     0     0
## [10,]     0     0     0     0     0     0     0     0     0     0     0     0
## [11,]     0     0     0     0     0     0     0     0     0     0     0     0
## [12,]     0     0     0     0     0     0     0     0     0     0     0     0
## [13,]     0     0     0     0     0     0     0     0     0     0     0     0
## [14,]     0     0     0     0     0     0     0     0     0     0     0     0
## [15,]     0     0     0     0     0     0     0     0     0     0     0     0
## [16,]     0     0     0     0     0     0     0     0     0     0     0     0
## [17,]     0     0     0     0     0     0     0     0     0     0     0     0
## [18,]     0     0     0     0     0     0     0     0     0     0     0     0
## [19,]     0     0     0     0     0     0     0     0     0     0     0     0
## [20,]     0     0     0     0     0     0     0     0     0     0     0     0
## [21,]     0     0     0     0     0     0     0     0     0     0     0     0
## [22,]     0     0     0     0     0     0     0     0     0     0     0     0
## [23,]     0     0     0     0     0     0     0     0     0     0     0     0
## [24,]     0     0     0     0     0     0     0     0     0     0     0     0
## [25,]     0     0     0     0     0     0     0     0     0     0     0     0
## [26,]     0     0     0     0     0     0     0     0     0     0     0     0
## [27,]     0     0     0     0     0     0     0     0     0     0     0     0
## [28,]     0     0     0     0     0     0     0     0     0     0     0     0
##       [,26] [,27] [,28]
##  [1,]     0     0     0
##  [2,]     0     0     0
##  [3,]     0     0     0
##  [4,]     0     0     0
##  [5,]     0     0     0
##  [6,]     0     0     0
##  [7,]     0     0     0
##  [8,]     0     0     0
##  [9,]     0     0     0
## [10,]     0     0     0
## [11,]     0     0     0
## [12,]     0     0     0
## [13,]     0     0     0
## [14,]     0     0     0
## [15,]     0     0     0
## [16,]     0     0     0
## [17,]     0     0     0
## [18,]     0     0     0
## [19,]     0     0     0
## [20,]     0     0     0
## [21,]     0     0     0
## [22,]     0     0     0
## [23,]     0     0     0
## [24,]     0     0     0
## [25,]     0     0     0
## [26,]     0     0     0
## [27,]     0     0     0
## [28,]     0     0     0

d) Construct the ANOVA table and test for significance of regression given the normality assumption.

betaMat<-solve(t(design_matrix)%*%design_matrix)%*%t(design_matrix)%*%response_matrix

hat_matrix<-design_matrix%*%solve(t(design_matrix)%*%design_matrix)%*%t(design_matrix)

y_hat_matrix<-design_matrix%*%betaMat

error_vector<-response_matrix-y_hat_matrix

n<-dim(nfl)[1]

p<-2

ms_res<-sum(error_vector^2)/(n-p-1)

ss_res<-t(response_matrix)%*%(I-hat_matrix)%*%response_matrix

ones<-matrix(c(rep(1, dim(nfl)[1])), 
             nrow=dim(nfl)[1])

J<-ones%*%t(ones)

ss_tot<-t(response_matrix)%*%(I-(J/n))%*%response_matrix

ss_reg<-t(response_matrix)%*%(hat_matrix-(J/n))%*%response_matrix

ms_res<-ss_res/(n-p-1)

ms_reg<-ss_reg/p

f_stat<-ms_reg/ms_res

p_value<-pf(f_stat, p, n-p-1, lower.tail = FALSE)

# SS(Res)
ss_res
##          [,1]
## [1,] 128.5531
# SS(Reg)
ss_reg
##          [,1]
## [1,] 198.4112
# MS(Res)
ms_res
##          [,1]
## [1,] 5.142124
# MS(Reg)
ms_reg
##         [,1]
## [1,] 99.2056
# F Statistic
f_stat
##          [,1]
## [1,] 19.29273
# P Value
p_value
##              [,1]
## [1,] 8.556137e-06
# Regression Degrees of Freedom
p
## [1] 2
# Residual Degrees of Freedom
n-p-1
## [1] 25

Verifying:

anova(mlr)
## Analysis of Variance Table
## 
## Response: nfl$y
##           Df  Sum Sq Mean Sq F value    Pr(>F)    
## nfl$x1     1 115.068 115.068  22.378 7.492e-05 ***
## nfl$x2     1  83.343  83.343  16.208 0.0004635 ***
## Residuals 25 128.553   5.142                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(mlr)
## 
## Call:
## lm(formula = nfl$y ~ nfl$x1 + nfl$x2, data = nfl)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -6.4613 -1.4362  0.0489  1.6283  3.5213 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -1.218e+01  3.112e+00  -3.913 0.000619 ***
## nfl$x1       5.520e-03  1.132e-03   4.875 5.15e-05 ***
## nfl$x2       3.522e-03  8.749e-04   4.026 0.000464 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.268 on 25 degrees of freedom
## Multiple R-squared:  0.6068, Adjusted R-squared:  0.5754 
## F-statistic: 19.29 on 2 and 25 DF,  p-value: 8.556e-06

e) Report a good estimate of the nuisance parameter σ.

# Old estimate is sqrt(ms_res)
sqrt(ms_res)
##          [,1]
## [1,] 2.267625
# New estimate is sqrt(diag(covMat))

f) Create the covariance matrix for beta hat. Print it.

ms_res<-sum(error_vector^2)/(n-p-1)

covMat<-ms_res*solve(t(design_matrix)%*%design_matrix)

covMat
##              [,1]          [,2]          [,3]
## [1,]  9.682627559 -2.782428e-03 -1.705263e-03
## [2,] -0.002782428  1.281857e-06  3.640215e-08
## [3,] -0.001705263  3.640215e-08  7.655303e-07

g) Report the standard errors of beta_not_hat, beta_one_hat, and beta_two_hat.

se_bj<-sqrt(diag(covMat))

# beta 0 hat standard error
beta0_se<-se_bj[1]
beta0_se
## [1] 3.111692
# beta 1 hat standard error
beta1_se<-se_bj[2]
beta1_se
## [1] 0.001132191
# beta 2 hat standard error
beta2_se<-se_bj[3]
beta2_se
## [1] 0.0008749459

h) Based on the sample, give an estimate of the covariance between beta_one_hat and beta_two_hat.

covMat[2]-covMat[3]
## [1] -0.001077165

i) Perform t-tests for the slope parameters. Report their test statistics, reference distribution, degrees of freedom, and p-value.

# Test Statistics for beta_0, beta_1, and beta_2
t_test<-betaMat/se_bj
t_test
##           [,1]
## [1,] -3.913135
## [2,]  4.875239
## [3,]  4.025902
# R-Squared
r_squared<-ss_reg/ss_tot
r_squared
##           [,1]
## [1,] 0.6068283
# P-Value(s)
n<-dim(nfl)[1]
p<-2
pt(abs(t_test), df= n-p-1, lower.tail = FALSE)*2
##              [,1]
## [1,] 6.190716e-04
## [2,] 5.148197e-05
## [3,] 4.635451e-04

These tests use an F distribution, with n-p-1 and p degrees of freedom (this would be 25), and a p-value of 6.190716e-04, 5.148197e-05, and 4.635451e-04 for the intercept, x1, and x2, respectively.

j) Interpret each of these tests on the context of the data.

# Rejection Region
qf(0.05/2, df1=n-p-1, df2=p, lower.tail = FALSE)
## [1] 39.4579

Based on these tests, the test statistics do not exceed the rejection region. However, their p-values do indicate there is some significance.