RStudio Required Question 1: Load the \"gala\" data from the \"faraway\" package
ID: 3073550 • Letter: R
Question
RStudio Required
Question 1: Load the "gala" data from the "faraway" package. The goal is to predict the num- ber of plant species found on the island (Species) using five other predictors (Area, Elevation Nearest, Scruz, and Adjacent). You can read either the R document of the "faravay" package or the JF text book page 18 to get more information. For this question, you are NOT allowed to use the 1mC) function. Make sure that your R output is simplified so that you don't produce an extremely long report. In R markdown, To prevent a chunk of R code from printing the result, you can specify ‘ "(r, eval=FALSE) as demonstrated in the Rintro file. n)t Xx pn definite. b). (1 point) Calculate the regression coefficients c). (1 point) Construct the "hat matrix" H and utilize it in the calculation of the residuals. From the residuals, calculate SSE and 2 d). (1 point) Calculate the R2Explanation / Answer
rm(list=ls(all=TRUE))
> library(faraway)
> gala
Species Endemics Area Elevation Nearest Scruz Adjacent
Baltra 58 23 25.09 346 0.6 0.6 1.84
Bartolome 31 21 1.24 109 0.6 26.3 572.33
Caldwell 3 3 0.21 114 2.8 58.7 0.78
Champion 25 9 0.10 46 1.9 47.4 0.18
Coamano 2 1 0.05 77 1.9 1.9 903.82
Daphne.Major 18 11 0.34 119 8.0 8.0 1.84
Daphne.Minor 24 0 0.08 93 6.0 12.0 0.34
Darwin 10 7 2.33 168 34.1 290.2 2.85
Eden 8 4 0.03 71 0.4 0.4 17.95
Enderby 2 2 0.18 112 2.6 50.2 0.10
Espanola 97 26 58.27 198 1.1 88.3 0.57
Fernandina 93 35 634.49 1494 4.3 95.3 4669.32
Gardner1 58 17 0.57 49 1.1 93.1 58.27
Gardner2 5 4 0.78 227 4.6 62.2 0.21
Genovesa 40 19 17.35 76 47.4 92.2 129.49
Isabela 347 89 4669.32 1707 0.7 28.1 634.49
Marchena 51 23 129.49 343 29.1 85.9 59.56
Onslow 2 2 0.01 25 3.3 45.9 0.10
Pinta 104 37 59.56 777 29.1 119.6 129.49
Pinzon 108 33 17.95 458 10.7 10.7 0.03
Las.Plazas 12 9 0.23 94 0.5 0.6 25.09
Rabida 70 30 4.89 367 4.4 24.4 572.33
SanCristobal 280 65 551.62 716 45.2 66.6 0.57
SanSalvador 237 81 572.33 906 0.2 19.8 4.89
SantaCruz 444 95 903.82 864 0.6 0.0 0.52
SantaFe 62 28 24.08 259 16.5 16.5 0.52
SantaMaria 285 73 170.92 640 2.6 49.2 0.10
Seymour 44 16 1.84 147 0.6 9.6 25.09
Tortuga 16 8 1.24 186 6.8 50.9 17.95
Wolf 21 12 2.85 253 34.1 254.7 2.33
> y=gala$Species;y #response variable
[1] 58 31 3 25 2 18 24 10 8 2 97 93 58 5 40 347 51 2 104 108 12 70
[23] 280 237 444 62 285 44 16 21
> n=length(y);n
[1] 30
> x0=rep(1,30);x0
[1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
> x1=gala$Area
> x2=gala$Elevation
> x3=gala$Nearest
> x4=gala$Scruz
> x5=gala$Adjacent
> #design matrix X with intercept
> x=matrix(c(x0,x1,x2,x3,x4,x5),30,6);x
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 1 25.09 346 0.6 0.6 1.84
[2,] 1 1.24 109 0.6 26.3 572.33
[3,] 1 0.21 114 2.8 58.7 0.78
[4,] 1 0.10 46 1.9 47.4 0.18
[5,] 1 0.05 77 1.9 1.9 903.82
[6,] 1 0.34 119 8.0 8.0 1.84
[7,] 1 0.08 93 6.0 12.0 0.34
[8,] 1 2.33 168 34.1 290.2 2.85
[9,] 1 0.03 71 0.4 0.4 17.95
[10,] 1 0.18 112 2.6 50.2 0.10
[11,] 1 58.27 198 1.1 88.3 0.57
[12,] 1 634.49 1494 4.3 95.3 4669.32
[13,] 1 0.57 49 1.1 93.1 58.27
[14,] 1 0.78 227 4.6 62.2 0.21
[15,] 1 17.35 76 47.4 92.2 129.49
[16,] 1 4669.32 1707 0.7 28.1 634.49
[17,] 1 129.49 343 29.1 85.9 59.56
[18,] 1 0.01 25 3.3 45.9 0.10
[19,] 1 59.56 777 29.1 119.6 129.49
[20,] 1 17.95 458 10.7 10.7 0.03
[21,] 1 0.23 94 0.5 0.6 25.09
[22,] 1 4.89 367 4.4 24.4 572.33
[23,] 1 551.62 716 45.2 66.6 0.57
[24,] 1 572.33 906 0.2 19.8 4.89
[25,] 1 903.82 864 0.6 0.0 0.52
[26,] 1 24.08 259 16.5 16.5 0.52
[27,] 1 170.92 640 2.6 49.2 0.10
[28,] 1 1.84 147 0.6 9.6 25.09
[29,] 1 1.24 186 6.8 50.9 17.95
[30,] 1 2.85 253 34.1 254.7 2.33
> p=6
> pd=t(x)%*%x;pd
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 30.00 7851.26 11041.0 301.80 1709.30 7832.95
[2,] 7851.26 23708665.46 10852798.5 39240.84 275516.84 5950313.65
[3,] 11041.00 10852798.53 9218227.0 109139.20 616237.80 8553187.95
[4,] 301.80 39240.84 109139.2 8945.30 34527.34 37196.67
[5,] 1709.30 275516.84 616237.8 34527.34 231613.77 534409.98
[6,] 7832.95 5950313.65 8553187.9 37196.67 534409.98 23719568.46
> eigen(pd)
$values
[1] 3.659801e+07 1.787397e+07 2.243836e+06 1.679281e+05 3.293730e+03 1.013371e+01
$vectors
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] -0.0004070598 -6.565549e-06 -0.002253151 -0.003779895 0.001827127 0.9999885657
[2,] -0.6578883570 6.498814e-01 0.377036883 -0.051574948 0.004486495 0.0003828472
[3,] -0.4498348101 6.597096e-02 -0.878358151 0.147036209 -0.012699699 -0.0015827832
[4,] -0.0026812736 2.339028e-04 -0.034471516 -0.128656732 0.991083382 -0.0023759306
[5,] -0.0214797443 -1.047954e-02 -0.151781563 -0.979199426 -0.132458010 -0.0038100959
[6,] -0.6036247336 -7.570945e-01 0.249196996 -0.017944910 0.004884175 0.0002340453
> #Here XtX is a symmetric matrix and the eigne values are postive .So XtX is positive definite
> xty=t(x)%*%y;xty
[,1]
[1,] 2557.0
[2,] 2444013.2
[3,] 1976099.0
[4,] 25054.6
[5,] 106983.1
[6,] 742829.8
> xtxinverse=solve(pd);xtxinverse
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 9.867829e-02 3.778242e-05 -1.561976e-04 -2.339027e-04 -3.760293e-04 2.309832e-05
[2,] 3.778242e-05 1.352247e-07 -2.593617e-07 1.294003e-06 -4.913149e-08 4.620303e-08
[3,] -1.561976e-04 -2.593617e-07 7.745339e-07 -3.549366e-06 3.080831e-07 -1.640241e-07
[4,] -2.339027e-04 1.294003e-06 -3.549366e-06 2.988732e-04 -3.821077e-05 1.424729e-06
[5,] -3.760293e-04 -4.913149e-08 3.080831e-07 -3.821077e-05 1.247941e-05 -1.958356e-07
[6,] 2.309832e-05 4.620303e-08 -1.640241e-07 1.424729e-06 -1.958356e-07 8.426543e-08
> b=xtxinverse%*%xty;b
[,1]
[1,] 7.068220709
[2,] -0.023938338
[3,] 0.319464761
[4,] 0.009143961
[5,] -0.240524230
[6,] -0.074804832
> h=x%*%xtxinverse%*%t(x);h #hat matrix
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 0.07871937 0.030046980 0.036597135 0.033995316 2.166880e-02 0.044989777
[2,] 0.03004698 0.091353235 0.056168898 0.069268961 1.155680e-01 0.059722906
[3,] 0.03659714 0.056168898 0.062314427 0.065015280 4.747372e-02 0.036964513
[4,] 0.03399532 0.069268961 0.065015280 0.072376765 6.986545e-02 0.047974532
[5,] 0.02166880 0.115568041 0.047473720 0.069865454 1.687837e-01 0.082270132
[6,] 0.04498978 0.059722906 0.036964513 0.047974532 8.227013e-02 0.071637899
[7,] 0.04376576 0.064461309 0.043749546 0.054794511 8.378158e-02 0.068915612
[8,] -0.06408858 -0.006558534 0.060993396 0.044015503 -5.968361e-02 -0.049331245
[9,] 0.05138259 0.074102594 0.053156692 0.064795655 9.042923e-02 0.069450832
[10,] 0.03910303 0.057849373 0.060426662 0.064227214 5.257285e-02 0.041486608
[11,] 0.03616807 0.041436482 0.069698186 0.064487048 1.068569e-02 0.011775742
[12,] -0.01141441 0.081282022 -0.021482704 -0.028815595 1.365081e-01 -0.031343661
[13,] 0.02037118 0.065344307 0.079298996 0.081061534 4.686534e-02 0.022421046
[14,] 0.04494162 0.036425903 0.052866214 0.049879887 1.937056e-02 0.027425274
[15,] -0.03846472 0.036120440 -0.017243516 0.003015155 1.070553e-01 0.088030804
[16,] -0.03072350 0.004621363 0.002609610 0.011134084 8.275937e-03 -0.005252051
[17,] 0.01095834 0.006411174 0.003576389 0.004218613 2.106413e-02 0.042095499
[18,] 0.03048936 0.071964605 0.062986080 0.072210067 7.777675e-02 0.052692539
[19,] 0.04715056 -0.067108507 -0.013691893 -0.040618917 -1.054559e-01 -0.015741882
[20,] 0.07493222 0.003919105 0.012061472 0.006184427 1.894630e-06 0.043678273
[21,] 0.05333291 0.070688314 0.051610872 0.062138892 8.531628e-02 0.067507282
[22,] 0.05217274 0.048095762 0.032433143 0.033739661 5.698846e-02 0.042953670
[23,] 0.01618007 -0.048391388 -0.053181340 -0.056833256 -1.995102e-02 0.048360679
[24,] 0.10521102 -0.042531039 0.014238024 -0.011224683 -9.632178e-02 -0.007304476
[25,] 0.09036268 -0.021518127 0.013308244 -0.001673163 -5.367739e-02 0.013444520
[26,] 0.04508936 0.031484662 0.013841704 0.020186561 5.441604e-02 0.066910134
[27,] 0.08564336 -0.020400646 0.030035379 0.008970007 -6.878930e-02 -0.002767701
[28,] 0.05601181 0.060859025 0.050804734 0.057453426 6.703796e-02 0.057979055
[29,] 0.04057647 0.044177721 0.047564166 0.049292177 4.060787e-02 0.040694123
[30,] -0.04516931 -0.014864940 0.045805971 0.028864884 -6.050474e-02 -0.037640434
[,7] [,8] [,9] [,10] [,11] [,12]
[1,] 0.0437657622 -0.064088576 0.051382589 0.039103030 0.036168073 -0.011414414
[2,] 0.0644613091 -0.006558534 0.074102594 0.057849373 0.041436482 0.081282022
[3,] 0.0437495459 0.060993396 0.053156692 0.060426662 0.069698186 -0.021482704
[4,] 0.0547945114 0.044015503 0.064795655 0.064227214 0.064487048 -0.028815595
[5,] 0.0837815769 -0.059683614 0.090429228 0.052572849 0.010685689 0.136508065
[6,] 0.0689156123 -0.049331245 0.069450832 0.041486608 0.011775742 -0.031343661
[7,] 0.0682865118 -0.036375924 0.071407274 0.047417930 0.022453955 -0.032320249
[8,] -0.0363759242 0.465517265 -0.048793668 0.044517125 0.119417643 0.008129048
[9,] 0.0714072738 -0.048793668 0.080225388 0.056556734 0.035210996 -0.030412892
[10,] 0.0474179302 0.044517125 0.056556734 0.059330985 0.064178163 -0.023085561
[11,] 0.0224539548 0.119417643 0.035210996 0.064178163 0.098245833 -0.011603719
[12,] -0.0323202486 0.008129048 -0.030412892 -0.023085561 -0.011603719 0.949673245
[13,] 0.0351872887 0.135616328 0.048739640 0.073859734 0.100228954 -0.009832660
[14,] 0.0321392953 0.058253822 0.039315762 0.050742410 0.065865990 -0.012238238
[15,] 0.0698856825 0.052116090 0.031045170 -0.010003378 -0.082868184 -0.014499224
[16,] -0.0007091869 0.016646452 0.002350385 0.001903810 0.009332430 0.007709218
[17,] 0.0326242441 0.058959450 0.013102492 0.005543695 -0.014063322 -0.003732930
[18,] 0.0586504478 0.039849739 0.067060759 0.062795858 0.057798450 -0.031435899
[19,] -0.0264382650 0.098055907 -0.045571409 -0.016436530 0.012254581 0.054976326
[20,] 0.0356629367 -0.068063995 0.032087219 0.015925032 0.004903598 -0.004524818
[21,] 0.0691613205 -0.050002146 0.077790976 0.054953357 0.034928235 -0.027141150
[22,] 0.0420044888 -0.031958079 0.046317177 0.034472755 0.026509132 0.101034205
[23,] 0.0232721448 -0.018055847 -0.016918483 -0.046011679 -0.091607308 -0.013152432
[24,] -0.0103118578 -0.044654849 -0.003225864 0.013223107 0.050152838 0.013974377
[25,] 0.0095821040 -0.074164127 0.015149232 0.014706127 0.030933834 -0.009484868
[26,] 0.0580614080 -0.054638383 0.049006918 0.019373109 -0.014555455 -0.023043624
[27,] -0.0023654001 0.015677359 0.004779036 0.027385471 0.064744889 0.013351559
[28,] 0.0600317936 -0.035307439 0.068887943 0.053108189 0.041479333 -0.021302132
[29,] 0.0430956013 0.034143358 0.047262389 0.047320963 0.048273937 -0.015160674
[30,] -0.0298718620 0.389767939 -0.044690763 0.032556858 0.093533979 0.009389376
[,13] [,14] [,15] [,16] [,17] [,18]
[1,] 0.020371183 0.044941620 -0.038464716 -0.0307235041 0.0109583370 0.030489359
[2,] 0.065344307 0.036425903 0.036120440 0.0046213627 0.0064111741 0.071964605
[3,] 0.079298996 0.052866214 -0.017243516 0.0026096097 0.0035763890 0.062986080
[4,] 0.081061534 0.049879887 0.003015155 0.0111340844 0.0042186133 0.072210067
[5,] 0.046865341 0.019370561 0.107055263 0.0082759367 0.0210641306 0.077776746
[6,] 0.022421046 0.027425274 0.088030804 -0.0052520505 0.0420954994 0.052692539
[7,] 0.035187289 0.032139295 0.069885683 -0.0007091869 0.0326242441 0.058650448
[8,] 0.135616328 0.058253822 0.052116090 0.0166464515 0.0589594500 0.039849739
[9,] 0.048739640 0.039315762 0.031045170 0.0023503854 0.0131024922 0.067060759
[10,] 0.073859734 0.050742410 -0.010003378 0.0019038097 0.0055436948 0.062795858
[11,] 0.100228954 0.065865990 -0.082868184 0.0093324296 -0.0140633216 0.057798450
[12,] -0.009832660 -0.012238238 -0.014499224 0.0077092180 -0.0037329301 -0.031435899
[13,] 0.117956891 0.063873745 -0.049341071 0.0169371219 -0.0140461242 0.077130710
[14,] 0.063873745 0.052735679 -0.031959172 -0.0133689781 0.0088059319 0.046118775
[15,] -0.049341071 -0.031959172 0.430065941 0.0080340168 0.1813790769 0.024567669
[16,] 0.016937122 -0.013368978 0.008034017 0.9685320732 0.0010400066 0.013637975
[17,] -0.014046124 0.008805932 0.181379077 0.0010400066 0.1035450235 0.010837954
[18,] 0.077130710 0.046118775 0.024567669 0.0136379750 0.0108379540 0.073385171
[19,] -0.035128420 0.028252930 0.031453021 -0.0742853614 0.0878296621 -0.046162454
[20,] -0.019700015 0.029961322 0.025370593 -0.0494963594 0.0490017742 0.004950906
[21,] 0.046189613 0.039537335 0.026354555 -0.0008291358 0.0132303136 0.063987406
[22,] 0.023895392 0.033780944 0.009886985 -0.0323737732 0.0203021036 0.033113364
[23,] -0.113927074 -0.027902406 0.300846422 0.0492895260 0.1746819446 -0.045168378
[24,] -0.008111044 0.053896500 -0.164035649 0.0313158656 -0.0016431570 -0.024569519
[25,] -0.011827290 0.040412928 -0.101006393 0.1194546107 0.0078180799 -0.009930531
[26,] -0.015286379 0.015292618 0.132217419 -0.0199961544 0.0736978372 0.026045038
[27,] 0.022853069 0.059093414 -0.133572376 -0.0301357084 0.0006478486 -0.002570019
[28,] 0.047132800 0.043130377 0.004234388 -0.0069376095 0.0101333925 0.057512770
[29,] 0.051912356 0.043652943 0.014640849 -0.0090714814 0.0222754431 0.048622997
[30,] 0.100324028 0.049696616 0.066674137 0.0003548197 0.0697051160 0.025651417
[,19] [,20] [,21] [,22] [,23] [,24]
[1,] 0.04715056 7.493222e-02 0.0533329139 0.052172740 0.016180066 0.105211022
[2,] -0.06710851 3.919105e-03 0.0706883141 0.048095762 -0.048391388 -0.042531039
[3,] -0.01369189 1.206147e-02 0.0516108724 0.032433143 -0.053181340 0.014238024
[4,] -0.04061892 6.184427e-03 0.0621388917 0.033739661 -0.056833256 -0.011224683
[5,] -0.10545593 1.894630e-06 0.0853162820 0.056988456 -0.019951022 -0.096321780
[6,] -0.01574188 4.367827e-02 0.0675072825 0.042953670 0.048360679 -0.007304476
[7,] -0.02643826 3.566294e-02 0.0691613205 0.042004489 0.023272145 -0.010311858
[8,] 0.09805591 -6.806399e-02 -0.0500021458 -0.031958079 -0.018055847 -0.044654849
[9,] -0.04557141 3.208722e-02 0.0777909760 0.046317177 -0.016918483 -0.003225864
[10,] -0.01643653 1.592503e-02 0.0549533573 0.034472755 -0.046011679 0.013223107
[11,] 0.01225458 4.903598e-03 0.0349282349 0.026509132 -0.091607308 0.050152838
[12,] 0.05497633 -4.524818e-03 -0.0271411498 0.101034205 -0.013152432 0.013974377
[13,] -0.03512842 -1.970001e-02 0.0461896128 0.023895392 -0.113927074 -0.008111044
[14,] 0.02825293 2.996132e-02 0.0395373346 0.033780944 -0.027902406 0.053896500
[15,] 0.03145302 2.537059e-02 0.0263545553 0.009886985 0.300846422 -0.164035649
[16,] -0.07428536 -4.949636e-02 -0.0008291358 -0.032373773 0.049289526 0.031315866
[17,] 0.08782966 4.900177e-02 0.0132303136 0.020302104 0.174681945 -0.001643157
[18,] -0.04616245 4.950906e-03 0.0639874058 0.033113364 -0.045168378 -0.024569519
[19,] 0.24690400 1.027707e-01 -0.0380536295 0.025721887 0.188412676 0.177771022
[20,] 0.10277071 9.775826e-02 0.0354571172 0.049345657 0.108285479 0.118060387
[21,] -0.03805363 3.545712e-02 0.0757044571 0.046893422 -0.013720347 0.004941445
[22,] 0.02572189 4.934566e-02 0.0468934217 0.053595160 0.017171303 0.047531472
[23,] 0.18841268 1.082855e-01 -0.0137203469 0.017171303 0.375247525 0.046522642
[24,] 0.17777102 1.180604e-01 0.0049414451 0.047531472 0.046522642 0.267547021
[25,] 0.12090140 1.004102e-01 0.0207201405 0.042477190 0.060680449 0.207640849
[26,] 0.04321053 6.822134e-02 0.0488396615 0.040944387 0.130607386 0.018283715
[27,] 0.14404706 8.935017e-02 0.0108394678 0.043406742 0.012853915 0.204656450
[28,] -0.01801087 3.928450e-02 0.0676906562 0.045983476 -0.016456453 0.026718009
[29,] 0.01350422 3.060149e-02 0.0466020707 0.034948825 -0.001170677 0.026798880
[30,] 0.11948757 -3.640093e-02 -0.0446696972 -0.021387645 0.030035933 -0.014549709
[,25] [,26] [,27] [,28] [,29] [,30]
[1,] 0.090362679 0.04508936 0.0856433607 0.056011806 0.040576466 -0.0451693148
[2,] -0.021518127 0.03148466 -0.0204006459 0.060859025 0.044177721 -0.0148649395
[3,] 0.013308244 0.01384170 0.0300353790 0.050804734 0.047564166 0.0458059713
[4,] -0.001673163 0.02018656 0.0089700067 0.057453426 0.049292177 0.0288648837
[5,] -0.053677390 0.05441604 -0.0687892968 0.067037958 0.040607872 -0.0605047409
[6,] 0.013444520 0.06691013 -0.0027677013 0.057979055 0.040694123 -0.0376404337
[7,] 0.009582104 0.05806141 -0.0023654001 0.060031794 0.043095601 -0.0298718620
[8,] -0.074164127 -0.05463838 0.0156773594 -0.035307439 0.034143358 0.3897679391
[9,] 0.015149232 0.04900692 0.0047790361 0.068887943 0.047262389 -0.0446907634
[10,] 0.014706127 0.01937311 0.0273854706 0.053108189 0.047320963 0.0325568578
[11,] 0.030933834 -0.01455545 0.0647448886 0.041479333 0.048273937 0.0935339792
[12,] -0.009484868 -0.02304362 0.0133515588 -0.021302132 -0.015160674 0.0093893763
[13,] -0.011827290 -0.01528638 0.0228530689 0.047132800 0.051912356 0.1003240280
[14,] 0.040412928 0.01529262 0.0590934141 0.043130377 0.043652943 0.0496966158
[15,] -0.101006393 0.13221742 -0.1335723760 0.004234388 0.014640849 0.0666741369
[16,] 0.119454611 -0.01999615 -0.0301357084 -0.006937609 -0.009071481 0.0003548197
[17,] 0.007818080 0.07369784 0.0006478486 0.010133393 0.022275443 0.0697051160
[18,] -0.009930531 0.02604504 -0.0025700190 0.057512770 0.048622997 0.0256514171
[19,] 0.120901399 0.04321053 0.1440470629 -0.018010872 0.013504221 0.1194875712
[20,] 0.100410240 0.06822134 0.0893501657 0.039284500 0.030601492 -0.0364009299
[21,] 0.020720140 0.04883966 0.0108394678 0.067690656 0.046602071 -0.0446696972
[22,] 0.042477190 0.04094439 0.0434067419 0.045983476 0.034948825 -0.0213876450
[23,] 0.060680449 0.13060739 0.0128539151 -0.016456453 -0.001170677 0.0300359327
[24,] 0.207640849 0.01828372 0.2046564501 0.026718009 0.026798880 -0.0145497086
[25,] 0.178116117 0.03264404 0.1500003703 0.033475165 0.025416351 -0.0443727781
[26,] 0.032644038 0.08550763 0.0110099454 0.041833386 0.031112830 -0.0303176570
[27,] 0.150000370 0.01100995 0.1682503376 0.029236986 0.034132657 0.0296356567
[28,] 0.033475165 0.04183339 0.0292369859 0.063008931 0.045732346 -0.0307459422
[29,] 0.025416351 0.03111283 0.0341326568 0.045732346 0.042206398 0.0302334005
[30,] -0.044372778 -0.03031766 0.0296356567 -0.030745942 0.030233400 0.3334687104
> i=diag(30) #identity matrix
> e=(i-h)%*%y;e #residuals
[,1]
[1,] -58.725946
[2,] 38.273154
[3,] -26.330659
[4,] 14.635734
[5,] 38.383916
[6,] -25.087705
[7,] -9.919668
[8,] 19.018992
[9,] -20.314202
[10,] -28.785943
[11,] 49.343513
[12,] -3.989598
[13,] 62.033276
[14,] -59.633796
[15,] 40.497176
[16,] -39.403558
[17,] -37.694540
[18,] -2.037233
[19,] -111.679486
[20,] -42.475375
[21,] -23.075807
[22,] -5.553122
[23,] 73.048122
[24,] -40.676318
[25,] 182.583587
[26,] -23.376486
[27,] 89.383371
[28,] -5.805095
[29,] -36.935732
[30,] -5.700573
> sse=sum(e^2);sse #error sum of squares
[1] 89231.37
> s2=sse/(n-p);s2 #estimate of variance
[1] 3717.974
> sst=t(y)%*%y-(sum(y)^2)/n ;sst #total sum of squares
[,1]
[1,] 381081.4
> r2=1-(sse/sst);r2 #coefficient of deternmination
[,1]
[1,] 0.7658469
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.