library(ISLR2)
Auto <- na.omit(Auto)
9a)
| Quantitative | Qualitative |
|---|---|
| Qualitative | origin |
| Qualitative | name |
| Qualitative | cylinders |
| mpg | |
| displacement | |
| horsepower | |
| weight | |
| acceleration | |
| year |
9b)
data.frame(
"Quantitative"=c("MPG", "Cylinders", "Displacement", "Horse Power", "Weight", "Acceleration", "Year"),
"Lower Range"=c(range(Auto$mpg)[1], range(Auto$cylinders)[1], range(Auto$displacement)[1], range(Auto$horsepower)[1], range(Auto$weight)[1], range(Auto$acceleration)[1], range(Auto$year)[1]),
"Upper Range"=c(range(Auto$mpg)[2], range(Auto$cylinders)[2], range(Auto$displacement)[2], range(Auto$horsepower)[2], range(Auto$weight)[2], range(Auto$acceleration)[2], range(Auto$year)[2])
)
## Quantitative Lower.Range Upper.Range
## 1 MPG 9 46.6
## 2 Cylinders 3 8.0
## 3 Displacement 68 455.0
## 4 Horse Power 46 230.0
## 5 Weight 1613 5140.0
## 6 Acceleration 8 24.8
## 7 Year 70 82.0
9c)
data.frame(
"Quantitative"=c("MPG", "Cylinders", "Displacement", "Horse Power", "Weight", "Acceleration", "Year"),
"Mean"=c(mean(Auto$mpg), mean(Auto$cylinders), mean(Auto$displacement), mean(Auto$horsepower), mean(Auto$weight), mean(Auto$acceleration), mean(Auto$year)),
"Standard Deviation"=c(sd(Auto$mpg),sd(Auto$cylinders),sd(Auto$displacement),sd(Auto$horsepower),sd(Auto$weight),sd(Auto$acceleration),sd(Auto$year))
)
## Quantitative Mean Standard.Deviation
## 1 MPG 23.445918 7.805007
## 2 Cylinders 5.471939 1.705783
## 3 Displacement 194.411990 104.644004
## 4 Horse Power 104.469388 38.491160
## 5 Weight 2977.584184 849.402560
## 6 Acceleration 15.541327 2.758864
## 7 Year 75.979592 3.683737
Auto_filtered <- Auto[-c(10:85), ]
dim(Auto_filtered)
## [1] 316 9
dim(Auto)
## [1] 392 9
9d)
data.frame(
"Quantitative"=c("MPG", "Cylinders", "Displacement", "Horse Power", "Weight", "Acceleration", "Year"),
"Range"=c(range(Auto_filtered$mpg),range(Auto_filtered$cylinders),range(Auto_filtered$displacement),range(Auto_filtered$horsepower),range(Auto_filtered$weight),range(Auto_filtered$acceleration),range(Auto_filtered$year)),
"Mean"=c(mean(Auto_filtered$mpg),mean(Auto_filtered$cylinders),mean(Auto_filtered$displacement),mean(Auto_filtered$horsepower),mean(Auto_filtered$weight),mean(Auto_filtered$acceleration),mean(Auto_filtered$year)),
"Standard Deviation" = c(sd(Auto_filtered$mpg),sd(Auto_filtered$cylinders),sd(Auto_filtered$displacement),sd(Auto_filtered$horsepower),sd(Auto_filtered$weight),sd(Auto_filtered$acceleration),sd(Auto_filtered$year))
)
## Quantitative Range Mean Standard.Deviation
## 1 MPG 11.0 24.404430 7.867283
## 2 Cylinders 46.6 5.373418 1.654179
## 3 Displacement 3.0 187.240506 99.678367
## 4 Horse Power 8.0 100.721519 35.708853
## 5 Weight 68.0 2935.971519 811.300208
## 6 Acceleration 455.0 15.726899 2.693721
## 7 Year 46.0 77.145570 3.106217
## 8 MPG 230.0 24.404430 7.867283
## 9 Cylinders 1649.0 5.373418 1.654179
## 10 Displacement 4997.0 187.240506 99.678367
## 11 Horse Power 8.5 100.721519 35.708853
## 12 Weight 24.8 2935.971519 811.300208
## 13 Acceleration 70.0 15.726899 2.693721
## 14 Year 82.0 77.145570 3.106217
9e)
pairs(Auto)
This shows that horsepower, mpg, displacement, and weight all have strong correlations with each other
plot(Auto$cylinders, Auto$mpg)
plot(Auto$acceleration, Auto$mpg)
plot(Auto$horsepower, Auto$mpg)
plot(Auto$displacement, Auto$mpg)
I believe horsepower and displacement would be useful to determine mpg. There may be some use in including acceleration, but because of the spread, it may not be easy to get a precise answer.
library(ISLR2)
10a) 506 rows, 13 columns The rows are each a separate suburb of Boston. The columns are 13 different variables related to housing values
10b)
pairs(Boston)
There are many correlations between the different columns. Some do not correlate. For example, the Charles River (dummy variable) has no bearing on anything.
10c)
plot(Boston$crim,Boston$medv)
plot(Boston$zn, Boston$crim)
plot(Boston$indus, Boston$crim)
plot(Boston$nox, Boston$crim)
plot(Boston$rm, Boston$crim)
plot(Boston$age, Boston$crim)
plot(Boston$dis, Boston$crim)
plot(Boston$rad, Boston$crim)
plot(Boston$tax, Boston$crim)
plot(Boston$ptratio, Boston$crim)
plot(Boston$lstat, Boston$crim)
The proportion of owner-occupied units built before 1940, the lower status of the population, and the lower status of the population are positively related to the crime rate. The median value of owner-occupied homes is negatively correlated.
10d)
plot(Boston$tax)
plot(Boston$ptratio)
plot(Boston$crim)
range(Boston$ptratio)
## [1] 12.6 22.0
range(Boston$crim)
## [1] 0.00632 88.97620
range(Boston$tax)
## [1] 187 711
There are some census tracts with extremely high crime rates, tax rates, and pupil-to-teacher ratios. The range of pupil-to-teacher ratio is not relatively large (12.6 to 22.0). However, there is a wide range of crime and tax rates. Crime rates range: 0.00632 to 88.97620 and tax rates range: 187 to 711.
10e)
sum(Boston$chas)
## [1] 35
35
10f)
summary(Boston$ptratio)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 12.60 17.40 19.05 18.46 20.20 22.00
19.05
10g)
Boston[which.min(Boston$medv), ]
## crim zn indus chas nox rm age dis rad tax ptratio lstat medv
## 399 38.3518 0 18.1 0 0.693 5.453 100 1.4896 24 666 20.2 30.59 5
range(Boston$crim)
## [1] 0.00632 88.97620
range(Boston$zn)
## [1] 0 100
range(Boston$nox)
## [1] 0.385 0.871
range(Boston$rm)
## [1] 3.561 8.780
range(Boston$age)
## [1] 2.9 100.0
range(Boston$dis)
## [1] 1.1296 12.1265
range(Boston$rad)
## [1] 1 24
range(Boston$tax)
## [1] 187 711
range(Boston$ptratio)
## [1] 12.6 22.0
range(Boston$lstat)
## [1] 1.73 37.97
range(Boston$medv)
## [1] 5 50
range(Boston$indus)
## [1] 0.46 27.74
In crime, they’re in the middle of the range. In proportion of non-retail business acres per town, it is on the higher end. In nitrogen oxide concentration, they are on the higher end. In average number of rooms, they are in the middle of the range. In age, they are at the highest end. In distance from Boston employment centers, they are on the lower end. In accessibility to radial highways, they are on the highest end. In tax rate, they are on the higher end. In pupil-to-teacher ratio, they are on the higher end. In the lower status of the population, they are on the higher end. I think it is quite interesting to see that a majority of predictors are on the higher end for a census tract with the lowest median value.
10h)
data.frame(
"Avg Room gt 7" = c(sum(Boston$rm>7)),
"Avg Room gt 8" = c(sum(Boston$rm>8))
)
## Avg.Room.gt.7 Avg.Room.gt.8
## 1 64 13
Boston[Boston$rm>8,]
## crim zn indus chas nox rm age dis rad tax ptratio lstat medv
## 98 0.12083 0 2.89 0 0.4450 8.069 76.0 3.4952 2 276 18.0 4.21 38.7
## 164 1.51902 0 19.58 1 0.6050 8.375 93.9 2.1620 5 403 14.7 3.32 50.0
## 205 0.02009 95 2.68 0 0.4161 8.034 31.9 5.1180 4 224 14.7 2.88 50.0
## 225 0.31533 0 6.20 0 0.5040 8.266 78.3 2.8944 8 307 17.4 4.14 44.8
## 226 0.52693 0 6.20 0 0.5040 8.725 83.0 2.8944 8 307 17.4 4.63 50.0
## 227 0.38214 0 6.20 0 0.5040 8.040 86.5 3.2157 8 307 17.4 3.13 37.6
## 233 0.57529 0 6.20 0 0.5070 8.337 73.3 3.8384 8 307 17.4 2.47 41.7
## 234 0.33147 0 6.20 0 0.5070 8.247 70.4 3.6519 8 307 17.4 3.95 48.3
## 254 0.36894 22 5.86 0 0.4310 8.259 8.4 8.9067 7 330 19.1 3.54 42.8
## 258 0.61154 20 3.97 0 0.6470 8.704 86.9 1.8010 5 264 13.0 5.12 50.0
## 263 0.52014 20 3.97 0 0.6470 8.398 91.5 2.2885 5 264 13.0 5.91 48.8
## 268 0.57834 20 3.97 0 0.5750 8.297 67.0 2.4216 5 264 13.0 7.44 50.0
## 365 3.47428 0 18.10 1 0.7180 8.780 82.9 1.9047 24 666 20.2 5.29 21.9
All census tracts that have more than 8 average rooms seem to have ;ow lower status of population, low crime rate, and high median value.