# Question 1a
# Load up data mtcars and generate its descriptive statistics.
# Installing some important packages
library(psych)
## Warning: package 'psych' was built under R version 4.2.3
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.2.3
## Warning: package 'ggplot2' was built under R version 4.2.3
## Warning: package 'tibble' was built under R version 4.2.3
## Warning: package 'dplyr' was built under R version 4.2.3
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.1 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.2 ✔ tibble 3.2.1
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ purrr 1.0.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ ggplot2::%+%() masks psych::%+%()
## ✖ ggplot2::alpha() masks psych::alpha()
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the ]8;;http://conflicted.r-lib.org/conflicted package]8;; to force all conflicts to become errors
# Loading data
data(mtcars)
mtcars
## mpg cyl disp hp drat wt qsec vs am gear carb
## Mazda RX4 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4
## Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4
## Datsun 710 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1
## Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1
## Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3 2
## Valiant 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1
## Duster 360 14.3 8 360.0 245 3.21 3.570 15.84 0 0 3 4
## Merc 240D 24.4 4 146.7 62 3.69 3.190 20.00 1 0 4 2
## Merc 230 22.8 4 140.8 95 3.92 3.150 22.90 1 0 4 2
## Merc 280 19.2 6 167.6 123 3.92 3.440 18.30 1 0 4 4
## Merc 280C 17.8 6 167.6 123 3.92 3.440 18.90 1 0 4 4
## Merc 450SE 16.4 8 275.8 180 3.07 4.070 17.40 0 0 3 3
## Merc 450SL 17.3 8 275.8 180 3.07 3.730 17.60 0 0 3 3
## Merc 450SLC 15.2 8 275.8 180 3.07 3.780 18.00 0 0 3 3
## Cadillac Fleetwood 10.4 8 472.0 205 2.93 5.250 17.98 0 0 3 4
## Lincoln Continental 10.4 8 460.0 215 3.00 5.424 17.82 0 0 3 4
## Chrysler Imperial 14.7 8 440.0 230 3.23 5.345 17.42 0 0 3 4
## Fiat 128 32.4 4 78.7 66 4.08 2.200 19.47 1 1 4 1
## Honda Civic 30.4 4 75.7 52 4.93 1.615 18.52 1 1 4 2
## Toyota Corolla 33.9 4 71.1 65 4.22 1.835 19.90 1 1 4 1
## Toyota Corona 21.5 4 120.1 97 3.70 2.465 20.01 1 0 3 1
## Dodge Challenger 15.5 8 318.0 150 2.76 3.520 16.87 0 0 3 2
## AMC Javelin 15.2 8 304.0 150 3.15 3.435 17.30 0 0 3 2
## Camaro Z28 13.3 8 350.0 245 3.73 3.840 15.41 0 0 3 4
## Pontiac Firebird 19.2 8 400.0 175 3.08 3.845 17.05 0 0 3 2
## Fiat X1-9 27.3 4 79.0 66 4.08 1.935 18.90 1 1 4 1
## Porsche 914-2 26.0 4 120.3 91 4.43 2.140 16.70 0 1 5 2
## Lotus Europa 30.4 4 95.1 113 3.77 1.513 16.90 1 1 5 2
## Ford Pantera L 15.8 8 351.0 264 4.22 3.170 14.50 0 1 5 4
## Ferrari Dino 19.7 6 145.0 175 3.62 2.770 15.50 0 1 5 6
## Maserati Bora 15.0 8 301.0 335 3.54 3.570 14.60 0 1 5 8
## Volvo 142E 21.4 4 121.0 109 4.11 2.780 18.60 1 1 4 2
describe(mtcars) %>%
select(-range) %>%
round(2)
## vars n mean sd median trimmed mad min max skew kurtosis
## mpg 1 32 20.09 6.03 19.20 19.70 5.41 10.40 33.90 0.61 -0.37
## cyl 2 32 6.19 1.79 6.00 6.23 2.97 4.00 8.00 -0.17 -1.76
## disp 3 32 230.72 123.94 196.30 222.52 140.48 71.10 472.00 0.38 -1.21
## hp 4 32 146.69 68.56 123.00 141.19 77.10 52.00 335.00 0.73 -0.14
## drat 5 32 3.60 0.53 3.70 3.58 0.70 2.76 4.93 0.27 -0.71
## wt 6 32 3.22 0.98 3.33 3.15 0.77 1.51 5.42 0.42 -0.02
## qsec 7 32 17.85 1.79 17.71 17.83 1.42 14.50 22.90 0.37 0.34
## vs 8 32 0.44 0.50 0.00 0.42 0.00 0.00 1.00 0.24 -2.00
## am 9 32 0.41 0.50 0.00 0.38 0.00 0.00 1.00 0.36 -1.92
## gear 10 32 3.69 0.74 4.00 3.62 1.48 3.00 5.00 0.53 -1.07
## carb 11 32 2.81 1.62 2.00 2.65 1.48 1.00 8.00 1.05 1.26
## se
## mpg 1.07
## cyl 0.32
## disp 21.91
## hp 12.12
## drat 0.09
## wt 0.17
## qsec 0.32
## vs 0.09
## am 0.09
## gear 0.13
## carb 0.29
# --------The end of Q1a--------
# Question 1b
# Based on the plot, which predictors may have transformations like 𝑙𝑜𝑔(𝑥), √𝑥 or 𝑥2. Comment on your findings.
library(ggplot2)
# Mpg&disp
ggplot(mtcars, aes(x = mpg, y = disp)) +
geom_point() + geom_smooth(method= "lm")
## `geom_smooth()` using formula = 'y ~ x'

model1 <- lm(mpg ~ disp + I(sqrt(disp)), data = mtcars)
plot(model1)




model2 <- lm(mpg ~ disp + I(log(disp)), data = mtcars)
plot(model2)




hist(mtcars$disp)

hist(log(mtcars$disp))

hist(sqrt(mtcars$disp))

# Based on the multiple regressions, disp should be transformed. Sqrt and log regressions show better relationship visualization between mpg and disp.
# Mpg&cyl
ggplot(mtcars, aes(x = mpg, y = cyl)) +
geom_point() + geom_smooth(method= "lm")
## `geom_smooth()` using formula = 'y ~ x'

# Since we can not clear relationship between mpg and cyl using linear regression, let's try other regressions.
model3 <- lm(mpg ~ cyl + I(sqrt(cyl)), data = mtcars)
plot(model3)




model4 <- lm(mpg ~ cyl + I(log(cyl)), data = mtcars)
plot(model4)




hist(mtcars$cyl)

hist(log(mtcars$cyl))

hist(sqrt(mtcars$cyl))

# Based on the multiple regressions, cyl also should be transformed. Sqrt and log regressions show better relationship visualization between mpg and disp.
# Mpg&hp
ggplot(mtcars, aes(x = mpg, y = hp)) +
geom_point() + geom_smooth(method= "lm")
## `geom_smooth()` using formula = 'y ~ x'

# Mpg and hp has also inverse relationship.
model5 <- lm(mpg ~ hp + I(sqrt(hp)), data = mtcars)
plot(model5)




model6 <- lm(mpg ~ hp + I(log(hp)), data = mtcars)
plot(model6)




hist(mtcars$hp)

hist(log(mtcars$hp))

hist(sqrt(mtcars$hp))

# Mpg & Drat
ggplot(mtcars, aes(x = mpg, y = drat)) +
geom_point() + geom_smooth(method= "lm")
## `geom_smooth()` using formula = 'y ~ x'

# Mpg and drat is directly related.
model7 <- lm(mpg ~ drat + I(sqrt(drat)), data = mtcars)
plot(model7)




model8 <- lm(mpg ~ drat + I(log(drat)), data = mtcars)
plot(model8)




# Mpg & wt
ggplot(mtcars, aes(x = mpg, y = wt)) +
geom_point() + geom_smooth(method= "lm")
## `geom_smooth()` using formula = 'y ~ x'

# Mpg and wt has also inverse relationship.
model9 <- lm(mpg ~ wt + I(sqrt(wt)), data = mtcars)
plot(model9)




model10 <- lm(mpg ~ wt + I(log(wt)), data = mtcars)
plot(model10)




# Wt should not be transformed.
# Mpg & qsec
ggplot(mtcars, aes(x = mpg, y = qsec)) +
geom_point() + geom_smooth(method= "lm")
## `geom_smooth()` using formula = 'y ~ x'

# Mpg and qsec has also linear relationship.
model11 <- lm(mpg ~ qsec + I(sqrt(qsec)), data = mtcars)
plot(model11)




model12 <- lm(mpg ~ qsec + I(log(qsec)), data = mtcars)
plot(model12)




# Qsec should not be transformed.
# Mpg & vs
ggplot(mtcars, aes(x = mpg, y = vs)) +
geom_point() + geom_smooth(method= "lm")
## `geom_smooth()` using formula = 'y ~ x'

model13<- lm(mpg ~ vs + I(sqrt(vs)), data = mtcars)
plot(model13)




hist(mtcars$vs)

hist(log(mtcars$vs))

hist(sqrt(mtcars$vs))

# Mpg & am
ggplot(mtcars, aes(x = mpg, y = am)) +
geom_point() + geom_smooth(method= "lm")
## `geom_smooth()` using formula = 'y ~ x'

model15 <- lm(mpg ~ am + I(sqrt(am)), data = mtcars)
plot(model15)




hist(mtcars$am)

hist(log(mtcars$am))

hist(sqrt(mtcars$am))

# mpg & gear
ggplot(mtcars, aes(x = mpg, y = gear)) +
geom_point() + geom_smooth(method= "lm")
## `geom_smooth()` using formula = 'y ~ x'

hist(mtcars$gear)

hist(log(mtcars$gear))

hist(sqrt(mtcars$gear))

model17 <- lm(mpg ~ gear + I(sqrt(gear)), data = mtcars)
plot(model7)




model18 <- lm(mpg ~ gear + I(log(gear)), data = mtcars)
plot(model18)




# Final answer to Q1b:
# The explanation about the plots:
# The residual and fitted plots are graphical tools used to evaluate the adequacy of a statistical model. The residual plot shows the distribution of the residuals, while the fitted plot shows the relationship between the predicted and actual values of the dependent variable.
# In a normal Q-Q plot, if the data points lie close to a straight line, then it indicates that the data follows a normal distribution. Specifically, if the points fall roughly along a straight line with a slope of 1 and intercept of 0, then the data is considered to be normally distributed. If the points deviate from a straight line, then it indicates that the data is not normally distributed.
# The scale-location plot can also be used to check for linearity, which means that the relationship between the independent and dependent variables is linear. If the plot shows a roughly linear relationship between the fitted values and the residuals, then the assumption of linearity is met. If the plot shows a curved or non-linear relationship, then the assumption of linearity is violated.
# The plot is created by plotting the standardized residuals (on the y-axis) against the leverage values (on the x-axis), with a line representing the cutoff for identifying influential observations. The leverage values are a measure of how far an observation is from the center of the independent variable(s), and standardized residuals are the residuals divided by their estimated standard deviation.
# Based on the plot, I concluded that the cyl, wt, gear, am, vs and hp should not be transformed. And, disp, drat and qsec should be transformed.
# ------ The end of Q1b------
# Question 1c
# Run the multiple regression on mpg across all predictors and show the estimated results.
model <- lm(mpg ~ ., data = mtcars)
summary(model)
##
## Call:
## lm(formula = mpg ~ ., data = mtcars)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.4506 -1.6044 -0.1196 1.2193 4.6271
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 12.30337 18.71788 0.657 0.5181
## cyl -0.11144 1.04502 -0.107 0.9161
## disp 0.01334 0.01786 0.747 0.4635
## hp -0.02148 0.02177 -0.987 0.3350
## drat 0.78711 1.63537 0.481 0.6353
## wt -3.71530 1.89441 -1.961 0.0633 .
## qsec 0.82104 0.73084 1.123 0.2739
## vs 0.31776 2.10451 0.151 0.8814
## am 2.52023 2.05665 1.225 0.2340
## gear 0.65541 1.49326 0.439 0.6652
## carb -0.19942 0.82875 -0.241 0.8122
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2.65 on 21 degrees of freedom
## Multiple R-squared: 0.869, Adjusted R-squared: 0.8066
## F-statistic: 13.93 on 10 and 21 DF, p-value: 3.793e-07
#--------The end of Q1c---------
# Question 1d
# Use vif to estimate if there is any multi collinearity among predictors. Find predictors with vif higher than 10.
library(car)
## Warning: package 'car' was built under R version 4.2.3
## Loading required package: carData
## Warning: package 'carData' was built under R version 4.2.3
##
## Attaching package: 'car'
## The following object is masked from 'package:dplyr':
##
## recode
## The following object is masked from 'package:purrr':
##
## some
## The following object is masked from 'package:psych':
##
## logit
vif(model)
## cyl disp hp drat wt qsec vs am
## 15.373833 21.620241 9.832037 3.374620 15.164887 7.527958 4.965873 4.648487
## gear carb
## 5.357452 7.908747
# Explanation
# The VIFs of cyl, disp, and wt are higher than 10.
# ----------The end of Q1d-------------
# Question 1e
# Rerun the multiple regressions by (1) excluding disp, and (2) excluding disp and cyl from predictors. Are there any improvements observed from the regression results?
# The multiple regression by excluding disp
model_1 <- lm(mpg ~ . - disp, data = mtcars)
summary(model_1)
##
## Call:
## lm(formula = mpg ~ . - disp, data = mtcars)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.7863 -1.4055 -0.2635 1.2029 4.4753
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 12.55052 18.52585 0.677 0.5052
## cyl 0.09627 0.99715 0.097 0.9240
## hp -0.01295 0.01834 -0.706 0.4876
## drat 0.92864 1.60794 0.578 0.5694
## wt -2.62694 1.19800 -2.193 0.0392 *
## qsec 0.66523 0.69335 0.959 0.3478
## vs 0.16035 2.07277 0.077 0.9390
## am 2.47882 2.03513 1.218 0.2361
## gear 0.74300 1.47360 0.504 0.6191
## carb -0.61686 0.60566 -1.018 0.3195
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2.623 on 22 degrees of freedom
## Multiple R-squared: 0.8655, Adjusted R-squared: 0.8105
## F-statistic: 15.73 on 9 and 22 DF, p-value: 1.183e-07
# The multiple regression by excluding disp and cyl
model_2 <- lm(mpg ~ . - disp - cyl, data = mtcars)
summary(model_2)
##
## Call:
## lm(formula = mpg ~ . - disp - cyl, data = mtcars)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.8187 -1.3903 -0.3045 1.2269 4.5183
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 13.80810 12.88582 1.072 0.2950
## hp -0.01225 0.01649 -0.743 0.4650
## drat 0.88894 1.52061 0.585 0.5645
## wt -2.60968 1.15878 -2.252 0.0342 *
## qsec 0.63983 0.62752 1.020 0.3185
## vs 0.08786 1.88992 0.046 0.9633
## am 2.42418 1.91227 1.268 0.2176
## gear 0.69390 1.35294 0.513 0.6129
## carb -0.61286 0.59109 -1.037 0.3106
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2.566 on 23 degrees of freedom
## Multiple R-squared: 0.8655, Adjusted R-squared: 0.8187
## F-statistic: 18.5 on 8 and 23 DF, p-value: 2.627e-08
# Explanation
# The value of the adjusted R is higher after excluding the both disp and cyl. The model_2 shows the better result.
# ------------The end of the question 1-------------
# --------The beginning of the question number 2------------
# Question 2a
# Load data and fit a multiple regression model to predict Sales using Price, Urban and US.
library(ISLR2)
## Warning: package 'ISLR2' was built under R version 4.2.3
data("Carseats")
Carseats
## Sales CompPrice Income Advertising Population Price ShelveLoc Age Education
## 1 9.50 138 73 11 276 120 Bad 42 17
## 2 11.22 111 48 16 260 83 Good 65 10
## 3 10.06 113 35 10 269 80 Medium 59 12
## 4 7.40 117 100 4 466 97 Medium 55 14
## 5 4.15 141 64 3 340 128 Bad 38 13
## 6 10.81 124 113 13 501 72 Bad 78 16
## 7 6.63 115 105 0 45 108 Medium 71 15
## 8 11.85 136 81 15 425 120 Good 67 10
## 9 6.54 132 110 0 108 124 Medium 76 10
## 10 4.69 132 113 0 131 124 Medium 76 17
## 11 9.01 121 78 9 150 100 Bad 26 10
## 12 11.96 117 94 4 503 94 Good 50 13
## 13 3.98 122 35 2 393 136 Medium 62 18
## 14 10.96 115 28 11 29 86 Good 53 18
## 15 11.17 107 117 11 148 118 Good 52 18
## 16 8.71 149 95 5 400 144 Medium 76 18
## 17 7.58 118 32 0 284 110 Good 63 13
## 18 12.29 147 74 13 251 131 Good 52 10
## 19 13.91 110 110 0 408 68 Good 46 17
## 20 8.73 129 76 16 58 121 Medium 69 12
## 21 6.41 125 90 2 367 131 Medium 35 18
## 22 12.13 134 29 12 239 109 Good 62 18
## 23 5.08 128 46 6 497 138 Medium 42 13
## 24 5.87 121 31 0 292 109 Medium 79 10
## 25 10.14 145 119 16 294 113 Bad 42 12
## 26 14.90 139 32 0 176 82 Good 54 11
## 27 8.33 107 115 11 496 131 Good 50 11
## 28 5.27 98 118 0 19 107 Medium 64 17
## 29 2.99 103 74 0 359 97 Bad 55 11
## 30 7.81 104 99 15 226 102 Bad 58 17
## 31 13.55 125 94 0 447 89 Good 30 12
## 32 8.25 136 58 16 241 131 Medium 44 18
## 33 6.20 107 32 12 236 137 Good 64 10
## 34 8.77 114 38 13 317 128 Good 50 16
## 35 2.67 115 54 0 406 128 Medium 42 17
## 36 11.07 131 84 11 29 96 Medium 44 17
## 37 8.89 122 76 0 270 100 Good 60 18
## 38 4.95 121 41 5 412 110 Medium 54 10
## 39 6.59 109 73 0 454 102 Medium 65 15
## 40 3.24 130 60 0 144 138 Bad 38 10
## 41 2.07 119 98 0 18 126 Bad 73 17
## 42 7.96 157 53 0 403 124 Bad 58 16
## 43 10.43 77 69 0 25 24 Medium 50 18
## 44 4.12 123 42 11 16 134 Medium 59 13
## 45 4.16 85 79 6 325 95 Medium 69 13
## 46 4.56 141 63 0 168 135 Bad 44 12
## 47 12.44 127 90 14 16 70 Medium 48 15
## 48 4.38 126 98 0 173 108 Bad 55 16
## 49 3.91 116 52 0 349 98 Bad 69 18
## 50 10.61 157 93 0 51 149 Good 32 17
## 51 1.42 99 32 18 341 108 Bad 80 16
## 52 4.42 121 90 0 150 108 Bad 75 16
## 53 7.91 153 40 3 112 129 Bad 39 18
## 54 6.92 109 64 13 39 119 Medium 61 17
## 55 4.90 134 103 13 25 144 Medium 76 17
## 56 6.85 143 81 5 60 154 Medium 61 18
## 57 11.91 133 82 0 54 84 Medium 50 17
## 58 0.91 93 91 0 22 117 Bad 75 11
## 59 5.42 103 93 15 188 103 Bad 74 16
## 60 5.21 118 71 4 148 114 Medium 80 13
## 61 8.32 122 102 19 469 123 Bad 29 13
## 62 7.32 105 32 0 358 107 Medium 26 13
## 63 1.82 139 45 0 146 133 Bad 77 17
## 64 8.47 119 88 10 170 101 Medium 61 13
## 65 7.80 100 67 12 184 104 Medium 32 16
## 66 4.90 122 26 0 197 128 Medium 55 13
## 67 8.85 127 92 0 508 91 Medium 56 18
## 68 9.01 126 61 14 152 115 Medium 47 16
## 69 13.39 149 69 20 366 134 Good 60 13
## 70 7.99 127 59 0 339 99 Medium 65 12
## 71 9.46 89 81 15 237 99 Good 74 12
## 72 6.50 148 51 16 148 150 Medium 58 17
## 73 5.52 115 45 0 432 116 Medium 25 15
## 74 12.61 118 90 10 54 104 Good 31 11
## 75 6.20 150 68 5 125 136 Medium 64 13
## 76 8.55 88 111 23 480 92 Bad 36 16
## 77 10.64 102 87 10 346 70 Medium 64 15
## 78 7.70 118 71 12 44 89 Medium 67 18
## 79 4.43 134 48 1 139 145 Medium 65 12
## 80 9.14 134 67 0 286 90 Bad 41 13
## 81 8.01 113 100 16 353 79 Bad 68 11
## 82 7.52 116 72 0 237 128 Good 70 13
## 83 11.62 151 83 4 325 139 Good 28 17
## 84 4.42 109 36 7 468 94 Bad 56 11
## 85 2.23 111 25 0 52 121 Bad 43 18
## 86 8.47 125 103 0 304 112 Medium 49 13
## 87 8.70 150 84 9 432 134 Medium 64 15
## 88 11.70 131 67 7 272 126 Good 54 16
## 89 6.56 117 42 7 144 111 Medium 62 10
## 90 7.95 128 66 3 493 119 Medium 45 16
## 91 5.33 115 22 0 491 103 Medium 64 11
## 92 4.81 97 46 11 267 107 Medium 80 15
## 93 4.53 114 113 0 97 125 Medium 29 12
## 94 8.86 145 30 0 67 104 Medium 55 17
## 95 8.39 115 97 5 134 84 Bad 55 11
## 96 5.58 134 25 10 237 148 Medium 59 13
## 97 9.48 147 42 10 407 132 Good 73 16
## 98 7.45 161 82 5 287 129 Bad 33 16
## 99 12.49 122 77 24 382 127 Good 36 16
## 100 4.88 121 47 3 220 107 Bad 56 16
## 101 4.11 113 69 11 94 106 Medium 76 12
## 102 6.20 128 93 0 89 118 Medium 34 18
## 103 5.30 113 22 0 57 97 Medium 65 16
## 104 5.07 123 91 0 334 96 Bad 78 17
## 105 4.62 121 96 0 472 138 Medium 51 12
## 106 5.55 104 100 8 398 97 Medium 61 11
## 107 0.16 102 33 0 217 139 Medium 70 18
## 108 8.55 134 107 0 104 108 Medium 60 12
## 109 3.47 107 79 2 488 103 Bad 65 16
## 110 8.98 115 65 0 217 90 Medium 60 17
## 111 9.00 128 62 7 125 116 Medium 43 14
## 112 6.62 132 118 12 272 151 Medium 43 14
## 113 6.67 116 99 5 298 125 Good 62 12
## 114 6.01 131 29 11 335 127 Bad 33 12
## 115 9.31 122 87 9 17 106 Medium 65 13
## 116 8.54 139 35 0 95 129 Medium 42 13
## 117 5.08 135 75 0 202 128 Medium 80 10
## 118 8.80 145 53 0 507 119 Medium 41 12
## 119 7.57 112 88 2 243 99 Medium 62 11
## 120 7.37 130 94 8 137 128 Medium 64 12
## 121 6.87 128 105 11 249 131 Medium 63 13
## 122 11.67 125 89 10 380 87 Bad 28 10
## 123 6.88 119 100 5 45 108 Medium 75 10
## 124 8.19 127 103 0 125 155 Good 29 15
## 125 8.87 131 113 0 181 120 Good 63 14
## 126 9.34 89 78 0 181 49 Medium 43 15
## 127 11.27 153 68 2 60 133 Good 59 16
## 128 6.52 125 48 3 192 116 Medium 51 14
## 129 4.96 133 100 3 350 126 Bad 55 13
## 130 4.47 143 120 7 279 147 Bad 40 10
## 131 8.41 94 84 13 497 77 Medium 51 12
## 132 6.50 108 69 3 208 94 Medium 77 16
## 133 9.54 125 87 9 232 136 Good 72 10
## 134 7.62 132 98 2 265 97 Bad 62 12
## 135 3.67 132 31 0 327 131 Medium 76 16
## 136 6.44 96 94 14 384 120 Medium 36 18
## 137 5.17 131 75 0 10 120 Bad 31 18
## 138 6.52 128 42 0 436 118 Medium 80 11
## 139 10.27 125 103 12 371 109 Medium 44 10
## 140 12.30 146 62 10 310 94 Medium 30 13
## 141 6.03 133 60 10 277 129 Medium 45 18
## 142 6.53 140 42 0 331 131 Bad 28 15
## 143 7.44 124 84 0 300 104 Medium 77 15
## 144 0.53 122 88 7 36 159 Bad 28 17
## 145 9.09 132 68 0 264 123 Good 34 11
## 146 8.77 144 63 11 27 117 Medium 47 17
## 147 3.90 114 83 0 412 131 Bad 39 14
## 148 10.51 140 54 9 402 119 Good 41 16
## 149 7.56 110 119 0 384 97 Medium 72 14
## 150 11.48 121 120 13 140 87 Medium 56 11
## 151 10.49 122 84 8 176 114 Good 57 10
## 152 10.77 111 58 17 407 103 Good 75 17
## 153 7.64 128 78 0 341 128 Good 45 13
## 154 5.93 150 36 7 488 150 Medium 25 17
## 155 6.89 129 69 10 289 110 Medium 50 16
## 156 7.71 98 72 0 59 69 Medium 65 16
## 157 7.49 146 34 0 220 157 Good 51 16
## 158 10.21 121 58 8 249 90 Medium 48 13
## 159 12.53 142 90 1 189 112 Good 39 10
## 160 9.32 119 60 0 372 70 Bad 30 18
## 161 4.67 111 28 0 486 111 Medium 29 12
## 162 2.93 143 21 5 81 160 Medium 67 12
## 163 3.63 122 74 0 424 149 Medium 51 13
## 164 5.68 130 64 0 40 106 Bad 39 17
## 165 8.22 148 64 0 58 141 Medium 27 13
## 166 0.37 147 58 7 100 191 Bad 27 15
## 167 6.71 119 67 17 151 137 Medium 55 11
## 168 6.71 106 73 0 216 93 Medium 60 13
## 169 7.30 129 89 0 425 117 Medium 45 10
## 170 11.48 104 41 15 492 77 Good 73 18
## 171 8.01 128 39 12 356 118 Medium 71 10
## 172 12.49 93 106 12 416 55 Medium 75 15
## 173 9.03 104 102 13 123 110 Good 35 16
## 174 6.38 135 91 5 207 128 Medium 66 18
## 175 0.00 139 24 0 358 185 Medium 79 15
## 176 7.54 115 89 0 38 122 Medium 25 12
## 177 5.61 138 107 9 480 154 Medium 47 11
## 178 10.48 138 72 0 148 94 Medium 27 17
## 179 10.66 104 71 14 89 81 Medium 25 14
## 180 7.78 144 25 3 70 116 Medium 77 18
## 181 4.94 137 112 15 434 149 Bad 66 13
## 182 7.43 121 83 0 79 91 Medium 68 11
## 183 4.74 137 60 4 230 140 Bad 25 13
## 184 5.32 118 74 6 426 102 Medium 80 18
## 185 9.95 132 33 7 35 97 Medium 60 11
## 186 10.07 130 100 11 449 107 Medium 64 10
## 187 8.68 120 51 0 93 86 Medium 46 17
## 188 6.03 117 32 0 142 96 Bad 62 17
## 189 8.07 116 37 0 426 90 Medium 76 15
## 190 12.11 118 117 18 509 104 Medium 26 15
## 191 8.79 130 37 13 297 101 Medium 37 13
## 192 6.67 156 42 13 170 173 Good 74 14
## 193 7.56 108 26 0 408 93 Medium 56 14
## 194 13.28 139 70 7 71 96 Good 61 10
## 195 7.23 112 98 18 481 128 Medium 45 11
## 196 4.19 117 93 4 420 112 Bad 66 11
## 197 4.10 130 28 6 410 133 Bad 72 16
## 198 2.52 124 61 0 333 138 Medium 76 16
## 199 3.62 112 80 5 500 128 Medium 69 10
## 200 6.42 122 88 5 335 126 Medium 64 14
## 201 5.56 144 92 0 349 146 Medium 62 12
## 202 5.94 138 83 0 139 134 Medium 54 18
## 203 4.10 121 78 4 413 130 Bad 46 10
## 204 2.05 131 82 0 132 157 Bad 25 14
## 205 8.74 155 80 0 237 124 Medium 37 14
## 206 5.68 113 22 1 317 132 Medium 28 12
## 207 4.97 162 67 0 27 160 Medium 77 17
## 208 8.19 111 105 0 466 97 Bad 61 10
## 209 7.78 86 54 0 497 64 Bad 33 12
## 210 3.02 98 21 11 326 90 Bad 76 11
## 211 4.36 125 41 2 357 123 Bad 47 14
## 212 9.39 117 118 14 445 120 Medium 32 15
## 213 12.04 145 69 19 501 105 Medium 45 11
## 214 8.23 149 84 5 220 139 Medium 33 10
## 215 4.83 115 115 3 48 107 Medium 73 18
## 216 2.34 116 83 15 170 144 Bad 71 11
## 217 5.73 141 33 0 243 144 Medium 34 17
## 218 4.34 106 44 0 481 111 Medium 70 14
## 219 9.70 138 61 12 156 120 Medium 25 14
## 220 10.62 116 79 19 359 116 Good 58 17
## 221 10.59 131 120 15 262 124 Medium 30 10
## 222 6.43 124 44 0 125 107 Medium 80 11
## 223 7.49 136 119 6 178 145 Medium 35 13
## 224 3.45 110 45 9 276 125 Medium 62 14
## 225 4.10 134 82 0 464 141 Medium 48 13
## 226 6.68 107 25 0 412 82 Bad 36 14
## 227 7.80 119 33 0 245 122 Good 56 14
## 228 8.69 113 64 10 68 101 Medium 57 16
## 229 5.40 149 73 13 381 163 Bad 26 11
## 230 11.19 98 104 0 404 72 Medium 27 18
## 231 5.16 115 60 0 119 114 Bad 38 14
## 232 8.09 132 69 0 123 122 Medium 27 11
## 233 13.14 137 80 10 24 105 Good 61 15
## 234 8.65 123 76 18 218 120 Medium 29 14
## 235 9.43 115 62 11 289 129 Good 56 16
## 236 5.53 126 32 8 95 132 Medium 50 17
## 237 9.32 141 34 16 361 108 Medium 69 10
## 238 9.62 151 28 8 499 135 Medium 48 10
## 239 7.36 121 24 0 200 133 Good 73 13
## 240 3.89 123 105 0 149 118 Bad 62 16
## 241 10.31 159 80 0 362 121 Medium 26 18
## 242 12.01 136 63 0 160 94 Medium 38 12
## 243 4.68 124 46 0 199 135 Medium 52 14
## 244 7.82 124 25 13 87 110 Medium 57 10
## 245 8.78 130 30 0 391 100 Medium 26 18
## 246 10.00 114 43 0 199 88 Good 57 10
## 247 6.90 120 56 20 266 90 Bad 78 18
## 248 5.04 123 114 0 298 151 Bad 34 16
## 249 5.36 111 52 0 12 101 Medium 61 11
## 250 5.05 125 67 0 86 117 Bad 65 11
## 251 9.16 137 105 10 435 156 Good 72 14
## 252 3.72 139 111 5 310 132 Bad 62 13
## 253 8.31 133 97 0 70 117 Medium 32 16
## 254 5.64 124 24 5 288 122 Medium 57 12
## 255 9.58 108 104 23 353 129 Good 37 17
## 256 7.71 123 81 8 198 81 Bad 80 15
## 257 4.20 147 40 0 277 144 Medium 73 10
## 258 8.67 125 62 14 477 112 Medium 80 13
## 259 3.47 108 38 0 251 81 Bad 72 14
## 260 5.12 123 36 10 467 100 Bad 74 11
## 261 7.67 129 117 8 400 101 Bad 36 10
## 262 5.71 121 42 4 188 118 Medium 54 15
## 263 6.37 120 77 15 86 132 Medium 48 18
## 264 7.77 116 26 6 434 115 Medium 25 17
## 265 6.95 128 29 5 324 159 Good 31 15
## 266 5.31 130 35 10 402 129 Bad 39 17
## 267 9.10 128 93 12 343 112 Good 73 17
## 268 5.83 134 82 7 473 112 Bad 51 12
## 269 6.53 123 57 0 66 105 Medium 39 11
## 270 5.01 159 69 0 438 166 Medium 46 17
## 271 11.99 119 26 0 284 89 Good 26 10
## 272 4.55 111 56 0 504 110 Medium 62 16
## 273 12.98 113 33 0 14 63 Good 38 12
## 274 10.04 116 106 8 244 86 Medium 58 12
## 275 7.22 135 93 2 67 119 Medium 34 11
## 276 6.67 107 119 11 210 132 Medium 53 11
## 277 6.93 135 69 14 296 130 Medium 73 15
## 278 7.80 136 48 12 326 125 Medium 36 16
## 279 7.22 114 113 2 129 151 Good 40 15
## 280 3.42 141 57 13 376 158 Medium 64 18
## 281 2.86 121 86 10 496 145 Bad 51 10
## 282 11.19 122 69 7 303 105 Good 45 16
## 283 7.74 150 96 0 80 154 Good 61 11
## 284 5.36 135 110 0 112 117 Medium 80 16
## 285 6.97 106 46 11 414 96 Bad 79 17
## 286 7.60 146 26 11 261 131 Medium 39 10
## 287 7.53 117 118 11 429 113 Medium 67 18
## 288 6.88 95 44 4 208 72 Bad 44 17
## 289 6.98 116 40 0 74 97 Medium 76 15
## 290 8.75 143 77 25 448 156 Medium 43 17
## 291 9.49 107 111 14 400 103 Medium 41 11
## 292 6.64 118 70 0 106 89 Bad 39 17
## 293 11.82 113 66 16 322 74 Good 76 15
## 294 11.28 123 84 0 74 89 Good 59 10
## 295 12.66 148 76 3 126 99 Good 60 11
## 296 4.21 118 35 14 502 137 Medium 79 10
## 297 8.21 127 44 13 160 123 Good 63 18
## 298 3.07 118 83 13 276 104 Bad 75 10
## 299 10.98 148 63 0 312 130 Good 63 15
## 300 9.40 135 40 17 497 96 Medium 54 17
## 301 8.57 116 78 1 158 99 Medium 45 11
## 302 7.41 99 93 0 198 87 Medium 57 16
## 303 5.28 108 77 13 388 110 Bad 74 14
## 304 10.01 133 52 16 290 99 Medium 43 11
## 305 11.93 123 98 12 408 134 Good 29 10
## 306 8.03 115 29 26 394 132 Medium 33 13
## 307 4.78 131 32 1 85 133 Medium 48 12
## 308 5.90 138 92 0 13 120 Bad 61 12
## 309 9.24 126 80 19 436 126 Medium 52 10
## 310 11.18 131 111 13 33 80 Bad 68 18
## 311 9.53 175 65 29 419 166 Medium 53 12
## 312 6.15 146 68 12 328 132 Bad 51 14
## 313 6.80 137 117 5 337 135 Bad 38 10
## 314 9.33 103 81 3 491 54 Medium 66 13
## 315 7.72 133 33 10 333 129 Good 71 14
## 316 6.39 131 21 8 220 171 Good 29 14
## 317 15.63 122 36 5 369 72 Good 35 10
## 318 6.41 142 30 0 472 136 Good 80 15
## 319 10.08 116 72 10 456 130 Good 41 14
## 320 6.97 127 45 19 459 129 Medium 57 11
## 321 5.86 136 70 12 171 152 Medium 44 18
## 322 7.52 123 39 5 499 98 Medium 34 15
## 323 9.16 140 50 10 300 139 Good 60 15
## 324 10.36 107 105 18 428 103 Medium 34 12
## 325 2.66 136 65 4 133 150 Bad 53 13
## 326 11.70 144 69 11 131 104 Medium 47 11
## 327 4.69 133 30 0 152 122 Medium 53 17
## 328 6.23 112 38 17 316 104 Medium 80 16
## 329 3.15 117 66 1 65 111 Bad 55 11
## 330 11.27 100 54 9 433 89 Good 45 12
## 331 4.99 122 59 0 501 112 Bad 32 14
## 332 10.10 135 63 15 213 134 Medium 32 10
## 333 5.74 106 33 20 354 104 Medium 61 12
## 334 5.87 136 60 7 303 147 Medium 41 10
## 335 7.63 93 117 9 489 83 Bad 42 13
## 336 6.18 120 70 15 464 110 Medium 72 15
## 337 5.17 138 35 6 60 143 Bad 28 18
## 338 8.61 130 38 0 283 102 Medium 80 15
## 339 5.97 112 24 0 164 101 Medium 45 11
## 340 11.54 134 44 4 219 126 Good 44 15
## 341 7.50 140 29 0 105 91 Bad 43 16
## 342 7.38 98 120 0 268 93 Medium 72 10
## 343 7.81 137 102 13 422 118 Medium 71 10
## 344 5.99 117 42 10 371 121 Bad 26 14
## 345 8.43 138 80 0 108 126 Good 70 13
## 346 4.81 121 68 0 279 149 Good 79 12
## 347 8.97 132 107 0 144 125 Medium 33 13
## 348 6.88 96 39 0 161 112 Good 27 14
## 349 12.57 132 102 20 459 107 Good 49 11
## 350 9.32 134 27 18 467 96 Medium 49 14
## 351 8.64 111 101 17 266 91 Medium 63 17
## 352 10.44 124 115 16 458 105 Medium 62 16
## 353 13.44 133 103 14 288 122 Good 61 17
## 354 9.45 107 67 12 430 92 Medium 35 12
## 355 5.30 133 31 1 80 145 Medium 42 18
## 356 7.02 130 100 0 306 146 Good 42 11
## 357 3.58 142 109 0 111 164 Good 72 12
## 358 13.36 103 73 3 276 72 Medium 34 15
## 359 4.17 123 96 10 71 118 Bad 69 11
## 360 3.13 130 62 11 396 130 Bad 66 14
## 361 8.77 118 86 7 265 114 Good 52 15
## 362 8.68 131 25 10 183 104 Medium 56 15
## 363 5.25 131 55 0 26 110 Bad 79 12
## 364 10.26 111 75 1 377 108 Good 25 12
## 365 10.50 122 21 16 488 131 Good 30 14
## 366 6.53 154 30 0 122 162 Medium 57 17
## 367 5.98 124 56 11 447 134 Medium 53 12
## 368 14.37 95 106 0 256 53 Good 52 17
## 369 10.71 109 22 10 348 79 Good 74 14
## 370 10.26 135 100 22 463 122 Medium 36 14
## 371 7.68 126 41 22 403 119 Bad 42 12
## 372 9.08 152 81 0 191 126 Medium 54 16
## 373 7.80 121 50 0 508 98 Medium 65 11
## 374 5.58 137 71 0 402 116 Medium 78 17
## 375 9.44 131 47 7 90 118 Medium 47 12
## 376 7.90 132 46 4 206 124 Medium 73 11
## 377 16.27 141 60 19 319 92 Good 44 11
## 378 6.81 132 61 0 263 125 Medium 41 12
## 379 6.11 133 88 3 105 119 Medium 79 12
## 380 5.81 125 111 0 404 107 Bad 54 15
## 381 9.64 106 64 10 17 89 Medium 68 17
## 382 3.90 124 65 21 496 151 Bad 77 13
## 383 4.95 121 28 19 315 121 Medium 66 14
## 384 9.35 98 117 0 76 68 Medium 63 10
## 385 12.85 123 37 15 348 112 Good 28 12
## 386 5.87 131 73 13 455 132 Medium 62 17
## 387 5.32 152 116 0 170 160 Medium 39 16
## 388 8.67 142 73 14 238 115 Medium 73 14
## 389 8.14 135 89 11 245 78 Bad 79 16
## 390 8.44 128 42 8 328 107 Medium 35 12
## 391 5.47 108 75 9 61 111 Medium 67 12
## 392 6.10 153 63 0 49 124 Bad 56 16
## 393 4.53 129 42 13 315 130 Bad 34 13
## 394 5.57 109 51 10 26 120 Medium 30 17
## 395 5.35 130 58 19 366 139 Bad 33 16
## 396 12.57 138 108 17 203 128 Good 33 14
## 397 6.14 139 23 3 37 120 Medium 55 11
## 398 7.41 162 26 12 368 159 Medium 40 18
## 399 5.94 100 79 7 284 95 Bad 50 12
## 400 9.71 134 37 0 27 120 Good 49 16
## Urban US
## 1 Yes Yes
## 2 Yes Yes
## 3 Yes Yes
## 4 Yes Yes
## 5 Yes No
## 6 No Yes
## 7 Yes No
## 8 Yes Yes
## 9 No No
## 10 No Yes
## 11 No Yes
## 12 Yes Yes
## 13 Yes No
## 14 Yes Yes
## 15 Yes Yes
## 16 No No
## 17 Yes No
## 18 Yes Yes
## 19 No Yes
## 20 Yes Yes
## 21 Yes Yes
## 22 No Yes
## 23 Yes No
## 24 Yes No
## 25 Yes Yes
## 26 No No
## 27 No Yes
## 28 Yes No
## 29 Yes Yes
## 30 Yes Yes
## 31 Yes No
## 32 Yes Yes
## 33 No Yes
## 34 Yes Yes
## 35 Yes Yes
## 36 No Yes
## 37 No No
## 38 Yes Yes
## 39 Yes No
## 40 No No
## 41 No No
## 42 Yes No
## 43 Yes No
## 44 Yes Yes
## 45 Yes Yes
## 46 Yes Yes
## 47 No Yes
## 48 Yes No
## 49 Yes No
## 50 Yes No
## 51 Yes Yes
## 52 Yes No
## 53 Yes Yes
## 54 Yes Yes
## 55 No Yes
## 56 Yes Yes
## 57 Yes No
## 58 Yes No
## 59 Yes Yes
## 60 Yes No
## 61 Yes Yes
## 62 No No
## 63 Yes Yes
## 64 Yes Yes
## 65 No Yes
## 66 No No
## 67 Yes No
## 68 Yes Yes
## 69 Yes Yes
## 70 Yes No
## 71 Yes Yes
## 72 No Yes
## 73 Yes No
## 74 No Yes
## 75 No Yes
## 76 No Yes
## 77 Yes Yes
## 78 No Yes
## 79 Yes Yes
## 80 Yes No
## 81 Yes Yes
## 82 Yes No
## 83 Yes Yes
## 84 Yes Yes
## 85 No No
## 86 No No
## 87 Yes No
## 88 No Yes
## 89 Yes Yes
## 90 No No
## 91 No No
## 92 Yes Yes
## 93 Yes No
## 94 Yes No
## 95 Yes Yes
## 96 Yes Yes
## 97 No Yes
## 98 Yes Yes
## 99 No Yes
## 100 No Yes
## 101 No Yes
## 102 Yes No
## 103 No No
## 104 Yes Yes
## 105 Yes No
## 106 Yes Yes
## 107 No No
## 108 Yes No
## 109 Yes No
## 110 No No
## 111 Yes Yes
## 112 Yes Yes
## 113 Yes Yes
## 114 Yes Yes
## 115 Yes Yes
## 116 Yes No
## 117 No No
## 118 Yes No
## 119 Yes Yes
## 120 Yes Yes
## 121 Yes Yes
## 122 Yes Yes
## 123 Yes Yes
## 124 No Yes
## 125 Yes No
## 126 No No
## 127 Yes Yes
## 128 Yes Yes
## 129 Yes Yes
## 130 No Yes
## 131 Yes Yes
## 132 Yes No
## 133 Yes Yes
## 134 Yes Yes
## 135 Yes No
## 136 No Yes
## 137 No No
## 138 Yes No
## 139 Yes Yes
## 140 No Yes
## 141 Yes Yes
## 142 Yes No
## 143 Yes No
## 144 Yes Yes
## 145 No No
## 146 Yes Yes
## 147 Yes No
## 148 No Yes
## 149 No Yes
## 150 Yes Yes
## 151 No Yes
## 152 No Yes
## 153 No No
## 154 No Yes
## 155 No Yes
## 156 Yes No
## 157 Yes No
## 158 No Yes
## 159 No Yes
## 160 No No
## 161 No No
## 162 No Yes
## 163 Yes No
## 164 No No
## 165 No Yes
## 166 Yes Yes
## 167 Yes Yes
## 168 Yes No
## 169 Yes No
## 170 Yes Yes
## 171 Yes Yes
## 172 Yes Yes
## 173 Yes Yes
## 174 Yes Yes
## 175 No No
## 176 Yes No
## 177 No Yes
## 178 Yes Yes
## 179 No Yes
## 180 Yes Yes
## 181 Yes Yes
## 182 Yes No
## 183 Yes No
## 184 Yes Yes
## 185 No Yes
## 186 Yes Yes
## 187 No No
## 188 Yes No
## 189 Yes No
## 190 No Yes
## 191 No Yes
## 192 Yes Yes
## 193 No No
## 194 Yes Yes
## 195 Yes Yes
## 196 Yes Yes
## 197 Yes Yes
## 198 Yes No
## 199 Yes Yes
## 200 Yes Yes
## 201 No No
## 202 Yes No
## 203 No Yes
## 204 Yes No
## 205 Yes No
## 206 Yes No
## 207 Yes Yes
## 208 No No
## 209 Yes No
## 210 No Yes
## 211 No Yes
## 212 Yes Yes
## 213 Yes Yes
## 214 Yes Yes
## 215 Yes Yes
## 216 Yes Yes
## 217 Yes No
## 218 No No
## 219 Yes Yes
## 220 Yes Yes
## 221 Yes Yes
## 222 Yes No
## 223 Yes Yes
## 224 Yes Yes
## 225 No No
## 226 Yes No
## 227 Yes No
## 228 Yes Yes
## 229 No Yes
## 230 No No
## 231 No No
## 232 No No
## 233 Yes Yes
## 234 No Yes
## 235 No Yes
## 236 Yes Yes
## 237 Yes Yes
## 238 Yes Yes
## 239 Yes No
## 240 Yes Yes
## 241 Yes No
## 242 Yes No
## 243 No No
## 244 Yes Yes
## 245 Yes No
## 246 No Yes
## 247 Yes Yes
## 248 Yes No
## 249 Yes Yes
## 250 Yes No
## 251 Yes Yes
## 252 Yes Yes
## 253 Yes No
## 254 No Yes
## 255 Yes Yes
## 256 Yes Yes
## 257 Yes No
## 258 Yes Yes
## 259 No No
## 260 No Yes
## 261 Yes Yes
## 262 Yes Yes
## 263 Yes Yes
## 264 Yes Yes
## 265 Yes Yes
## 266 Yes Yes
## 267 No Yes
## 268 No Yes
## 269 Yes No
## 270 Yes No
## 271 Yes No
## 272 Yes No
## 273 Yes No
## 274 Yes Yes
## 275 Yes Yes
## 276 Yes Yes
## 277 Yes Yes
## 278 Yes Yes
## 279 No Yes
## 280 Yes Yes
## 281 Yes Yes
## 282 No Yes
## 283 Yes No
## 284 No No
## 285 No No
## 286 Yes Yes
## 287 No Yes
## 288 Yes Yes
## 289 No No
## 290 Yes Yes
## 291 No Yes
## 292 Yes No
## 293 Yes Yes
## 294 Yes No
## 295 Yes Yes
## 296 No Yes
## 297 Yes Yes
## 298 Yes Yes
## 299 Yes No
## 300 No Yes
## 301 Yes Yes
## 302 Yes Yes
## 303 Yes Yes
## 304 Yes Yes
## 305 Yes Yes
## 306 Yes Yes
## 307 Yes Yes
## 308 Yes No
## 309 Yes Yes
## 310 Yes Yes
## 311 Yes Yes
## 312 Yes Yes
## 313 Yes Yes
## 314 Yes No
## 315 Yes Yes
## 316 Yes Yes
## 317 Yes Yes
## 318 No No
## 319 No Yes
## 320 No Yes
## 321 Yes Yes
## 322 Yes No
## 323 Yes Yes
## 324 Yes Yes
## 325 Yes Yes
## 326 Yes Yes
## 327 Yes No
## 328 Yes Yes
## 329 Yes Yes
## 330 Yes Yes
## 331 No No
## 332 Yes Yes
## 333 Yes Yes
## 334 Yes Yes
## 335 Yes Yes
## 336 Yes Yes
## 337 Yes No
## 338 Yes No
## 339 Yes No
## 340 Yes Yes
## 341 Yes No
## 342 No No
## 343 No Yes
## 344 Yes Yes
## 345 No Yes
## 346 Yes No
## 347 No No
## 348 No No
## 349 Yes Yes
## 350 No Yes
## 351 No Yes
## 352 No Yes
## 353 Yes Yes
## 354 No Yes
## 355 Yes Yes
## 356 Yes No
## 357 Yes No
## 358 Yes Yes
## 359 Yes Yes
## 360 Yes Yes
## 361 No Yes
## 362 No Yes
## 363 Yes Yes
## 364 Yes No
## 365 Yes Yes
## 366 No No
## 367 No Yes
## 368 Yes No
## 369 No Yes
## 370 Yes Yes
## 371 Yes Yes
## 372 Yes No
## 373 No No
## 374 Yes No
## 375 Yes Yes
## 376 Yes No
## 377 Yes Yes
## 378 No No
## 379 Yes Yes
## 380 Yes No
## 381 Yes Yes
## 382 Yes Yes
## 383 Yes Yes
## 384 Yes No
## 385 Yes Yes
## 386 Yes Yes
## 387 Yes No
## 388 No Yes
## 389 Yes Yes
## 390 Yes Yes
## 391 Yes Yes
## 392 Yes No
## 393 Yes Yes
## 394 No Yes
## 395 Yes Yes
## 396 Yes Yes
## 397 No Yes
## 398 Yes Yes
## 399 Yes Yes
## 400 Yes Yes
# Fit the multiple regression model
model1 <- lm(Sales ~ Price + Urban + US, data=Carseats)
# View the model summary
summary(model1)
##
## Call:
## lm(formula = Sales ~ Price + Urban + US, data = Carseats)
##
## Residuals:
## Min 1Q Median 3Q Max
## -6.9206 -1.6220 -0.0564 1.5786 7.0581
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 13.043469 0.651012 20.036 < 2e-16 ***
## Price -0.054459 0.005242 -10.389 < 2e-16 ***
## UrbanYes -0.021916 0.271650 -0.081 0.936
## USYes 1.200573 0.259042 4.635 4.86e-06 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2.472 on 396 degrees of freedom
## Multiple R-squared: 0.2393, Adjusted R-squared: 0.2335
## F-statistic: 41.52 on 3 and 396 DF, p-value: < 2.2e-16
predict1 <- Carseats %>% select(Sales) %>% bind_cols(predict(model1,new_data=Carseats))
## New names:
## • `` -> `...2`
colnames(predict1) = c("Sales", "Predicted_Sales")
head(predict1, 10)
## Sales Predicted_Sales
## 1 9.50 7.687064
## 2 11.22 9.702041
## 3 10.06 9.865418
## 4 7.40 8.939617
## 5 4.15 6.050820
## 6 10.81 10.323004
## 7 6.63 7.139997
## 8 11.85 7.687064
## 9 6.54 6.290572
## 10 4.69 7.491144
# ------------The end of the question 2a -------------
# Question 2b
# Provide an interpretation of each coefficient in the model.
# In the multiple regression model to predict Sales using Price, Urban, and US, there are two qualitative variables: Urban and US. Here are the interpretations of the coefficients for each predictor variable:
#Price: The estimated coefficient for Price is -0.0545. This means that for every one unit increase in Price, Sales is expected to decrease by 0.0545 units, holding all other variables constant.
#Urban: The estimated coefficient for UrbanYes is -0.022. This means that for stores located in urban areas, Sales is expected to decrease by 0.022 units compared to stores located in rural areas, holding all other variables constant. However, the p-value of 0.827 suggests that this effect is not statistically significant at the 0.05 level.
#US: The estimated coefficient for USYes is 1.20. This means that for stores located in the US, Sales is expected to be higher by 1.20 units compared to stores located outside the US, holding all other variables constant. However, the p-value of 0.063 suggests that this effect is not statistically significant at the 0.05 level.
# ------------The end of the question 2b-------------
# Question 2c:
# Write out the model in equation form
#Sales = β0 + β1 * Price + β2 * UrbanYes + β3 * USYes + ε
#Sales= 13.04 - 0.0545 * Price - 0.022 * UrbanYes + 1.20 * USYes + ε
#where:
#Sales is the dependent variable, representing sales of car seats (in thousands of units).
#Price is the independent variable, representing the price of the car seats.
#UrbanYes is a binary variable that takes on a value of 1 if the store is located in an urban area and 0 if it is located in a rural area.
#USYes is a binary variable that takes on a value of 1 if the store is located in the US and 0 if it is located outside the US.
#β0 is the intercept term, representing the expected value of Sales when all predictor variables are zero.
#β1 is the estimated coefficient for Price, representing the expected change in Sales for every one unit increase in Price, holding all other variables constant.
#β2 is the estimated coefficient for UrbanYes, representing the expected difference in Sales for stores located in urban areas compared to stores located in rural areas, holding all other variables constant.
#β3 is the estimated coefficient for USYes, representing the expected difference in Sales for stores located in the US compared to stores located outside the US, holding all other variables constant.
#ε is the error term, representing the random variability in Sales that is not accounted for by the predictor variables.
# ------------The end of the question2c-------------
# Question 2d
# For which of the predictors can you reject the null hypothesis 𝐻0: 𝛽𝑗 = 0?
# To determine which of the predictors we can reject the null hypothesis H0: βj = 0, we need to look at the p-values associated with each estimated coefficient. A p-value less than 0.05 indicates that we can reject the null hypothesis at the 0.05 level of significance.
#In the multiple regression model to predict Sales using Price, Urban, and US, the p-values for the estimated coefficients are as follows:
#Price: The p-value for the estimated coefficient for Price is less than 0.001, indicating that we can reject the null hypothesis that the true coefficient for Price is zero. This means that Price has a statistically significant effect on Sales.
#Urban: The p-value for the estimated coefficient for UrbanYes is 0.827, which is greater than 0.05. Therefore, we cannot reject the null hypothesis that the true coefficient for UrbanYes is zero. This means that Urban does not have a statistically significant effect on Sales.
#US: The p-value for the estimated coefficient for USYes is 0.063, which is slightly greater than 0.05. Therefore, we cannot reject the null hypothesis that the true coefficient for USYes is zero at the 0.05 level of significance. However, if we were to use a significance level of 0.10, we could reject the null hypothesis and conclude that US has a statistically significant effect on Sales.
# Question 2e:
# On the basis of your response to the previous question, fit a smaller model that only uses the predictors for which there is evidence of association with the outcome.
# Fit smaller model with only Price as predictor
model_smaller <- lm(Sales ~ Price, data = Carseats)
# Print summary of model
summary(model_smaller)
##
## Call:
## lm(formula = Sales ~ Price, data = Carseats)
##
## Residuals:
## Min 1Q Median 3Q Max
## -6.5224 -1.8442 -0.1459 1.6503 7.5108
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 13.641915 0.632812 21.558 <2e-16 ***
## Price -0.053073 0.005354 -9.912 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2.532 on 398 degrees of freedom
## Multiple R-squared: 0.198, Adjusted R-squared: 0.196
## F-statistic: 98.25 on 1 and 398 DF, p-value: < 2.2e-16
# Question 2f: How well do the models in (a) and (e) fit the data?
# Fit multiple regression model with all three predictors
model_full <- lm(Sales ~ Price + Urban + US, data = Carseats)
summary(model_full)
##
## Call:
## lm(formula = Sales ~ Price + Urban + US, data = Carseats)
##
## Residuals:
## Min 1Q Median 3Q Max
## -6.9206 -1.6220 -0.0564 1.5786 7.0581
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 13.043469 0.651012 20.036 < 2e-16 ***
## Price -0.054459 0.005242 -10.389 < 2e-16 ***
## UrbanYes -0.021916 0.271650 -0.081 0.936
## USYes 1.200573 0.259042 4.635 4.86e-06 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2.472 on 396 degrees of freedom
## Multiple R-squared: 0.2393, Adjusted R-squared: 0.2335
## F-statistic: 41.52 on 3 and 396 DF, p-value: < 2.2e-16
# Print R-squared and adjusted R-squared values
summary(model_full)$r.squared
## [1] 0.2392754
summary(model_full)$adj.r.squared
## [1] 0.2335123
# The R-squared value for this model is 0.239, which means that about 24% of the variance in Sales is explained by the three predictor variables. The adjusted R-squared value is slightly lower at 0.235, which takes into account the number of predictor variables in the model.
# Fit smaller model with only Price as predictor
model_smaller <- lm(Sales ~ Price, data = Carseats)
summary(model_smaller)
##
## Call:
## lm(formula = Sales ~ Price, data = Carseats)
##
## Residuals:
## Min 1Q Median 3Q Max
## -6.5224 -1.8442 -0.1459 1.6503 7.5108
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 13.641915 0.632812 21.558 <2e-16 ***
## Price -0.053073 0.005354 -9.912 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2.532 on 398 degrees of freedom
## Multiple R-squared: 0.198, Adjusted R-squared: 0.196
## F-statistic: 98.25 on 1 and 398 DF, p-value: < 2.2e-16
# Print R-squared and adjusted R-squared values
summary(model_smaller)$r.squared
## [1] 0.1979812
summary(model_smaller)$adj.r.squared
## [1] 0.195966
#The R-squared value for this model is 0.198 which is slightly lower than the R-squared value for the model with all three predictors. This suggests that Price alone may not be a slightly better predictor of Sales than the combination of Price, Urban, and US. The adjusted R-squared value for the smaller model is also slightly smaller at 0.196, which indicates that the smaller model is not a better fit when taking into account the number of predictor variables.
# Question 2g: Using the model from (e), obtain 95% confidence intervals for the coefficient(s)
# Fit smaller model with only Price as predictor
model_smaller <- lm(Sales ~ Price, data = Carseats)
# Get 95% confidence intervals for coefficients
confint(model_smaller)
## 2.5 % 97.5 %
## (Intercept) 12.3978438 14.88598655
## Price -0.0635995 -0.04254653
# Question 2h: Is there evidence of ouitliers or high leverage observations in the model from (e)?
# Fit smaller model with only Price as predictor
model_smaller <- lm(Sales ~ Price, data = Carseats)
# Generate diagnostic plots
par(mfrow = c(2,2))
plot(model_smaller)
