You are on page 1of 16

Minor-1

library(ISLR2) ## This librarry is for the Auto dataset

##Name
Warning: package
- SAMBHAV 'ISLR2' was Roll
RAGHUWANSHI built under R version 4.1.3
- M21AI589

Boston <- Boston

# Variable names in the data


names(Boston)

## [1] "crim" "zn" "indus" "chas" "nox" "rm" "age"


## [8] "dis" "rad" "tax" "ptratio" "lstat" "medv"

# summary of the data


print(summary(Boston))

## crim zn indus chas


## Min. : 0.00632 Min. : 0.00 Min. : 0.46 Min. :0.00000
## 1st Qu.: 0.08205 1st Qu.: 0.00 1st Qu.: 5.19 1st Qu.:0.00000
## Median : 0.25651 Median : 0.00 Median : 9.69 Median :0.00000
## Mean : 3.61352 Mean : 11.36 Mean :11.14 Mean :0.06917
## 3rd Qu.: 3.67708 3rd Qu.: 12.50 3rd Qu.:18.10 3rd Qu.:0.00000
## Max. :88.97620 Max. :100.00 Max. :27.74 Max. :1.00000
## nox rm age dis
## Min. :0.3850 Min. :3.561 Min. : 2.90 Min. : 1.130
## 1st Qu.:0.4490 1st Qu.:5.886 1st Qu.: 45.02 1st Qu.: 2.100
## Median :0.5380 Median :6.208 Median : 77.50 Median : 3.207
## Mean :0.5547 Mean :6.285 Mean : 68.57 Mean : 3.795
## 3rd Qu.:0.6240 3rd Qu.:6.623 3rd Qu.: 94.08 3rd Qu.: 5.188
## Max. :0.8710 Max. :8.780 Max. :100.00 Max. :12.127
## rad tax ptratio lstat
## Min. : 1.000 Min. :187.0 Min. :12.60 Min. : 1.73
## 1st Qu.: 4.000 1st Qu.:279.0 1st Qu.:17.40 1st Qu.: 6.95
## Median : 5.000 Median :330.0 Median :19.05 Median :11.36
## Mean : 9.549 Mean :408.2 Mean :18.46 Mean :12.65
## 3rd Qu.:24.000 3rd Qu.:666.0 3rd Qu.:20.20 3rd Qu.:16.95
## Max. :24.000 Max. :711.0 Max. :22.00 Max. :37.97
## medv
## Min. : 5.00
## 1st Qu.:17.02
## Median :21.20
## Mean :22.53
## 3rd Qu.:25.00
## Max. :50.00

#(i) Find the best fitted linear regression model to predict crim using the
minimum number of predictors among Zn, Indus and age.
#Linear crim Using Fit Zn, Indus and age

# Linear fit
lim.fit <- lm(crim~zn,Boston)
summary(lim.fit)

##
## Call:
## lm(formula = crim ~ zn, data = Boston)
##
## Residuals:
## Min 1Q Median 3Q Max
## -4.429 -4.222 -2.620 1.250 84.523
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4.45369 0.41722 10.675 < 2e-16 ***
## zn -0.07393 0.01609 -4.594 5.51e-06 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 8.435 on 504 degrees of freedom
## Multiple R-squared: 0.04019, Adjusted R-squared: 0.03828
## F-statistic: 21.1 on 1 and 504 DF, p-value: 5.506e-06

# Linear fit
lim.fit <- lm(crim~zn+indus,Boston)
summary(lim.fit)

##
## Call:
## lm(formula = crim ~ zn + indus, data = Boston)
##
## Residuals:
## Min 1Q Median 3Q Max
## -12.132 -2.594 -0.728 0.686 81.802
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -2.33371 0.87203 -2.676 0.00769 **
## zn 0.00855 0.01776 0.481 0.63048
## indus 0.52529 0.06039 8.699 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 7.872 on 503 degrees of freedom
## Multiple R-squared: 0.1657, Adjusted R-squared: 0.1624
## F-statistic: 49.95 on 2 and 503 DF, p-value: < 2.2e-16
# Linear fit
lim.fit <- lm(crim~zn+age,Boston)
summary(lim.fit)

##
## Call:
## lm(formula = crim ~ zn + age, data = Boston)
##
## Residuals:
## Min 1Q Median 3Q Max
## -6.793 -4.259 -1.228 1.530 82.849
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -3.7880764 1.2501333 -3.030 0.00257 **
## zn 0.0002326 0.0187203 0.012 0.99009
## age 0.1078960 0.0155105 6.956 1.09e-11 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 8.065 on 503 degrees of freedom
## Multiple R-squared: 0.1244, Adjusted R-squared: 0.1209
## F-statistic: 35.74 on 2 and 503 DF, p-value: 3.07e-15

# Linear fit
lim.fit <- lm(crim~indus+age,Boston)
summary(lim.fit)

##
## Call:
## lm(formula = crim ~ indus + age, data = Boston)
##
## Residuals:
## Min 1Q Median 3Q Max
## -11.323 -2.917 -0.867 1.044 81.581
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -3.91657 0.91511 -4.280 2.24e-05 ***
## indus 0.38445 0.06626 5.802 1.16e-08 ***
## age 0.04737 0.01615 2.934 0.0035 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 7.808 on 503 degrees of freedom
## Multiple R-squared: 0.1794, Adjusted R-squared: 0.1761
## F-statistic: 54.97 on 2 and 503 DF, p-value: < 2.2e-16

# Linear fit
lim.fit <- lm(crim~zn+indus+age,Boston)
summary(lim.fit)
##
## Call:
## lm(formula = crim ~ zn + indus + age, data = Boston)
##
## Residuals:
## Min 1Q Median 3Q Max
## -11.758 -2.705 -0.662 0.889 81.495
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -5.24955 1.23243 -4.260 2.45e-05 ***
## zn 0.03025 0.01877 1.612 0.10767
## indus 0.41377 0.06861 6.031 3.16e-09 ***
## age 0.05704 0.01720 3.316 0.00098 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 7.795 on 502 degrees of freedom
## Multiple R-squared: 0.1836, Adjusted R-squared: 0.1787
## F-statistic: 37.63 on 3 and 502 DF, p-value: < 2.2e-16

#Answer :- When all the 3 variable in model are use. In that case we got best
fitted linear regression model to predict (Multiple R-squared: 0.1836),
which is max in all.

#(ii) Find the 97% confidence intervals of parameters of the best fitted
model.
lim.fit <- lm(crim~zn+indus+age,Boston)
summary(lim.fit)

##
## Call:
## lm(formula = crim ~ zn + indus + age, data = Boston)
##
## Residuals:
## Min 1Q Median 3Q Max
## -11.758 -2.705 -0.662 0.889 81.495
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -5.24955 1.23243 -4.260 2.45e-05 ***
## zn 0.03025 0.01877 1.612 0.10767
## indus 0.41377 0.06861 6.031 3.16e-09 ***
## age 0.05704 0.01720 3.316 0.00098 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 7.795 on 502 degrees of freedom
## Multiple R-squared: 0.1836, Adjusted R-squared: 0.1787
## F-statistic: 37.63 on 3 and 502 DF, p-value: < 2.2e-16
confint(lim.fit, level=0.97)

## 1.5 % 98.5 %
## (Intercept) -7.93165087 -2.56745207
## zn -0.01059638 0.07108649
## indus 0.26445883 0.56307204
## age 0.01960335 0.09447242

#(iii) Find the 95% confidence interval of the mean response at


(Zn,Indus,age) = (26,5.7,28).
lim.fit <- lm(crim~zn+indus+age,Boston)
summary(lim.fit)

##
## Call:
## lm(formula = crim ~ zn + indus + age, data = Boston)
##
## Residuals:
## Min 1Q Median 3Q Max
## -11.758 -2.705 -0.662 0.889 81.495
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -5.24955 1.23243 -4.260 2.45e-05 ***
## zn 0.03025 0.01877 1.612 0.10767
## indus 0.41377 0.06861 6.031 3.16e-09 ***
## age 0.05704 0.01720 3.316 0.00098 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 7.795 on 502 degrees of freedom
## Multiple R-squared: 0.1836, Adjusted R-squared: 0.1787
## F-statistic: 37.63 on 3 and 502 DF, p-value: < 2.2e-16

confint(lim.fit, level=0.97)

## 1.5 % 98.5 %
## (Intercept) -7.93165087 -2.56745207
## zn -0.01059638 0.07108649
## indus 0.26445883 0.56307204
## age 0.01960335 0.09447242

predict(object=lim.fit, newdata = data.frame(zn=26, indus=5.7, age=28),


interval = "confidence", level = 0.95)

## fit lwr upr


## 1 -0.5076564 -1.716426 0.7011128

#(iv)Find the 95% prediction interval of the response at (Zn,Indus,age) =


(26,5.7,28)
lim.fit <- lm(crim~zn+indus+age,Boston)
summary(lim.fit)
##
## Call:
## lm(formula = crim ~ zn + indus + age, data = Boston)
##
## Residuals:
## Min 1Q Median 3Q Max
## -11.758 -2.705 -0.662 0.889 81.495
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -5.24955 1.23243 -4.260 2.45e-05 ***
## zn 0.03025 0.01877 1.612 0.10767
## indus 0.41377 0.06861 6.031 3.16e-09 ***
## age 0.05704 0.01720 3.316 0.00098 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 7.795 on 502 degrees of freedom
## Multiple R-squared: 0.1836, Adjusted R-squared: 0.1787
## F-statistic: 37.63 on 3 and 502 DF, p-value: < 2.2e-16

confint(lim.fit, level=0.97)

## 1.5 % 98.5 %
## (Intercept) -7.93165087 -2.56745207
## zn -0.01059638 0.07108649
## indus 0.26445883 0.56307204
## age 0.01960335 0.09447242

predict(object=lim.fit, newdata = data.frame(zn=26, indus=5.7, age=28),


interval = "prediction", level = 0.95)

## fit lwr upr


## 1 -0.5076564 -15.87055 14.85523

#(v) Plot the standardized and studentized residuals.


lim.fit <- lm(crim~zn+indus+age,Boston)
summary(lim.fit)

##
## Call:
## lm(formula = crim ~ zn + indus + age, data = Boston)
##
## Residuals:
## Min 1Q Median 3Q Max
## -11.758 -2.705 -0.662 0.889 81.495
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -5.24955 1.23243 -4.260 2.45e-05 ***
## zn 0.03025 0.01877 1.612 0.10767
## indus 0.41377 0.06861 6.031 3.16e-09 ***
## age 0.05704 0.01720 3.316 0.00098 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 7.795 on 502 degrees of freedom
## Multiple R-squared: 0.1836, Adjusted R-squared: 0.1787
## F-statistic: 37.63 on 3 and 502 DF, p-value: < 2.2e-16

confint(lim.fit, level=0.97)

## 1.5 % 98.5 %
## (Intercept) -7.93165087 -2.56745207
## zn -0.01059638 0.07108649
## indus 0.26445883 0.56307204
## age 0.01960335 0.09447242

predict(object=lim.fit, newdata = data.frame(zn=26, indus=5.7, age=28),


interval = "confidence", level = 0.95)

## fit lwr upr


## 1 -0.5076564 -1.716426 0.7011128

predict(object=lim.fit, newdata = data.frame(zn=26, indus=5.7, age=28),


interval = "prediction", level = 0.95)

## fit lwr upr


## 1 -0.5076564 -15.87055 14.85523

par(mfrow=c(2,2))
plot(rstandard(lim.fit), ylab="Standardized Residual")
plot(rstudent(lim.fit), ylab = "Studentized Residual")
#(vi) Find the R2 based on PRESS and conclude about your fitted model.
lim.fit <- lm(crim~zn+indus+age,Boston)
summary(lim.fit)

##
## Call:
## lm(formula = crim ~ zn + indus + age, data = Boston)
##
## Residuals:
## Min 1Q Median 3Q Max
## -11.758 -2.705 -0.662 0.889 81.495
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -5.24955 1.23243 -4.260 2.45e-05 ***
## zn 0.03025 0.01877 1.612 0.10767
## indus 0.41377 0.06861 6.031 3.16e-09 ***
## age 0.05704 0.01720 3.316 0.00098 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 7.795 on 502 degrees of freedom
## Multiple R-squared: 0.1836, Adjusted R-squared: 0.1787
## F-statistic: 37.63 on 3 and 502 DF, p-value: < 2.2e-16

confint(lim.fit, level=0.97)
## 1.5 % 98.5 %
## (Intercept) -7.93165087 -2.56745207
## zn -0.01059638 0.07108649
## indus 0.26445883 0.56307204
## age 0.01960335 0.09447242

predict(object=lim.fit, newdata = data.frame(zn=26, indus=5.7, age=28),


interval = "confidence", level = 0.95)

## fit lwr upr


## 1 -0.5076564 -1.716426 0.7011128

predict(object=lim.fit, newdata = data.frame(zn=26, indus=5.7, age=28),


interval = "prediction", level = 0.95)

## fit lwr upr


## 1 -0.5076564 -15.87055 14.85523

x=model.matrix(lim.fit)
press_res = summary(lim.fit)$res/(1-hat(x))
print(press_res)

## 1 2 3 4 5
6
## 0.03705227 -2.16043521 -1.13865625 1.78485966 1.33750086
1.03891942
## 7 8 9 10 11
12
## -2.10085963 -3.75273073 -3.91523200 -3.13120843 -3.56608536 -
3.01002132
## 13 14 15 16 17
18
## -0.51816682 -1.01767478 -2.31244146 -0.71685509 1.27792776 -
2.00399018
## 19 20 21 22 23
24
## 0.60161931 -1.36203641 -2.48320722 -2.36888551 -2.13079261 -
2.85983059
## 25 26 27 28 29
30
## -2.75577995 -2.17805761 -2.61390817 -2.24136009 -2.75033995 -
2.10766109
## 31 32 33 34 35
36
## -2.37240925 -2.49018343 -1.41452070 -2.40364275 -2.04931863 -
1.04800643
## 37 38 39 40 41
42
## -0.62449069 0.50033068 1.24908666 0.55425766 0.90902663
2.40816019
## 43 44 45 46 47
48
## 2.20165326 2.22585039 0.23336355 0.63985955 0.68584543 -
2.27224469
## 49 50 51 52 53
54
## -2.81719120 -0.93043233 -0.23798894 -1.27387055 1.14064490
1.11945428
## 55 56 57 58 59
60
## -1.40141005 0.80674640 0.36521864 -0.63892639 0.86492890 -
0.21889389
## 61 62 63 64 65
66
## -1.26153742 -2.81870829 -1.39278033 0.02194914 0.78080394
0.46547839
## 67 68 69 70 71
72
## -0.30045882 1.20929702 0.39872059 0.60979832 0.50041692 -
0.06375944
## 73 74 75 76 77
78
## 0.43343446 0.63368304 -0.33108287 -2.54896885 -4.21723028 -
2.60240872
## 79 80 81 82 83
84
## -3.08067078 -2.08379204 0.61607141 -1.49650848 0.68620194 -
0.14618285
## 85 86 87 88 89
90
## 0.70971053 0.25095070 0.87797290 0.22500507 -1.03934697
0.29487244
## 91 92 93 94 95
96
## 0.11618910 -0.34024172 -4.86851370 -3.48762357 -6.22220844
0.88644153
## 97 98 99 100 101
102
## 0.20081393 -0.16192612 2.05205770 0.56229649 -2.71253426 -
2.25292456
## 103 104 105 106 107
108
## -2.94949150 -3.08250399 -3.30576814 -3.70342879 -3.38445455 -
3.03600890
## 109 110 111 112 113
114
## -3.73147971 -3.25071982 -1.29296201 -3.45787813 -4.08963357 -
4.13600813
## 115 116 117 118 119
120
## -3.56619050 -3.76836318 -2.90450716 -3.46518667 -2.93987078 -
2.47400022
## 121 122 123 124 125
126
## -9.42881530 -10.22596599 -10.70121976 -10.87710527 -10.86097390 -
10.36925716
## 127 128 129 130 131
132
## -10.55713656 -9.08971287 -9.18469361 -8.38826117 -9.17574615 -
8.24722035
## 133 134 135 136 137
138
## -8.86607101 -8.98396542 -8.50603232 -8.91592162 -8.88195337 -
9.13444546
## 139 140 141 142 143
144
## -9.22615664 -8.91193382 -8.91966470 -7.94136665 -5.26420366 -
4.48348011
## 145 146 147 148 149
150
## -5.68121082 -6.21121876 -6.43677229 -5.97323068 -5.90152888 -
5.55982540
## 151 152 153 154 155
156
## -6.78150293 -7.09921323 -6.77906612 -6.35571751 -6.95037125 -
4.04968145
## 157 158 159 160 161
162
## -5.79675768 -7.22264662 -7.25355786 -7.17091490 -6.89542578 -
6.60108957
## 163 164 165 166 167
168
## -6.65547838 -6.72346430 -5.87556104 -5.25941841 -6.36242496 -
5.60024861
## 169 170 171 172 173
174
## -6.06490035 -5.86305094 -7.07704678 -6.12066156 -1.35017226 -
1.14288766
## 175 176 177 178 179
180
## -0.26220589 1.77082203 0.95927720 -0.56307950 -0.60840169
0.96709841
## 181 182 183 184 185
186
## -0.45944545 0.75970827 -0.95071162 -1.13991663 -0.81908667
0.37155337
## 187 188 189 190 191
192
## 1.24154309 0.20095795 0.93781431 0.33224183 1.34058177
0.78293095
## 193 194 195 196 197
198
## 1.05961129 1.70259639 1.17842351 0.84481734 0.30210426
0.16336793
## 199 200 201 202 203
204
## 0.05527200 0.95373342 1.02183092 -0.24676881 1.06294702 -
0.60917764
## 205 206 207 208 209
210
## -0.54814963 -0.27174681 -1.90576159 -3.03529592 -2.37573909 -
4.42967447
## 211 212 213 214 215
216
## -4.23112402 -3.82582400 -1.99233668 -0.84277115 0.61150180 -
1.36212237
## 217 218 219 220 221
222
## -3.66419542 -5.29589175 -5.75827190 -5.67340073 -2.02215965 -
2.13472151
## 223 224 225 226 227
228
## -1.13100181 -1.31846399 -1.47569199 -1.53375241 -1.88199396 -
1.47023194
## 229 230 231 232 233
234
## 2.04447698 1.93170473 -0.66655303 -1.24654235 -0.92656696 -
1.00517276
## 235 236 237 238 239
240
## -0.66432882 -0.49571175 -1.16555918 -0.89273716 1.34098461 -
0.01219265
## 241 242 243 244 245
246
## -0.68426315 -1.31137395 -0.61448587 2.00969010 -2.00901839 -
1.66053803
## 247 248 249 250 251
252
## 0.51124332 -2.17480627 -0.47824420 1.36532733 1.57630909
1.89081315
## 253 254 255 256 257
258
## 1.88035803 2.07709260 -0.46235690 0.27544188 -0.98547673 -
1.35718375
## 259 260 261 262 263
264
## -2.07098572 -2.07795581 -1.13352950 -1.58094793 -1.71762959 -
1.58393461
## 265 266 267 268 269
270
## -1.69317356 0.18253356 -1.04780577 -0.24251540 0.54461986 -
1.65699173
## 271 272 273 274 275
276
## -0.33858356 1.00815443 -1.47269838 -0.97060941 -0.43526629 -
0.96259666
## 277 278 279 280 281
282
## -1.30915500 -0.12635723 -0.36591557 1.65087884 -0.37851572
1.18858619
## 283 284 285 286 287
288
## 0.49564670 0.64338440 0.12446341 0.85440256 0.33113590 -
0.28862495
## 289 290 291 292 293
294
## -1.10366844 0.19921993 -0.79065520 -0.73426106 -0.52759846 -
1.50704971
## 295 296 297 298 299
300
## -2.86608159 -2.18382147 -3.38608130 -3.69392501 1.14072867
1.71869507
## 301 302 303 304 305
306
## -0.46132191 -0.57009818 0.75121042 0.79907582 1.06622793
0.09094844
## 307 308 309 310 311
312
## -0.68310466 -0.61664352 -3.07069366 -2.88127112 1.64619310 -
1.07274962
## 313 314 315 316 317
318
## -3.75974321 -3.31241406 -3.47207600 -3.03483474 -3.28640268 -
2.69919511
## 319 320 321 322 323
324
## -2.28458766 -1.73139933 -0.62269956 -0.72312577 -0.30072552 -
1.76620224
## 325 326 327 328 329
330
## 0.25169787 1.57591084 0.86032418 -0.05593083 2.53611034
3.04338483
## 331 332 333 334 335
336
## 2.14147227 0.11463470 0.39217574 0.98827230 0.95160752
1.18511450
## 337 338 339 340 341
342
## 0.49904545 -0.26854405 1.01656192 0.57166913 -0.17414227
0.76802076
## 343 344 345 346 347
348
## 1.09802922 -1.18205006 0.45401617 0.70307473 0.51526475 -
0.61374023
## 349 350 351 352 353
354
## 0.32558390 1.59447781 1.05942696 0.77585857 1.77342511 -
0.35972499
## 355 356 357 358 359
360
## 0.84993862 1.05444824 1.19335886 -3.59517176 -1.80213013 -
2.62639032
## 361 362 363 364 365
366
## -2.72802509 -3.61382843 -4.06665204 -3.10617907 -3.50810491 -
2.70828787
## 367 368 369 370 371
372
## -3.77153285 5.60633782 -3.06019777 -2.10042564 -1.26788446
1.29526903
## 373 374 375 376 377
378
## 0.92080137 3.18032529 10.60689222 11.84061805 7.75973289
1.95786318
## 379 380 381 382 383
384
## 15.99322687 9.97227604 81.83573468 8.02081126 1.24976559
0.04933106
## 385 386 387 388 389
390
## 12.69589597 9.01897475 16.53158444 15.31490800 6.42184222
0.27239027
## 391 392 393 394 395
396
## -0.81383873 -1.65898498 3.82305605 1.12819321 5.74370028
0.84583021
## 397 398 399 400 401
402
## -1.85145241 -0.20962980 30.55846110 3.25369716 17.18710326
6.32386110
## 403 404 405 406 407
408
## 1.66047230 17.16305658 34.55785055 60.27337127 12.83583708
4.02748513
## 409 410 411 412 413
414
## -0.42168498 6.52695838 43.40554459 6.13744574 10.92123575
20.81461556
## 415 416 417 418 419
420
## 37.98924876 10.19125128 3.42966725 18.69476952 65.91437046
5.23291370
## 421 422 423 424 425
426
## 3.15952314 -0.65560817 4.83155129 -0.04328133 2.53899132
8.21550666
## 427 428 429 430 431
432
## 6.65249630 31.06768291 0.67580114 1.65378628 1.34698755
2.45462840
## 433 434 435 436 437
438
## -0.06227878 -1.67893552 6.28268707 3.54038947 6.88883253
7.26950453
## 439 440 441 442 443
444
## 6.45088970 1.80290491 14.60242975 1.94942470 -2.28825729
2.03313218
## 445 446 447 448 449
450
## 5.07578037 3.03824953 -1.45654009 2.18526512 1.46681222 -
0.32193021
## 451 452 453 454 455
456
## -0.80698422 -2.41088930 -2.39547739 0.34629475 1.91500621 -
2.43079265
## 457 458 459 460 461
462
## -2.59487035 1.38667648 0.74156937 -0.25345576 -2.57138333 -
3.60320558
## 463 464 465 466 467
468
## -0.32013481 -1.55249342 1.88109289 -1.84585046 -3.30910221 -
3.22136816
## 469 470 471 472 473
474
## 9.33491437 7.66547331 -2.69291565 -3.38845524 -2.96259923 -
1.45687443
## 475 476 477 478 479
480
## 0.37643284 -1.40845403 -2.71854462 7.26737705 2.48910929
7.10342816
## 481 482 483 484 485
486
## -0.10662003 -0.80733963 -0.90439817 -1.74501849 -2.28222246 -
1.54139415
## 487 488 489 490 491
492
## -1.10416197 -0.44252038 -11.55139422 -11.83653509 -11.79493279 -
11.94396495
## 493 494 495 496 497
498
## -11.07563183 -1.67379858 -0.91624997 -0.22610366 -2.63646972 -
2.52606521
## 499 500 501 502 503
504
## -2.25243280 -2.78296749 -3.09223619 -3.57480777 -4.02638806 -
4.83491479
## 505 506
## -4.68733548 -4.25942431

press = sum(press_res^2)
tss = sum(anova(lim.fit)$"Sum Sq")
rsquare = 1- press/(tss)
print(rsquare)

## [1] 0.1749011

#Answer:- [1] 0.1749011

#Q2 Answer:- a, b and d #Q3 Answer:- a and d ``` #End

You might also like