# install.packages("ggplot2")
# install.packages("ISLR2")
library(ggplot2)
Explain whether each scenario is a classification or regression problem, and indicate whether we are most interested in inference or prediction. Finally, provide n and p.
What are the advantages and disadvantages of a very flexible (versus a less flexible) approach for regression or classification? Under what circumstances might a more flexible approach be preferred to a less flexible approach? When might a less flexible approach be preferred?
Describe the differences between a parametric and a non-parametric statistical learning approach. What are the advantages of a parametric approach to regression or classification (as opposed to a non-parametric approach)? What are its disadvantages?
This exercise relates to the College data set, which can be found in the file College.csv on the book website. It contains a number of variables for 777 different universities and colleges in the US. The variables are
college <- read.csv("College.csv", header = TRUE)
rownames(college) <- college[,1]
# had to comment out view as R would not knit the file if it was included
# View(college)
head(college)
## X Private Apps Accept
## Abilene Christian University Abilene Christian University Yes 1660 1232
## Adelphi University Adelphi University Yes 2186 1924
## Adrian College Adrian College Yes 1428 1097
## Agnes Scott College Agnes Scott College Yes 417 349
## Alaska Pacific University Alaska Pacific University Yes 193 146
## Albertson College Albertson College Yes 587 479
## Enroll Top10perc Top25perc F.Undergrad P.Undergrad
## Abilene Christian University 721 23 52 2885 537
## Adelphi University 512 16 29 2683 1227
## Adrian College 336 22 50 1036 99
## Agnes Scott College 137 60 89 510 63
## Alaska Pacific University 55 16 44 249 869
## Albertson College 158 38 62 678 41
## Outstate Room.Board Books Personal PhD Terminal
## Abilene Christian University 7440 3300 450 2200 70 78
## Adelphi University 12280 6450 750 1500 29 30
## Adrian College 11250 3750 400 1165 53 66
## Agnes Scott College 12960 5450 450 875 92 97
## Alaska Pacific University 7560 4120 800 1500 76 72
## Albertson College 13500 3335 500 675 67 73
## S.F.Ratio perc.alumni Expend Grad.Rate
## Abilene Christian University 18.1 12 7041 60
## Adelphi University 12.2 16 10527 56
## Adrian College 12.9 30 8735 54
## Agnes Scott College 7.7 37 19016 59
## Alaska Pacific University 11.9 2 10922 15
## Albertson College 9.4 11 9727 55
summary(college)
## X Private Apps Accept
## Length:777 Length:777 Min. : 81 Min. : 72
## Class :character Class :character 1st Qu.: 776 1st Qu.: 604
## Mode :character Mode :character Median : 1558 Median : 1110
## Mean : 3002 Mean : 2019
## 3rd Qu.: 3624 3rd Qu.: 2424
## Max. :48094 Max. :26330
## Enroll Top10perc Top25perc F.Undergrad
## Min. : 35 Min. : 1.00 Min. : 9.0 Min. : 139
## 1st Qu.: 242 1st Qu.:15.00 1st Qu.: 41.0 1st Qu.: 992
## Median : 434 Median :23.00 Median : 54.0 Median : 1707
## Mean : 780 Mean :27.56 Mean : 55.8 Mean : 3700
## 3rd Qu.: 902 3rd Qu.:35.00 3rd Qu.: 69.0 3rd Qu.: 4005
## Max. :6392 Max. :96.00 Max. :100.0 Max. :31643
## P.Undergrad Outstate Room.Board Books
## Min. : 1.0 Min. : 2340 Min. :1780 Min. : 96.0
## 1st Qu.: 95.0 1st Qu.: 7320 1st Qu.:3597 1st Qu.: 470.0
## Median : 353.0 Median : 9990 Median :4200 Median : 500.0
## Mean : 855.3 Mean :10441 Mean :4358 Mean : 549.4
## 3rd Qu.: 967.0 3rd Qu.:12925 3rd Qu.:5050 3rd Qu.: 600.0
## Max. :21836.0 Max. :21700 Max. :8124 Max. :2340.0
## Personal PhD Terminal S.F.Ratio
## Min. : 250 Min. : 8.00 Min. : 24.0 Min. : 2.50
## 1st Qu.: 850 1st Qu.: 62.00 1st Qu.: 71.0 1st Qu.:11.50
## Median :1200 Median : 75.00 Median : 82.0 Median :13.60
## Mean :1341 Mean : 72.66 Mean : 79.7 Mean :14.09
## 3rd Qu.:1700 3rd Qu.: 85.00 3rd Qu.: 92.0 3rd Qu.:16.50
## Max. :6800 Max. :103.00 Max. :100.0 Max. :39.80
## perc.alumni Expend Grad.Rate
## Min. : 0.00 Min. : 3186 Min. : 10.00
## 1st Qu.:13.00 1st Qu.: 6751 1st Qu.: 53.00
## Median :21.00 Median : 8377 Median : 65.00
## Mean :22.74 Mean : 9660 Mean : 65.46
## 3rd Qu.:31.00 3rd Qu.:10830 3rd Qu.: 78.00
## Max. :64.00 Max. :56233 Max. :118.00
# used rows 3 through 12 for pair plot as columns 1 is college names
# columns 2 is private (Yes if a a college is private school, No if a college is a public school)
A <- college[,3:12]
pairs(A)
# converted Private column into a factor type
college$Private <- as.factor(college$Private)
plot(college$Private, college$Outstate,
xlab = "Private",
ylab = "Outstate")
Create a new qualitative variable, called Elite, by binning the Top10perc variable. We are going to divide universities into two groups based on whether or not the proportion of students coming from the top 10 % of their high school classes exceeds 50 %.
Elite <- rep("No", nrow(college))
Elite[college$ Top10perc > 50] <- "Yes"
Elite <- as.factor(Elite)
college <- data.frame(college , Elite)
Use the summary() function to see how many elite universities there are.
summary(college$Elite)
## No Yes
## 699 78
Now use the plot() function to produce side-by-side boxplots of Outstate versus Elite.
plot(college$Elite, college$Outstate,
xlab = "Elite",
ylab = "Outstate")
Use the hist() function to produce some histograms with differing numbers of bins for a few of the quantitative variables. You may find the command par(mfrow = c(2, 2)) useful: it will divide the print window into four regions so that four plots can be made simultaneously. Modifying the arguments to this function will divide the screen in other ways.
par(mfrow = c(2,2))
hist(college$Outstate)
hist(college$Apps)
hist(college$Enroll)
hist(college$Grad.Rate)
college |>
ggplot(
aes(
x = Outstate,
y = Grad.Rate
)) +
geom_point() +
geom_smooth(method = lm, color = "red")
## `geom_smooth()` using formula = 'y ~ x'
college |>
ggplot(
aes(
x = Apps,
y = Accept
)
) + geom_point() +
geom_smooth(method = lm, color = "red")
## `geom_smooth()` using formula = 'y ~ x'
Based on the scatterplots above we can see that there is a positive correlation between students at outstate colleges and the graduation rate. We can also see that there is a positive correlation between the number of applications a college receives and the total number of students they accept. However, its important to note that majority of point are clustered on the lower left corner of the graph. This could be a problem when doing further analysis on the data.
This exercise involves the Auto data set studied in the lab. Make sure that the missing values have been removed from the data.
# removing rows that have a ? listed for horsepower as it will affect other parts of the question.
auto <- read.csv("Auto.csv", header = TRUE, na.strings = "?")
Response variable: mpg The name column will not be included due to it not being a good predictor variable
# removed any NA values as the current data set was affecting the range of some variables. Because if a column has just one NA value
# it will return NA for the whole function.
clean_auto <- na.omit(auto)
cat("displacement range:", range(clean_auto$displacement), "\n")
## displacement range: 68 455
cat("weight range:", range(clean_auto$weight), "\n")
## weight range: 1613 5140
cat("acceleration range:", range(clean_auto$acceleration), "\n")
## acceleration range: 8 24.8
cat("horsepower range:", range(clean_auto$horsepower), "\n")
## horsepower range: 46 230
Note that the horsepower range starts with ?. This is because there are 4 points in the dataset that have a ? listed as their horsepower.
# used cleaned data set from previous R chunk as the current data set was affecting the range of some variables.
# Because if a column has just one NA value it will return NA for the whole function.
cat("displacement mean:", mean(clean_auto$displacement), "\n")
## displacement mean: 194.412
cat("displacement standard deviation:", sd(clean_auto$displacement), "\n")
## displacement standard deviation: 104.644
cat("weight mean:", mean(clean_auto$weight), "\n")
## weight mean: 2977.584
cat("weight standard deviation:", sd(clean_auto$weight), "\n")
## weight standard deviation: 849.4026
cat("acceleration mean:", mean(clean_auto$acceleration), "\n")
## acceleration mean: 15.54133
cat("acceleration standard deviation:", sd(clean_auto$acceleration), "\n")
## acceleration standard deviation: 2.758864
cat("horsepower mean:", mean(clean_auto$horsepower), "\n")
## horsepower mean: 104.4694
cat("horsepower standard deviation:", sd(clean_auto$horsepower), "\n")
## horsepower standard deviation: 38.49116
# used cleaned data set from previous R chunk as the current data set was affecting the range of some variables.
# Because if a column has just one NA value it will return NA for the whole function.
auto <- clean_auto[-c(10:85),]
cat("displacement range:", range(clean_auto$displacement), "\n")
## displacement range: 68 455
cat("displacement mean:", mean(clean_auto$displacement), "\n")
## displacement mean: 194.412
cat("displacement standard deviation:", sd(clean_auto$displacement), "\n")
## displacement standard deviation: 104.644
cat("weight range:", range(clean_auto$weight), "\n")
## weight range: 1613 5140
cat("weight mean:", mean(clean_auto$weight), "\n")
## weight mean: 2977.584
cat("weight standard deviation:", sd(clean_auto$weight), "\n")
## weight standard deviation: 849.4026
cat("acceleration range:", range(clean_auto$acceleration), "\n")
## acceleration range: 8 24.8
cat("acceleration mean:", mean(clean_auto$acceleration), "\n")
## acceleration mean: 15.54133
cat("acceleration standard deviation:", sd(clean_auto$acceleration), "\n")
## acceleration standard deviation: 2.758864
cat("horsepower range:", range(clean_auto$horsepower), "\n")
## horsepower range: 46 230
cat("horsepower mean:", mean(clean_auto$horsepower), "\n")
## horsepower mean: 104.4694
cat("horsepower standard deviation:", sd(clean_auto$horsepower), "\n")
## horsepower standard deviation: 38.49116
auto_nums <- auto[1:8]
plot(auto_nums)
par(mfrow = c(1,2))
hist(auto$weight)
hist(auto$displacement)
Based on the pair plots above we can see that there is a negative correlation in the graph comparing mpg vs displacement and mpg vs weight. On the other hand for mpg vs year, we can see that the newer the car the more mpg a car has. Also, from the histograms we can see that the data is right skewed. For weight this means that majority of the cars in the data set are lighter in weight with a few points that are heavy. As for displacement, this means that majority of the cars in the data set have smaller engines. f. Suppose that we wish to predict gas mileage (mpg) on the basis of the other variables. Do your plots suggest that any of the other variables might be useful in predicting mpg? Justify your answer. Based on the previous plots, yes there are three main variables that to predict mpg would be weight, displacement, and horsepower. I believe these are the best options as we can see in the pair plots that they have the most correlation with each other. In the pair plots we can see that each has a negative correlation with mpg. While cylinder, year, and origin may be helpful in addition to the main three, I don’t think they provide enough information to a prediction model to accurately predict mpg.
This exercise involves the Boston housing data set.
library(ISLR2)
Now the data set is contained in the object Boston
head(Boston, 20)
## crim zn indus chas nox rm age dis rad tax ptratio lstat medv
## 1 0.00632 18.0 2.31 0 0.538 6.575 65.2 4.0900 1 296 15.3 4.98 24.0
## 2 0.02731 0.0 7.07 0 0.469 6.421 78.9 4.9671 2 242 17.8 9.14 21.6
## 3 0.02729 0.0 7.07 0 0.469 7.185 61.1 4.9671 2 242 17.8 4.03 34.7
## 4 0.03237 0.0 2.18 0 0.458 6.998 45.8 6.0622 3 222 18.7 2.94 33.4
## 5 0.06905 0.0 2.18 0 0.458 7.147 54.2 6.0622 3 222 18.7 5.33 36.2
## 6 0.02985 0.0 2.18 0 0.458 6.430 58.7 6.0622 3 222 18.7 5.21 28.7
## 7 0.08829 12.5 7.87 0 0.524 6.012 66.6 5.5605 5 311 15.2 12.43 22.9
## 8 0.14455 12.5 7.87 0 0.524 6.172 96.1 5.9505 5 311 15.2 19.15 27.1
## 9 0.21124 12.5 7.87 0 0.524 5.631 100.0 6.0821 5 311 15.2 29.93 16.5
## 10 0.17004 12.5 7.87 0 0.524 6.004 85.9 6.5921 5 311 15.2 17.10 18.9
## 11 0.22489 12.5 7.87 0 0.524 6.377 94.3 6.3467 5 311 15.2 20.45 15.0
## 12 0.11747 12.5 7.87 0 0.524 6.009 82.9 6.2267 5 311 15.2 13.27 18.9
## 13 0.09378 12.5 7.87 0 0.524 5.889 39.0 5.4509 5 311 15.2 15.71 21.7
## 14 0.62976 0.0 8.14 0 0.538 5.949 61.8 4.7075 4 307 21.0 8.26 20.4
## 15 0.63796 0.0 8.14 0 0.538 6.096 84.5 4.4619 4 307 21.0 10.26 18.2
## 16 0.62739 0.0 8.14 0 0.538 5.834 56.5 4.4986 4 307 21.0 8.47 19.9
## 17 1.05393 0.0 8.14 0 0.538 5.935 29.3 4.4986 4 307 21.0 6.58 23.1
## 18 0.78420 0.0 8.14 0 0.538 5.990 81.7 4.2579 4 307 21.0 14.67 17.5
## 19 0.80271 0.0 8.14 0 0.538 5.456 36.6 3.7965 4 307 21.0 11.69 20.2
## 20 0.72580 0.0 8.14 0 0.538 5.727 69.5 3.7965 4 307 21.0 11.28 18.2
Read about the data set:
?Boston
How many rows are in this data set? How many columns? What do the rows and columns represent? - 506 rows - 13 columns The columns represents all the variables in a data set and the rows represents the values for 506 suburbs of Boston.
pairs(Boston[,1:4])
pairs(Boston[,c(1,5:9)])
pairs(Boston[,c(1,10:13)])
Based on the pairwise scatterplots, we can see that majority of the predictor variables against crime rate (crim) are not showing a clear pattern. We can see that in the data set that many of the points represent a low crime rate with a few high points.
Are any of the predictors associated with per capita crime rate? If so, explain the relationship. Based on the plot from the previous question, I would say rad and age could be associated with per capita crime rate. I say this because in the scatterplot we can see that when rad is 24, the per capita crime rate increases. Also, for age, we can see that the older a house is the higher the crime right. For both plots it seems as though the points are cluster together on the higher end of age and rad which the crime rate increases.
Do any of the census tracts of Boston appear to have particularly high crime rates? Tax rates? Pupil-teacher ratios? Comment on the range of each predictor.
cat("Crime Rate Range:", range(Boston$crim), "\n")
## Crime Rate Range: 0.00632 88.9762
cat("Tax Rates Range:", range(Boston$tax), "\n")
## Tax Rates Range: 187 711
cat("Pupil-teacher Ratios Range:", range(Boston$ptratio))
## Pupil-teacher Ratios Range: 12.6 22
We can see that the crime rate and tax rate ranges are large compare to the pupil teach ratio that has a small range.
hist(Boston$crim)
Based on the histogram, we can see that the data is right skewed meaning that my thought in the previous question was correct. The data set contains a high number of low crime rates in the data set.
table(Boston$chas)
##
## 0 1
## 471 35
In this data set there are 35 census tracts that are bound to the Charles river. f. What is the median pupil-teacher ratio among the towns in this data set?
cat("Median Pupil-teacher Ratio:", median(Boston$ptratio))
## Median Pupil-teacher Ratio: 19.05
lowest_median <- which(Boston$medv == min(Boston$medv))
Boston[lowest_median,]
## 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
## 406 67.9208 0 18.1 0 0.693 5.683 100 1.4254 24 666 20.2 22.98 5
Using the which function along with minimum, we see there are two entries that have the lowest median value of owner-occupied homes; row 399 and row 406.
cat("zn Range:", range(Boston$zn), "\n")
## zn Range: 0 100
cat("indus Range:", range(Boston$indus), "\n")
## indus Range: 0.46 27.74
cat("chas Range:", range(Boston$chas), "\n")
## chas Range: 0 1
cat("nox Range:", range(Boston$nox), "\n")
## nox Range: 0.385 0.871
cat("rm Range:", range(Boston$rm), "\n")
## rm Range: 3.561 8.78
cat("age Range:", range(Boston$age), "\n")
## age Range: 2.9 100
cat("dis Range:", range(Boston$dis), "\n")
## dis Range: 1.1296 12.1265
cat("rad Range:", range(Boston$rad), "\n")
## rad Range: 1 24
cat("tax Range:", range(Boston$tax), "\n")
## tax Range: 187 711
cat("ptratio Range:", range(Boston$ptratio), "\n")
## ptratio Range: 12.6 22
cat("lstat Range:", range(Boston$lstat), "\n")
## lstat Range: 1.73 37.97
cat("medv Range:", range(Boston$medv))
## medv Range: 5 50
Based on the ranges, below is how rows 399 and 406 compare:
plus_sev_rms <- which(Boston$rm > 7)
Boston[plus_sev_rms,]
## crim zn indus chas nox rm age dis rad tax ptratio lstat
## 3 0.02729 0.0 7.07 0 0.4690 7.185 61.1 4.9671 2 242 17.8 4.03
## 5 0.06905 0.0 2.18 0 0.4580 7.147 54.2 6.0622 3 222 18.7 5.33
## 41 0.03359 75.0 2.95 0 0.4280 7.024 15.8 5.4011 3 252 18.3 1.98
## 56 0.01311 90.0 1.22 0 0.4030 7.249 21.9 8.6966 5 226 17.9 4.81
## 65 0.01951 17.5 1.38 0 0.4161 7.104 59.5 9.2229 3 216 18.6 8.05
## 89 0.05660 0.0 3.41 0 0.4890 7.007 86.3 3.4217 2 270 17.8 5.50
## 90 0.05302 0.0 3.41 0 0.4890 7.079 63.1 3.4145 2 270 17.8 5.70
## 98 0.12083 0.0 2.89 0 0.4450 8.069 76.0 3.4952 2 276 18.0 4.21
## 99 0.08187 0.0 2.89 0 0.4450 7.820 36.9 3.4952 2 276 18.0 3.57
## 100 0.06860 0.0 2.89 0 0.4450 7.416 62.5 3.4952 2 276 18.0 6.19
## 162 1.46336 0.0 19.58 0 0.6050 7.489 90.8 1.9709 5 403 14.7 1.73
## 163 1.83377 0.0 19.58 1 0.6050 7.802 98.2 2.0407 5 403 14.7 1.92
## 164 1.51902 0.0 19.58 1 0.6050 8.375 93.9 2.1620 5 403 14.7 3.32
## 167 2.01019 0.0 19.58 0 0.6050 7.929 96.2 2.0459 5 403 14.7 3.70
## 181 0.06588 0.0 2.46 0 0.4880 7.765 83.3 2.7410 3 193 17.8 7.56
## 183 0.09103 0.0 2.46 0 0.4880 7.155 92.2 2.7006 3 193 17.8 4.82
## 187 0.05602 0.0 2.46 0 0.4880 7.831 53.6 3.1992 3 193 17.8 4.45
## 190 0.08370 45.0 3.44 0 0.4370 7.185 38.9 4.5667 5 398 15.2 5.39
## 193 0.08664 45.0 3.44 0 0.4370 7.178 26.3 6.4798 5 398 15.2 2.87
## 196 0.01381 80.0 0.46 0 0.4220 7.875 32.0 5.6484 4 255 14.4 2.97
## 197 0.04011 80.0 1.52 0 0.4040 7.287 34.1 7.3090 2 329 12.6 4.08
## 198 0.04666 80.0 1.52 0 0.4040 7.107 36.6 7.3090 2 329 12.6 8.61
## 199 0.03768 80.0 1.52 0 0.4040 7.274 38.3 7.3090 2 329 12.6 6.62
## 201 0.01778 95.0 1.47 0 0.4030 7.135 13.9 7.6534 3 402 17.0 4.45
## 203 0.02177 82.5 2.03 0 0.4150 7.610 15.7 6.2700 2 348 14.7 3.11
## 204 0.03510 95.0 2.68 0 0.4161 7.853 33.2 5.1180 4 224 14.7 3.81
## 205 0.02009 95.0 2.68 0 0.4161 8.034 31.9 5.1180 4 224 14.7 2.88
## 225 0.31533 0.0 6.20 0 0.5040 8.266 78.3 2.8944 8 307 17.4 4.14
## 226 0.52693 0.0 6.20 0 0.5040 8.725 83.0 2.8944 8 307 17.4 4.63
## 227 0.38214 0.0 6.20 0 0.5040 8.040 86.5 3.2157 8 307 17.4 3.13
## 228 0.41238 0.0 6.20 0 0.5040 7.163 79.9 3.2157 8 307 17.4 6.36
## 229 0.29819 0.0 6.20 0 0.5040 7.686 17.0 3.3751 8 307 17.4 3.92
## 232 0.46296 0.0 6.20 0 0.5040 7.412 76.9 3.6715 8 307 17.4 5.25
## 233 0.57529 0.0 6.20 0 0.5070 8.337 73.3 3.8384 8 307 17.4 2.47
## 234 0.33147 0.0 6.20 0 0.5070 8.247 70.4 3.6519 8 307 17.4 3.95
## 238 0.51183 0.0 6.20 0 0.5070 7.358 71.6 4.1480 8 307 17.4 4.73
## 254 0.36894 22.0 5.86 0 0.4310 8.259 8.4 8.9067 7 330 19.1 3.54
## 257 0.01538 90.0 3.75 0 0.3940 7.454 34.2 6.3361 3 244 15.9 3.11
## 258 0.61154 20.0 3.97 0 0.6470 8.704 86.9 1.8010 5 264 13.0 5.12
## 259 0.66351 20.0 3.97 0 0.6470 7.333 100.0 1.8946 5 264 13.0 7.79
## 261 0.54011 20.0 3.97 0 0.6470 7.203 81.8 2.1121 5 264 13.0 9.59
## 262 0.53412 20.0 3.97 0 0.6470 7.520 89.4 2.1398 5 264 13.0 7.26
## 263 0.52014 20.0 3.97 0 0.6470 8.398 91.5 2.2885 5 264 13.0 5.91
## 264 0.82526 20.0 3.97 0 0.6470 7.327 94.5 2.0788 5 264 13.0 11.25
## 265 0.55007 20.0 3.97 0 0.6470 7.206 91.6 1.9301 5 264 13.0 8.10
## 267 0.78570 20.0 3.97 0 0.6470 7.014 84.6 2.1329 5 264 13.0 14.79
## 268 0.57834 20.0 3.97 0 0.5750 8.297 67.0 2.4216 5 264 13.0 7.44
## 269 0.54050 20.0 3.97 0 0.5750 7.470 52.6 2.8720 5 264 13.0 3.16
## 274 0.22188 20.0 6.96 1 0.4640 7.691 51.8 4.3665 3 223 18.6 6.58
## 277 0.10469 40.0 6.41 1 0.4470 7.267 49.0 4.7872 4 254 17.6 6.05
## 281 0.03578 20.0 3.33 0 0.4429 7.820 64.5 4.6947 5 216 14.9 3.76
## 283 0.06129 20.0 3.33 1 0.4429 7.645 49.7 5.2119 5 216 14.9 3.01
## 284 0.01501 90.0 1.21 1 0.4010 7.923 24.8 5.8850 1 198 13.6 3.16
## 285 0.00906 90.0 2.97 0 0.4000 7.088 20.8 7.3073 1 285 15.3 7.85
## 292 0.07886 80.0 4.95 0 0.4110 7.148 27.7 5.1167 4 245 19.2 3.56
## 300 0.05561 70.0 2.24 0 0.4000 7.041 10.0 7.8278 5 358 14.8 4.74
## 305 0.05515 33.0 2.18 0 0.4720 7.236 41.1 4.0220 7 222 18.4 6.93
## 307 0.07503 33.0 2.18 0 0.4720 7.420 71.9 3.0992 7 222 18.4 6.47
## 342 0.01301 35.0 1.52 0 0.4420 7.241 49.3 7.0379 1 284 15.5 5.49
## 365 3.47428 0.0 18.10 1 0.7180 8.780 82.9 1.9047 24 666 20.2 5.29
## 371 6.53876 0.0 18.10 1 0.6310 7.016 97.5 1.2024 24 666 20.2 2.96
## 376 19.60910 0.0 18.10 0 0.6710 7.313 97.9 1.3163 24 666 20.2 13.44
## 454 8.24809 0.0 18.10 0 0.7130 7.393 99.3 2.4527 24 666 20.2 16.74
## 483 5.73116 0.0 18.10 0 0.5320 7.061 77.0 3.4106 24 666 20.2 7.01
## medv
## 3 34.7
## 5 36.2
## 41 34.9
## 56 35.4
## 65 33.0
## 89 23.6
## 90 28.7
## 98 38.7
## 99 43.8
## 100 33.2
## 162 50.0
## 163 50.0
## 164 50.0
## 167 50.0
## 181 39.8
## 183 37.9
## 187 50.0
## 190 34.9
## 193 36.4
## 196 50.0
## 197 33.3
## 198 30.3
## 199 34.6
## 201 32.9
## 203 42.3
## 204 48.5
## 205 50.0
## 225 44.8
## 226 50.0
## 227 37.6
## 228 31.6
## 229 46.7
## 232 31.7
## 233 41.7
## 234 48.3
## 238 31.5
## 254 42.8
## 257 44.0
## 258 50.0
## 259 36.0
## 261 33.8
## 262 43.1
## 263 48.8
## 264 31.0
## 265 36.5
## 267 30.7
## 268 50.0
## 269 43.5
## 274 35.2
## 277 33.2
## 281 45.4
## 283 46.0
## 284 50.0
## 285 32.2
## 292 37.3
## 300 29.0
## 305 36.1
## 307 33.4
## 342 32.7
## 365 21.9
## 371 50.0
## 376 15.0
## 454 17.8
## 483 25.0
In this data set there are 64 census tracts that average more than seven rooms per dwelling.
plus_eight_rms <- which(Boston$rm > 8)
Boston[plus_eight_rms,]
## 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
In this data set there are 13 census tracts that average more than eight rooms per dwelling.
Of the census tracts that average more than eight rooms per dwelling we can see: