Chapter 07 (page 297): 6, 10

6. In this exercise, you will further analyze the Wage data set considered throughout this chapter.

library(ISLR)
## Warning: package 'ISLR' was built under R version 4.0.3
attach(Wage)
library(boot)
  1. Perform polynomial regression to predict wage using age. Use cross-validation to select the optimal degree d for the polynomial. What degree was chosen, and how does this compare to the results of hypothesis testing using ANOVA? Make a plot of the resulting polynomial fit to the data.
fit1 = glm(wage ~ poly(age, 1), data = Wage)
fit2 = glm(wage~ poly(age, 2), data = Wage)
fit3 = glm(wage ~ poly(age, 3), data = Wage)
fit4 = glm(wage ~ poly(age, 4), data = Wage)
fit5 = glm(wage ~ poly(age, 5), data = Wage)

fit_error = 
rbind(
  cv.glm(Wage, fit1)$delta[1],
cv.glm(Wage, fit2)$delta[1],
cv.glm(Wage, fit3)$delta[1],
cv.glm(Wage, fit4)$delta[1],
cv.glm(Wage, fit5)$delta[1]
)

fit_error
##          [,1]
## [1,] 1676.235
## [2,] 1600.529
## [3,] 1595.960
## [4,] 1594.596
## [5,] 1594.879

Based on the above, 4 looks to be the optimal degree.

coef(summary(fit4))
##                 Estimate Std. Error    t value     Pr(>|t|)
## (Intercept)    111.70361  0.7287409 153.283015 0.000000e+00
## poly(age, 4)1  447.06785 39.9147851  11.200558 1.484604e-28
## poly(age, 4)2 -478.31581 39.9147851 -11.983424 2.355831e-32
## poly(age, 4)3  125.52169 39.9147851   3.144742 1.678622e-03
## poly(age, 4)4  -77.91118 39.9147851  -1.951938 5.103865e-02
fit1 = lm(wage ~ poly(age, 1), data = Wage)
fit2 = lm(wage~ poly(age, 2), data = Wage)
fit3 = lm(wage ~ poly(age, 3), data = Wage)
fit4 = lm(wage ~ poly(age, 4), data = Wage)
fit5 = lm(wage ~ poly(age, 5), data = Wage)


anova(fit1, fit2, fit3, fit4, fit5)
## Analysis of Variance Table
## 
## Model 1: wage ~ poly(age, 1)
## Model 2: wage ~ poly(age, 2)
## Model 3: wage ~ poly(age, 3)
## Model 4: wage ~ poly(age, 4)
## Model 5: wage ~ poly(age, 5)
##   Res.Df     RSS Df Sum of Sq        F    Pr(>F)    
## 1   2998 5022216                                    
## 2   2997 4793430  1    228786 143.5931 < 2.2e-16 ***
## 3   2996 4777674  1     15756   9.8888  0.001679 ** 
## 4   2995 4771604  1      6070   3.8098  0.051046 .  
## 5   2994 4770322  1      1283   0.8050  0.369682    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# creating values for all ages in the data set
age.grid = seq(from = range(Wage$age)[1], to = range(Wage$age)[2])
# predicting wage for all values of age in the original data set
fit4_preds = predict(fit4, newdata = list(age = age.grid))

# plotting the raw data of the original data set
plot(wage ~ age, data = Wage, col = "darkgrey")
# overlaying the predicted values of wage on top of the original data set
lines(age.grid, fit4_preds, col = "red", lwd = 2)

  1. Fit a step function to predict wage using age, and perform crossvalidation to choose the optimal number of cuts. Make a plot of the fit obtained.
cut(Wage$age, 10)
##    [1] (17.9,24.2] (17.9,24.2] (42.8,49]   (42.8,49]   (49,55.2]   (49,55.2]  
##    [7] (42.8,49]   (24.2,30.4] (36.6,42.8] (49,55.2]   (42.8,49]   (30.4,36.6]
##   [13] (30.4,36.6] (36.6,42.8] (49,55.2]   (49,55.2]   (36.6,42.8] (49,55.2]  
##   [19] (55.2,61.4] (36.6,42.8] (36.6,42.8] (36.6,42.8] (73.8,80.1] (36.6,42.8]
##   [25] (36.6,42.8] (42.8,49]   (42.8,49]   (30.4,36.6] (55.2,61.4] (17.9,24.2]
##   [31] (49,55.2]   (49,55.2]   (30.4,36.6] (30.4,36.6] (30.4,36.6] (55.2,61.4]
##   [37] (67.6,73.8] (24.2,30.4] (30.4,36.6] (24.2,30.4] (24.2,30.4] (24.2,30.4]
##   [43] (42.8,49]   (49,55.2]   (36.6,42.8] (49,55.2]   (30.4,36.6] (55.2,61.4]
##   [49] (24.2,30.4] (30.4,36.6] (55.2,61.4] (67.6,73.8] (42.8,49]   (17.9,24.2]
##   [55] (24.2,30.4] (17.9,24.2] (55.2,61.4] (24.2,30.4] (55.2,61.4] (30.4,36.6]
##   [61] (42.8,49]   (49,55.2]   (67.6,73.8] (36.6,42.8] (42.8,49]   (42.8,49]  
##   [67] (36.6,42.8] (36.6,42.8] (49,55.2]   (17.9,24.2] (55.2,61.4] (30.4,36.6]
##   [73] (24.2,30.4] (30.4,36.6] (36.6,42.8] (42.8,49]   (55.2,61.4] (17.9,24.2]
##   [79] (61.4,67.6] (42.8,49]   (42.8,49]   (55.2,61.4] (49,55.2]   (17.9,24.2]
##   [85] (36.6,42.8] (24.2,30.4] (30.4,36.6] (49,55.2]   (49,55.2]   (67.6,73.8]
##   [91] (42.8,49]   (42.8,49]   (30.4,36.6] (30.4,36.6] (17.9,24.2] (73.8,80.1]
##   [97] (36.6,42.8] (42.8,49]   (42.8,49]   (30.4,36.6] (61.4,67.6] (36.6,42.8]
##  [103] (49,55.2]   (30.4,36.6] (49,55.2]   (42.8,49]   (36.6,42.8] (61.4,67.6]
##  [109] (36.6,42.8] (30.4,36.6] (24.2,30.4] (61.4,67.6] (36.6,42.8] (36.6,42.8]
##  [115] (36.6,42.8] (49,55.2]   (49,55.2]   (49,55.2]   (36.6,42.8] (42.8,49]  
##  [121] (36.6,42.8] (42.8,49]   (36.6,42.8] (55.2,61.4] (55.2,61.4] (24.2,30.4]
##  [127] (42.8,49]   (36.6,42.8] (36.6,42.8] (55.2,61.4] (42.8,49]   (49,55.2]  
##  [133] (42.8,49]   (55.2,61.4] (42.8,49]   (17.9,24.2] (55.2,61.4] (30.4,36.6]
##  [139] (55.2,61.4] (30.4,36.6] (24.2,30.4] (30.4,36.6] (36.6,42.8] (17.9,24.2]
##  [145] (49,55.2]   (42.8,49]   (30.4,36.6] (55.2,61.4] (36.6,42.8] (30.4,36.6]
##  [151] (30.4,36.6] (42.8,49]   (42.8,49]   (30.4,36.6] (55.2,61.4] (36.6,42.8]
##  [157] (49,55.2]   (49,55.2]   (55.2,61.4] (61.4,67.6] (42.8,49]   (30.4,36.6]
##  [163] (49,55.2]   (42.8,49]   (55.2,61.4] (42.8,49]   (42.8,49]   (42.8,49]  
##  [169] (49,55.2]   (49,55.2]   (42.8,49]   (30.4,36.6] (49,55.2]   (36.6,42.8]
##  [175] (49,55.2]   (36.6,42.8] (36.6,42.8] (49,55.2]   (49,55.2]   (42.8,49]  
##  [181] (42.8,49]   (24.2,30.4] (36.6,42.8] (42.8,49]   (36.6,42.8] (49,55.2]  
##  [187] (24.2,30.4] (36.6,42.8] (24.2,30.4] (30.4,36.6] (55.2,61.4] (24.2,30.4]
##  [193] (24.2,30.4] (36.6,42.8] (49,55.2]   (30.4,36.6] (42.8,49]   (24.2,30.4]
##  [199] (24.2,30.4] (36.6,42.8] (24.2,30.4] (42.8,49]   (42.8,49]   (17.9,24.2]
##  [205] (42.8,49]   (30.4,36.6] (61.4,67.6] (42.8,49]   (36.6,42.8] (24.2,30.4]
##  [211] (24.2,30.4] (36.6,42.8] (30.4,36.6] (42.8,49]   (55.2,61.4] (36.6,42.8]
##  [217] (36.6,42.8] (24.2,30.4] (36.6,42.8] (61.4,67.6] (24.2,30.4] (36.6,42.8]
##  [223] (55.2,61.4] (30.4,36.6] (17.9,24.2] (42.8,49]   (24.2,30.4] (42.8,49]  
##  [229] (30.4,36.6] (49,55.2]   (61.4,67.6] (36.6,42.8] (49,55.2]   (42.8,49]  
##  [235] (17.9,24.2] (30.4,36.6] (42.8,49]   (49,55.2]   (55.2,61.4] (55.2,61.4]
##  [241] (42.8,49]   (42.8,49]   (30.4,36.6] (30.4,36.6] (24.2,30.4] (17.9,24.2]
##  [247] (36.6,42.8] (36.6,42.8] (30.4,36.6] (36.6,42.8] (42.8,49]   (42.8,49]  
##  [253] (42.8,49]   (30.4,36.6] (42.8,49]   (36.6,42.8] (30.4,36.6] (55.2,61.4]
##  [259] (55.2,61.4] (67.6,73.8] (24.2,30.4] (42.8,49]   (24.2,30.4] (24.2,30.4]
##  [265] (30.4,36.6] (36.6,42.8] (42.8,49]   (42.8,49]   (49,55.2]   (36.6,42.8]
##  [271] (55.2,61.4] (42.8,49]   (42.8,49]   (42.8,49]   (36.6,42.8] (24.2,30.4]
##  [277] (42.8,49]   (30.4,36.6] (42.8,49]   (49,55.2]   (17.9,24.2] (49,55.2]  
##  [283] (30.4,36.6] (36.6,42.8] (36.6,42.8] (24.2,30.4] (24.2,30.4] (24.2,30.4]
##  [289] (42.8,49]   (49,55.2]   (55.2,61.4] (36.6,42.8] (55.2,61.4] (42.8,49]  
##  [295] (49,55.2]   (24.2,30.4] (30.4,36.6] (55.2,61.4] (24.2,30.4] (49,55.2]  
##  [301] (42.8,49]   (17.9,24.2] (24.2,30.4] (24.2,30.4] (36.6,42.8] (49,55.2]  
##  [307] (17.9,24.2] (30.4,36.6] (30.4,36.6] (49,55.2]   (42.8,49]   (42.8,49]  
##  [313] (36.6,42.8] (30.4,36.6] (36.6,42.8] (36.6,42.8] (24.2,30.4] (17.9,24.2]
##  [319] (17.9,24.2] (49,55.2]   (36.6,42.8] (36.6,42.8] (24.2,30.4] (49,55.2]  
##  [325] (17.9,24.2] (55.2,61.4] (36.6,42.8] (36.6,42.8] (73.8,80.1] (49,55.2]  
##  [331] (36.6,42.8] (30.4,36.6] (49,55.2]   (17.9,24.2] (36.6,42.8] (24.2,30.4]
##  [337] (67.6,73.8] (49,55.2]   (24.2,30.4] (30.4,36.6] (49,55.2]   (42.8,49]  
##  [343] (55.2,61.4] (24.2,30.4] (42.8,49]   (36.6,42.8] (42.8,49]   (42.8,49]  
##  [349] (24.2,30.4] (55.2,61.4] (49,55.2]   (36.6,42.8] (17.9,24.2] (55.2,61.4]
##  [355] (42.8,49]   (30.4,36.6] (55.2,61.4] (36.6,42.8] (36.6,42.8] (30.4,36.6]
##  [361] (49,55.2]   (42.8,49]   (49,55.2]   (36.6,42.8] (17.9,24.2] (24.2,30.4]
##  [367] (24.2,30.4] (55.2,61.4] (42.8,49]   (49,55.2]   (36.6,42.8] (17.9,24.2]
##  [373] (30.4,36.6] (42.8,49]   (30.4,36.6] (42.8,49]   (30.4,36.6] (49,55.2]  
##  [379] (24.2,30.4] (42.8,49]   (36.6,42.8] (49,55.2]   (42.8,49]   (24.2,30.4]
##  [385] (49,55.2]   (17.9,24.2] (61.4,67.6] (24.2,30.4] (30.4,36.6] (42.8,49]  
##  [391] (24.2,30.4] (42.8,49]   (36.6,42.8] (55.2,61.4] (36.6,42.8] (42.8,49]  
##  [397] (49,55.2]   (24.2,30.4] (36.6,42.8] (36.6,42.8] (30.4,36.6] (49,55.2]  
##  [403] (30.4,36.6] (42.8,49]   (42.8,49]   (36.6,42.8] (36.6,42.8] (55.2,61.4]
##  [409] (24.2,30.4] (30.4,36.6] (49,55.2]   (36.6,42.8] (42.8,49]   (24.2,30.4]
##  [415] (42.8,49]   (42.8,49]   (49,55.2]   (55.2,61.4] (42.8,49]   (42.8,49]  
##  [421] (30.4,36.6] (55.2,61.4] (42.8,49]   (49,55.2]   (55.2,61.4] (42.8,49]  
##  [427] (30.4,36.6] (30.4,36.6] (42.8,49]   (49,55.2]   (49,55.2]   (36.6,42.8]
##  [433] (24.2,30.4] (42.8,49]   (17.9,24.2] (30.4,36.6] (42.8,49]   (55.2,61.4]
##  [439] (55.2,61.4] (55.2,61.4] (49,55.2]   (36.6,42.8] (42.8,49]   (24.2,30.4]
##  [445] (42.8,49]   (30.4,36.6] (49,55.2]   (30.4,36.6] (42.8,49]   (30.4,36.6]
##  [451] (42.8,49]   (42.8,49]   (49,55.2]   (42.8,49]   (42.8,49]   (42.8,49]  
##  [457] (30.4,36.6] (49,55.2]   (42.8,49]   (36.6,42.8] (17.9,24.2] (42.8,49]  
##  [463] (30.4,36.6] (55.2,61.4] (42.8,49]   (55.2,61.4] (36.6,42.8] (36.6,42.8]
##  [469] (30.4,36.6] (36.6,42.8] (36.6,42.8] (24.2,30.4] (49,55.2]   (36.6,42.8]
##  [475] (55.2,61.4] (42.8,49]   (49,55.2]   (30.4,36.6] (24.2,30.4] (42.8,49]  
##  [481] (49,55.2]   (36.6,42.8] (61.4,67.6] (55.2,61.4] (42.8,49]   (30.4,36.6]
##  [487] (30.4,36.6] (24.2,30.4] (49,55.2]   (36.6,42.8] (17.9,24.2] (42.8,49]  
##  [493] (61.4,67.6] (55.2,61.4] (24.2,30.4] (24.2,30.4] (42.8,49]   (36.6,42.8]
##  [499] (55.2,61.4] (49,55.2]   (49,55.2]   (24.2,30.4] (42.8,49]   (36.6,42.8]
##  [505] (42.8,49]   (36.6,42.8] (49,55.2]   (42.8,49]   (42.8,49]   (42.8,49]  
##  [511] (49,55.2]   (36.6,42.8] (17.9,24.2] (55.2,61.4] (49,55.2]   (49,55.2]  
##  [517] (49,55.2]   (36.6,42.8] (24.2,30.4] (55.2,61.4] (49,55.2]   (55.2,61.4]
##  [523] (49,55.2]   (42.8,49]   (36.6,42.8] (49,55.2]   (49,55.2]   (24.2,30.4]
##  [529] (42.8,49]   (17.9,24.2] (24.2,30.4] (36.6,42.8] (42.8,49]   (36.6,42.8]
##  [535] (30.4,36.6] (36.6,42.8] (49,55.2]   (42.8,49]   (36.6,42.8] (55.2,61.4]
##  [541] (30.4,36.6] (36.6,42.8] (55.2,61.4] (24.2,30.4] (42.8,49]   (55.2,61.4]
##  [547] (24.2,30.4] (30.4,36.6] (42.8,49]   (36.6,42.8] (49,55.2]   (49,55.2]  
##  [553] (61.4,67.6] (49,55.2]   (36.6,42.8] (30.4,36.6] (24.2,30.4] (30.4,36.6]
##  [559] (49,55.2]   (73.8,80.1] (24.2,30.4] (24.2,30.4] (30.4,36.6] (49,55.2]  
##  [565] (30.4,36.6] (42.8,49]   (49,55.2]   (30.4,36.6] (42.8,49]   (36.6,42.8]
##  [571] (42.8,49]   (36.6,42.8] (36.6,42.8] (55.2,61.4] (30.4,36.6] (17.9,24.2]
##  [577] (36.6,42.8] (36.6,42.8] (24.2,30.4] (24.2,30.4] (42.8,49]   (49,55.2]  
##  [583] (17.9,24.2] (30.4,36.6] (36.6,42.8] (30.4,36.6] (49,55.2]   (36.6,42.8]
##  [589] (49,55.2]   (61.4,67.6] (49,55.2]   (49,55.2]   (30.4,36.6] (36.6,42.8]
##  [595] (17.9,24.2] (30.4,36.6] (36.6,42.8] (24.2,30.4] (42.8,49]   (17.9,24.2]
##  [601] (42.8,49]   (61.4,67.6] (42.8,49]   (36.6,42.8] (42.8,49]   (30.4,36.6]
##  [607] (42.8,49]   (30.4,36.6] (55.2,61.4] (42.8,49]   (49,55.2]   (24.2,30.4]
##  [613] (49,55.2]   (24.2,30.4] (17.9,24.2] (17.9,24.2] (36.6,42.8] (24.2,30.4]
##  [619] (30.4,36.6] (55.2,61.4] (30.4,36.6] (30.4,36.6] (30.4,36.6] (24.2,30.4]
##  [625] (42.8,49]   (42.8,49]   (55.2,61.4] (42.8,49]   (36.6,42.8] (36.6,42.8]
##  [631] (55.2,61.4] (55.2,61.4] (36.6,42.8] (55.2,61.4] (55.2,61.4] (42.8,49]  
##  [637] (67.6,73.8] (24.2,30.4] (42.8,49]   (36.6,42.8] (24.2,30.4] (36.6,42.8]
##  [643] (49,55.2]   (42.8,49]   (42.8,49]   (36.6,42.8] (17.9,24.2] (30.4,36.6]
##  [649] (55.2,61.4] (17.9,24.2] (36.6,42.8] (30.4,36.6] (36.6,42.8] (42.8,49]  
##  [655] (55.2,61.4] (24.2,30.4] (24.2,30.4] (49,55.2]   (36.6,42.8] (42.8,49]  
##  [661] (49,55.2]   (67.6,73.8] (61.4,67.6] (24.2,30.4] (49,55.2]   (49,55.2]  
##  [667] (49,55.2]   (24.2,30.4] (55.2,61.4] (30.4,36.6] (49,55.2]   (42.8,49]  
##  [673] (49,55.2]   (49,55.2]   (49,55.2]   (17.9,24.2] (36.6,42.8] (24.2,30.4]
##  [679] (42.8,49]   (49,55.2]   (42.8,49]   (42.8,49]   (36.6,42.8] (36.6,42.8]
##  [685] (42.8,49]   (49,55.2]   (49,55.2]   (42.8,49]   (24.2,30.4] (42.8,49]  
##  [691] (42.8,49]   (24.2,30.4] (42.8,49]   (42.8,49]   (30.4,36.6] (24.2,30.4]
##  [697] (17.9,24.2] (49,55.2]   (49,55.2]   (17.9,24.2] (36.6,42.8] (49,55.2]  
##  [703] (42.8,49]   (42.8,49]   (36.6,42.8] (36.6,42.8] (36.6,42.8] (30.4,36.6]
##  [709] (30.4,36.6] (17.9,24.2] (42.8,49]   (30.4,36.6] (24.2,30.4] (36.6,42.8]
##  [715] (42.8,49]   (55.2,61.4] (24.2,30.4] (42.8,49]   (24.2,30.4] (55.2,61.4]
##  [721] (49,55.2]   (55.2,61.4] (36.6,42.8] (49,55.2]   (30.4,36.6] (42.8,49]  
##  [727] (42.8,49]   (42.8,49]   (36.6,42.8] (42.8,49]   (49,55.2]   (42.8,49]  
##  [733] (49,55.2]   (30.4,36.6] (36.6,42.8] (24.2,30.4] (42.8,49]   (36.6,42.8]
##  [739] (49,55.2]   (61.4,67.6] (30.4,36.6] (24.2,30.4] (30.4,36.6] (24.2,30.4]
##  [745] (61.4,67.6] (42.8,49]   (55.2,61.4] (55.2,61.4] (36.6,42.8] (42.8,49]  
##  [751] (17.9,24.2] (55.2,61.4] (55.2,61.4] (42.8,49]   (36.6,42.8] (67.6,73.8]
##  [757] (42.8,49]   (36.6,42.8] (30.4,36.6] (55.2,61.4] (42.8,49]   (30.4,36.6]
##  [763] (30.4,36.6] (30.4,36.6] (49,55.2]   (42.8,49]   (49,55.2]   (36.6,42.8]
##  [769] (24.2,30.4] (49,55.2]   (24.2,30.4] (24.2,30.4] (42.8,49]   (42.8,49]  
##  [775] (36.6,42.8] (17.9,24.2] (55.2,61.4] (30.4,36.6] (42.8,49]   (24.2,30.4]
##  [781] (30.4,36.6] (55.2,61.4] (42.8,49]   (17.9,24.2] (55.2,61.4] (55.2,61.4]
##  [787] (17.9,24.2] (55.2,61.4] (42.8,49]   (55.2,61.4] (24.2,30.4] (42.8,49]  
##  [793] (42.8,49]   (49,55.2]   (42.8,49]   (36.6,42.8] (42.8,49]   (30.4,36.6]
##  [799] (49,55.2]   (49,55.2]   (67.6,73.8] (24.2,30.4] (42.8,49]   (30.4,36.6]
##  [805] (36.6,42.8] (24.2,30.4] (36.6,42.8] (36.6,42.8] (49,55.2]   (30.4,36.6]
##  [811] (30.4,36.6] (42.8,49]   (55.2,61.4] (36.6,42.8] (61.4,67.6] (36.6,42.8]
##  [817] (30.4,36.6] (49,55.2]   (17.9,24.2] (36.6,42.8] (17.9,24.2] (24.2,30.4]
##  [823] (30.4,36.6] (30.4,36.6] (24.2,30.4] (24.2,30.4] (36.6,42.8] (24.2,30.4]
##  [829] (30.4,36.6] (42.8,49]   (49,55.2]   (42.8,49]   (30.4,36.6] (49,55.2]  
##  [835] (36.6,42.8] (67.6,73.8] (61.4,67.6] (36.6,42.8] (30.4,36.6] (17.9,24.2]
##  [841] (49,55.2]   (17.9,24.2] (36.6,42.8] (42.8,49]   (30.4,36.6] (36.6,42.8]
##  [847] (17.9,24.2] (61.4,67.6] (30.4,36.6] (30.4,36.6] (42.8,49]   (42.8,49]  
##  [853] (42.8,49]   (36.6,42.8] (49,55.2]   (73.8,80.1] (30.4,36.6] (61.4,67.6]
##  [859] (55.2,61.4] (24.2,30.4] (55.2,61.4] (42.8,49]   (42.8,49]   (42.8,49]  
##  [865] (24.2,30.4] (42.8,49]   (36.6,42.8] (55.2,61.4] (55.2,61.4] (42.8,49]  
##  [871] (36.6,42.8] (36.6,42.8] (42.8,49]   (42.8,49]   (36.6,42.8] (49,55.2]  
##  [877] (55.2,61.4] (36.6,42.8] (24.2,30.4] (42.8,49]   (30.4,36.6] (30.4,36.6]
##  [883] (30.4,36.6] (49,55.2]   (30.4,36.6] (36.6,42.8] (30.4,36.6] (42.8,49]  
##  [889] (42.8,49]   (55.2,61.4] (24.2,30.4] (24.2,30.4] (42.8,49]   (24.2,30.4]
##  [895] (36.6,42.8] (30.4,36.6] (30.4,36.6] (36.6,42.8] (36.6,42.8] (30.4,36.6]
##  [901] (36.6,42.8] (42.8,49]   (42.8,49]   (42.8,49]   (24.2,30.4] (42.8,49]  
##  [907] (42.8,49]   (42.8,49]   (36.6,42.8] (49,55.2]   (42.8,49]   (36.6,42.8]
##  [913] (36.6,42.8] (55.2,61.4] (36.6,42.8] (24.2,30.4] (30.4,36.6] (30.4,36.6]
##  [919] (36.6,42.8] (42.8,49]   (42.8,49]   (55.2,61.4] (24.2,30.4] (36.6,42.8]
##  [925] (67.6,73.8] (42.8,49]   (24.2,30.4] (36.6,42.8] (36.6,42.8] (42.8,49]  
##  [931] (30.4,36.6] (42.8,49]   (49,55.2]   (36.6,42.8] (36.6,42.8] (24.2,30.4]
##  [937] (30.4,36.6] (24.2,30.4] (36.6,42.8] (24.2,30.4] (24.2,30.4] (49,55.2]  
##  [943] (24.2,30.4] (49,55.2]   (61.4,67.6] (55.2,61.4] (30.4,36.6] (55.2,61.4]
##  [949] (36.6,42.8] (42.8,49]   (49,55.2]   (42.8,49]   (30.4,36.6] (42.8,49]  
##  [955] (36.6,42.8] (55.2,61.4] (24.2,30.4] (24.2,30.4] (49,55.2]   (49,55.2]  
##  [961] (49,55.2]   (36.6,42.8] (30.4,36.6] (24.2,30.4] (42.8,49]   (49,55.2]  
##  [967] (49,55.2]   (42.8,49]   (55.2,61.4] (67.6,73.8] (17.9,24.2] (30.4,36.6]
##  [973] (30.4,36.6] (61.4,67.6] (42.8,49]   (42.8,49]   (49,55.2]   (42.8,49]  
##  [979] (42.8,49]   (30.4,36.6] (55.2,61.4] (36.6,42.8] (42.8,49]   (30.4,36.6]
##  [985] (30.4,36.6] (49,55.2]   (24.2,30.4] (42.8,49]   (30.4,36.6] (49,55.2]  
##  [991] (24.2,30.4] (30.4,36.6] (30.4,36.6] (49,55.2]   (30.4,36.6] (55.2,61.4]
##  [997] (61.4,67.6] (24.2,30.4] (36.6,42.8] (49,55.2]   (24.2,30.4] (30.4,36.6]
## [1003] (24.2,30.4] (61.4,67.6] (42.8,49]   (42.8,49]   (30.4,36.6] (42.8,49]  
## [1009] (42.8,49]   (55.2,61.4] (42.8,49]   (49,55.2]   (30.4,36.6] (49,55.2]  
## [1015] (55.2,61.4] (49,55.2]   (55.2,61.4] (42.8,49]   (55.2,61.4] (24.2,30.4]
## [1021] (17.9,24.2] (55.2,61.4] (55.2,61.4] (42.8,49]   (36.6,42.8] (30.4,36.6]
## [1027] (49,55.2]   (42.8,49]   (42.8,49]   (42.8,49]   (24.2,30.4] (17.9,24.2]
## [1033] (36.6,42.8] (30.4,36.6] (67.6,73.8] (49,55.2]   (30.4,36.6] (24.2,30.4]
## [1039] (24.2,30.4] (36.6,42.8] (17.9,24.2] (42.8,49]   (24.2,30.4] (36.6,42.8]
## [1045] (49,55.2]   (42.8,49]   (30.4,36.6] (42.8,49]   (24.2,30.4] (30.4,36.6]
## [1051] (30.4,36.6] (49,55.2]   (42.8,49]   (42.8,49]   (49,55.2]   (42.8,49]  
## [1057] (24.2,30.4] (55.2,61.4] (61.4,67.6] (61.4,67.6] (30.4,36.6] (24.2,30.4]
## [1063] (49,55.2]   (24.2,30.4] (30.4,36.6] (24.2,30.4] (36.6,42.8] (30.4,36.6]
## [1069] (42.8,49]   (36.6,42.8] (36.6,42.8] (55.2,61.4] (49,55.2]   (24.2,30.4]
## [1075] (30.4,36.6] (30.4,36.6] (17.9,24.2] (49,55.2]   (24.2,30.4] (42.8,49]  
## [1081] (30.4,36.6] (49,55.2]   (30.4,36.6] (30.4,36.6] (49,55.2]   (36.6,42.8]
## [1087] (36.6,42.8] (30.4,36.6] (61.4,67.6] (36.6,42.8] (61.4,67.6] (36.6,42.8]
## [1093] (30.4,36.6] (36.6,42.8] (42.8,49]   (55.2,61.4] (55.2,61.4] (17.9,24.2]
## [1099] (17.9,24.2] (49,55.2]   (42.8,49]   (30.4,36.6] (30.4,36.6] (36.6,42.8]
## [1105] (49,55.2]   (24.2,30.4] (30.4,36.6] (30.4,36.6] (55.2,61.4] (36.6,42.8]
## [1111] (36.6,42.8] (30.4,36.6] (30.4,36.6] (17.9,24.2] (42.8,49]   (55.2,61.4]
## [1117] (24.2,30.4] (30.4,36.6] (42.8,49]   (24.2,30.4] (30.4,36.6] (49,55.2]  
## [1123] (36.6,42.8] (42.8,49]   (61.4,67.6] (36.6,42.8] (36.6,42.8] (42.8,49]  
## [1129] (42.8,49]   (42.8,49]   (24.2,30.4] (61.4,67.6] (49,55.2]   (49,55.2]  
## [1135] (42.8,49]   (24.2,30.4] (36.6,42.8] (49,55.2]   (49,55.2]   (30.4,36.6]
## [1141] (30.4,36.6] (36.6,42.8] (30.4,36.6] (30.4,36.6] (42.8,49]   (61.4,67.6]
## [1147] (30.4,36.6] (42.8,49]   (42.8,49]   (42.8,49]   (42.8,49]   (42.8,49]  
## [1153] (49,55.2]   (24.2,30.4] (49,55.2]   (42.8,49]   (36.6,42.8] (42.8,49]  
## [1159] (49,55.2]   (36.6,42.8] (30.4,36.6] (24.2,30.4] (30.4,36.6] (42.8,49]  
## [1165] (36.6,42.8] (30.4,36.6] (42.8,49]   (49,55.2]   (42.8,49]   (30.4,36.6]
## [1171] (36.6,42.8] (49,55.2]   (17.9,24.2] (30.4,36.6] (61.4,67.6] (24.2,30.4]
## [1177] (24.2,30.4] (42.8,49]   (30.4,36.6] (42.8,49]   (42.8,49]   (67.6,73.8]
## [1183] (36.6,42.8] (36.6,42.8] (30.4,36.6] (73.8,80.1] (17.9,24.2] (30.4,36.6]
## [1189] (24.2,30.4] (49,55.2]   (24.2,30.4] (61.4,67.6] (36.6,42.8] (36.6,42.8]
## [1195] (30.4,36.6] (49,55.2]   (30.4,36.6] (36.6,42.8] (42.8,49]   (42.8,49]  
## [1201] (30.4,36.6] (36.6,42.8] (49,55.2]   (49,55.2]   (55.2,61.4] (42.8,49]  
## [1207] (42.8,49]   (17.9,24.2] (55.2,61.4] (36.6,42.8] (42.8,49]   (49,55.2]  
## [1213] (49,55.2]   (30.4,36.6] (30.4,36.6] (42.8,49]   (36.6,42.8] (61.4,67.6]
## [1219] (42.8,49]   (24.2,30.4] (55.2,61.4] (24.2,30.4] (42.8,49]   (24.2,30.4]
## [1225] (55.2,61.4] (36.6,42.8] (30.4,36.6] (49,55.2]   (42.8,49]   (42.8,49]  
## [1231] (49,55.2]   (36.6,42.8] (36.6,42.8] (42.8,49]   (42.8,49]   (24.2,30.4]
## [1237] (55.2,61.4] (55.2,61.4] (42.8,49]   (42.8,49]   (42.8,49]   (55.2,61.4]
## [1243] (30.4,36.6] (36.6,42.8] (36.6,42.8] (36.6,42.8] (24.2,30.4] (36.6,42.8]
## [1249] (55.2,61.4] (17.9,24.2] (30.4,36.6] (24.2,30.4] (42.8,49]   (24.2,30.4]
## [1255] (36.6,42.8] (30.4,36.6] (49,55.2]   (17.9,24.2] (49,55.2]   (36.6,42.8]
## [1261] (42.8,49]   (55.2,61.4] (42.8,49]   (61.4,67.6] (24.2,30.4] (36.6,42.8]
## [1267] (36.6,42.8] (17.9,24.2] (42.8,49]   (30.4,36.6] (42.8,49]   (49,55.2]  
## [1273] (49,55.2]   (49,55.2]   (24.2,30.4] (42.8,49]   (42.8,49]   (24.2,30.4]
## [1279] (36.6,42.8] (24.2,30.4] (55.2,61.4] (36.6,42.8] (36.6,42.8] (30.4,36.6]
## [1285] (55.2,61.4] (36.6,42.8] (24.2,30.4] (30.4,36.6] (36.6,42.8] (24.2,30.4]
## [1291] (24.2,30.4] (24.2,30.4] (30.4,36.6] (36.6,42.8] (49,55.2]   (55.2,61.4]
## [1297] (36.6,42.8] (30.4,36.6] (24.2,30.4] (49,55.2]   (49,55.2]   (24.2,30.4]
## [1303] (55.2,61.4] (61.4,67.6] (49,55.2]   (36.6,42.8] (17.9,24.2] (42.8,49]  
## [1309] (30.4,36.6] (55.2,61.4] (36.6,42.8] (55.2,61.4] (30.4,36.6] (24.2,30.4]
## [1315] (55.2,61.4] (42.8,49]   (36.6,42.8] (49,55.2]   (24.2,30.4] (17.9,24.2]
## [1321] (42.8,49]   (42.8,49]   (30.4,36.6] (17.9,24.2] (30.4,36.6] (36.6,42.8]
## [1327] (49,55.2]   (49,55.2]   (17.9,24.2] (30.4,36.6] (24.2,30.4] (36.6,42.8]
## [1333] (24.2,30.4] (30.4,36.6] (30.4,36.6] (36.6,42.8] (36.6,42.8] (17.9,24.2]
## [1339] (36.6,42.8] (36.6,42.8] (42.8,49]   (42.8,49]   (36.6,42.8] (49,55.2]  
## [1345] (24.2,30.4] (42.8,49]   (55.2,61.4] (49,55.2]   (17.9,24.2] (61.4,67.6]
## [1351] (36.6,42.8] (42.8,49]   (49,55.2]   (24.2,30.4] (36.6,42.8] (49,55.2]  
## [1357] (36.6,42.8] (42.8,49]   (42.8,49]   (42.8,49]   (30.4,36.6] (24.2,30.4]
## [1363] (42.8,49]   (55.2,61.4] (42.8,49]   (36.6,42.8] (42.8,49]   (24.2,30.4]
## [1369] (17.9,24.2] (42.8,49]   (42.8,49]   (55.2,61.4] (36.6,42.8] (42.8,49]  
## [1375] (49,55.2]   (49,55.2]   (42.8,49]   (42.8,49]   (36.6,42.8] (42.8,49]  
## [1381] (42.8,49]   (42.8,49]   (42.8,49]   (55.2,61.4] (73.8,80.1] (42.8,49]  
## [1387] (55.2,61.4] (36.6,42.8] (42.8,49]   (42.8,49]   (55.2,61.4] (42.8,49]  
## [1393] (36.6,42.8] (24.2,30.4] (55.2,61.4] (61.4,67.6] (42.8,49]   (36.6,42.8]
## [1399] (30.4,36.6] (55.2,61.4] (36.6,42.8] (17.9,24.2] (42.8,49]   (24.2,30.4]
## [1405] (17.9,24.2] (24.2,30.4] (49,55.2]   (24.2,30.4] (30.4,36.6] (36.6,42.8]
## [1411] (36.6,42.8] (42.8,49]   (30.4,36.6] (61.4,67.6] (17.9,24.2] (24.2,30.4]
## [1417] (36.6,42.8] (17.9,24.2] (36.6,42.8] (55.2,61.4] (42.8,49]   (61.4,67.6]
## [1423] (42.8,49]   (49,55.2]   (36.6,42.8] (30.4,36.6] (36.6,42.8] (49,55.2]  
## [1429] (42.8,49]   (49,55.2]   (49,55.2]   (30.4,36.6] (42.8,49]   (49,55.2]  
## [1435] (30.4,36.6] (36.6,42.8] (30.4,36.6] (49,55.2]   (36.6,42.8] (30.4,36.6]
## [1441] (36.6,42.8] (42.8,49]   (42.8,49]   (49,55.2]   (36.6,42.8] (24.2,30.4]
## [1447] (24.2,30.4] (30.4,36.6] (49,55.2]   (24.2,30.4] (30.4,36.6] (36.6,42.8]
## [1453] (55.2,61.4] (30.4,36.6] (24.2,30.4] (49,55.2]   (30.4,36.6] (24.2,30.4]
## [1459] (49,55.2]   (42.8,49]   (36.6,42.8] (24.2,30.4] (30.4,36.6] (49,55.2]  
## [1465] (61.4,67.6] (30.4,36.6] (17.9,24.2] (49,55.2]   (61.4,67.6] (61.4,67.6]
## [1471] (36.6,42.8] (24.2,30.4] (42.8,49]   (55.2,61.4] (36.6,42.8] (42.8,49]  
## [1477] (61.4,67.6] (30.4,36.6] (49,55.2]   (24.2,30.4] (42.8,49]   (55.2,61.4]
## [1483] (17.9,24.2] (55.2,61.4] (61.4,67.6] (61.4,67.6] (42.8,49]   (49,55.2]  
## [1489] (42.8,49]   (42.8,49]   (36.6,42.8] (30.4,36.6] (36.6,42.8] (17.9,24.2]
## [1495] (49,55.2]   (42.8,49]   (30.4,36.6] (42.8,49]   (30.4,36.6] (30.4,36.6]
## [1501] (42.8,49]   (36.6,42.8] (42.8,49]   (49,55.2]   (49,55.2]   (42.8,49]  
## [1507] (42.8,49]   (36.6,42.8] (17.9,24.2] (55.2,61.4] (55.2,61.4] (55.2,61.4]
## [1513] (42.8,49]   (42.8,49]   (24.2,30.4] (36.6,42.8] (24.2,30.4] (24.2,30.4]
## [1519] (36.6,42.8] (42.8,49]   (36.6,42.8] (30.4,36.6] (42.8,49]   (42.8,49]  
## [1525] (42.8,49]   (55.2,61.4] (36.6,42.8] (67.6,73.8] (24.2,30.4] (42.8,49]  
## [1531] (36.6,42.8] (36.6,42.8] (55.2,61.4] (42.8,49]   (36.6,42.8] (24.2,30.4]
## [1537] (49,55.2]   (42.8,49]   (36.6,42.8] (24.2,30.4] (24.2,30.4] (30.4,36.6]
## [1543] (42.8,49]   (17.9,24.2] (36.6,42.8] (24.2,30.4] (49,55.2]   (42.8,49]  
## [1549] (49,55.2]   (49,55.2]   (42.8,49]   (17.9,24.2] (36.6,42.8] (67.6,73.8]
## [1555] (36.6,42.8] (49,55.2]   (30.4,36.6] (55.2,61.4] (36.6,42.8] (42.8,49]  
## [1561] (55.2,61.4] (61.4,67.6] (36.6,42.8] (42.8,49]   (24.2,30.4] (73.8,80.1]
## [1567] (49,55.2]   (55.2,61.4] (49,55.2]   (42.8,49]   (36.6,42.8] (36.6,42.8]
## [1573] (30.4,36.6] (42.8,49]   (42.8,49]   (36.6,42.8] (49,55.2]   (36.6,42.8]
## [1579] (49,55.2]   (36.6,42.8] (36.6,42.8] (61.4,67.6] (17.9,24.2] (61.4,67.6]
## [1585] (42.8,49]   (24.2,30.4] (42.8,49]   (30.4,36.6] (36.6,42.8] (24.2,30.4]
## [1591] (61.4,67.6] (42.8,49]   (42.8,49]   (24.2,30.4] (30.4,36.6] (24.2,30.4]
## [1597] (30.4,36.6] (49,55.2]   (36.6,42.8] (17.9,24.2] (24.2,30.4] (42.8,49]  
## [1603] (42.8,49]   (24.2,30.4] (42.8,49]   (36.6,42.8] (49,55.2]   (55.2,61.4]
## [1609] (24.2,30.4] (61.4,67.6] (42.8,49]   (30.4,36.6] (17.9,24.2] (61.4,67.6]
## [1615] (55.2,61.4] (42.8,49]   (42.8,49]   (55.2,61.4] (30.4,36.6] (17.9,24.2]
## [1621] (24.2,30.4] (36.6,42.8] (42.8,49]   (55.2,61.4] (30.4,36.6] (42.8,49]  
## [1627] (30.4,36.6] (17.9,24.2] (49,55.2]   (55.2,61.4] (17.9,24.2] (42.8,49]  
## [1633] (49,55.2]   (49,55.2]   (36.6,42.8] (30.4,36.6] (49,55.2]   (17.9,24.2]
## [1639] (49,55.2]   (30.4,36.6] (24.2,30.4] (17.9,24.2] (55.2,61.4] (42.8,49]  
## [1645] (30.4,36.6] (36.6,42.8] (36.6,42.8] (30.4,36.6] (42.8,49]   (24.2,30.4]
## [1651] (30.4,36.6] (36.6,42.8] (49,55.2]   (49,55.2]   (30.4,36.6] (24.2,30.4]
## [1657] (55.2,61.4] (42.8,49]   (36.6,42.8] (55.2,61.4] (49,55.2]   (49,55.2]  
## [1663] (30.4,36.6] (42.8,49]   (42.8,49]   (61.4,67.6] (42.8,49]   (36.6,42.8]
## [1669] (30.4,36.6] (42.8,49]   (17.9,24.2] (49,55.2]   (42.8,49]   (49,55.2]  
## [1675] (30.4,36.6] (17.9,24.2] (55.2,61.4] (49,55.2]   (42.8,49]   (17.9,24.2]
## [1681] (49,55.2]   (61.4,67.6] (36.6,42.8] (17.9,24.2] (30.4,36.6] (42.8,49]  
## [1687] (30.4,36.6] (30.4,36.6] (30.4,36.6] (42.8,49]   (49,55.2]   (30.4,36.6]
## [1693] (42.8,49]   (36.6,42.8] (36.6,42.8] (17.9,24.2] (55.2,61.4] (55.2,61.4]
## [1699] (42.8,49]   (24.2,30.4] (36.6,42.8] (55.2,61.4] (36.6,42.8] (55.2,61.4]
## [1705] (30.4,36.6] (24.2,30.4] (49,55.2]   (36.6,42.8] (49,55.2]   (49,55.2]  
## [1711] (30.4,36.6] (36.6,42.8] (42.8,49]   (36.6,42.8] (55.2,61.4] (24.2,30.4]
## [1717] (36.6,42.8] (30.4,36.6] (24.2,30.4] (36.6,42.8] (49,55.2]   (30.4,36.6]
## [1723] (49,55.2]   (42.8,49]   (49,55.2]   (17.9,24.2] (36.6,42.8] (49,55.2]  
## [1729] (17.9,24.2] (42.8,49]   (30.4,36.6] (30.4,36.6] (42.8,49]   (55.2,61.4]
## [1735] (36.6,42.8] (42.8,49]   (42.8,49]   (55.2,61.4] (49,55.2]   (36.6,42.8]
## [1741] (30.4,36.6] (49,55.2]   (42.8,49]   (49,55.2]   (36.6,42.8] (42.8,49]  
## [1747] (49,55.2]   (36.6,42.8] (55.2,61.4] (49,55.2]   (24.2,30.4] (30.4,36.6]
## [1753] (24.2,30.4] (30.4,36.6] (42.8,49]   (36.6,42.8] (49,55.2]   (42.8,49]  
## [1759] (49,55.2]   (49,55.2]   (36.6,42.8] (42.8,49]   (36.6,42.8] (42.8,49]  
## [1765] (30.4,36.6] (30.4,36.6] (42.8,49]   (17.9,24.2] (42.8,49]   (55.2,61.4]
## [1771] (36.6,42.8] (17.9,24.2] (49,55.2]   (61.4,67.6] (42.8,49]   (30.4,36.6]
## [1777] (36.6,42.8] (30.4,36.6] (36.6,42.8] (36.6,42.8] (36.6,42.8] (49,55.2]  
## [1783] (30.4,36.6] (42.8,49]   (24.2,30.4] (17.9,24.2] (55.2,61.4] (17.9,24.2]
## [1789] (61.4,67.6] (49,55.2]   (17.9,24.2] (61.4,67.6] (49,55.2]   (36.6,42.8]
## [1795] (49,55.2]   (24.2,30.4] (36.6,42.8] (67.6,73.8] (17.9,24.2] (42.8,49]  
## [1801] (30.4,36.6] (42.8,49]   (49,55.2]   (49,55.2]   (30.4,36.6] (55.2,61.4]
## [1807] (17.9,24.2] (55.2,61.4] (36.6,42.8] (55.2,61.4] (30.4,36.6] (30.4,36.6]
## [1813] (30.4,36.6] (24.2,30.4] (55.2,61.4] (36.6,42.8] (49,55.2]   (30.4,36.6]
## [1819] (42.8,49]   (61.4,67.6] (42.8,49]   (30.4,36.6] (36.6,42.8] (17.9,24.2]
## [1825] (49,55.2]   (55.2,61.4] (49,55.2]   (30.4,36.6] (42.8,49]   (36.6,42.8]
## [1831] (24.2,30.4] (30.4,36.6] (42.8,49]   (55.2,61.4] (36.6,42.8] (30.4,36.6]
## [1837] (24.2,30.4] (36.6,42.8] (36.6,42.8] (49,55.2]   (49,55.2]   (36.6,42.8]
## [1843] (36.6,42.8] (30.4,36.6] (17.9,24.2] (36.6,42.8] (36.6,42.8] (49,55.2]  
## [1849] (73.8,80.1] (55.2,61.4] (24.2,30.4] (24.2,30.4] (24.2,30.4] (24.2,30.4]
## [1855] (30.4,36.6] (49,55.2]   (17.9,24.2] (42.8,49]   (30.4,36.6] (42.8,49]  
## [1861] (30.4,36.6] (42.8,49]   (42.8,49]   (42.8,49]   (36.6,42.8] (49,55.2]  
## [1867] (30.4,36.6] (55.2,61.4] (42.8,49]   (49,55.2]   (55.2,61.4] (55.2,61.4]
## [1873] (30.4,36.6] (55.2,61.4] (36.6,42.8] (17.9,24.2] (42.8,49]   (49,55.2]  
## [1879] (42.8,49]   (30.4,36.6] (24.2,30.4] (49,55.2]   (36.6,42.8] (49,55.2]  
## [1885] (36.6,42.8] (30.4,36.6] (30.4,36.6] (30.4,36.6] (36.6,42.8] (36.6,42.8]
## [1891] (36.6,42.8] (55.2,61.4] (42.8,49]   (42.8,49]   (24.2,30.4] (30.4,36.6]
## [1897] (42.8,49]   (55.2,61.4] (42.8,49]   (24.2,30.4] (42.8,49]   (30.4,36.6]
## [1903] (36.6,42.8] (42.8,49]   (55.2,61.4] (36.6,42.8] (36.6,42.8] (61.4,67.6]
## [1909] (36.6,42.8] (42.8,49]   (55.2,61.4] (49,55.2]   (36.6,42.8] (49,55.2]  
## [1915] (24.2,30.4] (49,55.2]   (49,55.2]   (49,55.2]   (24.2,30.4] (42.8,49]  
## [1921] (55.2,61.4] (36.6,42.8] (17.9,24.2] (49,55.2]   (49,55.2]   (42.8,49]  
## [1927] (49,55.2]   (30.4,36.6] (49,55.2]   (42.8,49]   (42.8,49]   (42.8,49]  
## [1933] (17.9,24.2] (42.8,49]   (42.8,49]   (17.9,24.2] (55.2,61.4] (42.8,49]  
## [1939] (17.9,24.2] (36.6,42.8] (30.4,36.6] (30.4,36.6] (42.8,49]   (55.2,61.4]
## [1945] (24.2,30.4] (61.4,67.6] (30.4,36.6] (42.8,49]   (24.2,30.4] (36.6,42.8]
## [1951] (30.4,36.6] (36.6,42.8] (30.4,36.6] (49,55.2]   (42.8,49]   (30.4,36.6]
## [1957] (36.6,42.8] (55.2,61.4] (42.8,49]   (30.4,36.6] (24.2,30.4] (17.9,24.2]
## [1963] (36.6,42.8] (24.2,30.4] (49,55.2]   (17.9,24.2] (55.2,61.4] (42.8,49]  
## [1969] (30.4,36.6] (42.8,49]   (42.8,49]   (24.2,30.4] (36.6,42.8] (24.2,30.4]
## [1975] (30.4,36.6] (36.6,42.8] (36.6,42.8] (17.9,24.2] (42.8,49]   (24.2,30.4]
## [1981] (55.2,61.4] (30.4,36.6] (55.2,61.4] (24.2,30.4] (36.6,42.8] (17.9,24.2]
## [1987] (36.6,42.8] (17.9,24.2] (36.6,42.8] (42.8,49]   (42.8,49]   (30.4,36.6]
## [1993] (42.8,49]   (49,55.2]   (30.4,36.6] (61.4,67.6] (42.8,49]   (42.8,49]  
## [1999] (49,55.2]   (30.4,36.6] (36.6,42.8] (30.4,36.6] (49,55.2]   (49,55.2]  
## [2005] (49,55.2]   (55.2,61.4] (49,55.2]   (42.8,49]   (24.2,30.4] (30.4,36.6]
## [2011] (49,55.2]   (49,55.2]   (49,55.2]   (36.6,42.8] (30.4,36.6] (30.4,36.6]
## [2017] (42.8,49]   (49,55.2]   (30.4,36.6] (61.4,67.6] (30.4,36.6] (42.8,49]  
## [2023] (73.8,80.1] (42.8,49]   (55.2,61.4] (49,55.2]   (55.2,61.4] (30.4,36.6]
## [2029] (24.2,30.4] (36.6,42.8] (55.2,61.4] (55.2,61.4] (55.2,61.4] (30.4,36.6]
## [2035] (36.6,42.8] (30.4,36.6] (42.8,49]   (30.4,36.6] (17.9,24.2] (55.2,61.4]
## [2041] (30.4,36.6] (42.8,49]   (24.2,30.4] (36.6,42.8] (55.2,61.4] (17.9,24.2]
## [2047] (55.2,61.4] (24.2,30.4] (49,55.2]   (36.6,42.8] (49,55.2]   (24.2,30.4]
## [2053] (36.6,42.8] (36.6,42.8] (67.6,73.8] (30.4,36.6] (42.8,49]   (42.8,49]  
## [2059] (36.6,42.8] (55.2,61.4] (30.4,36.6] (42.8,49]   (30.4,36.6] (17.9,24.2]
## [2065] (30.4,36.6] (24.2,30.4] (49,55.2]   (42.8,49]   (49,55.2]   (49,55.2]  
## [2071] (55.2,61.4] (42.8,49]   (24.2,30.4] (30.4,36.6] (49,55.2]   (42.8,49]  
## [2077] (30.4,36.6] (49,55.2]   (36.6,42.8] (42.8,49]   (36.6,42.8] (17.9,24.2]
## [2083] (49,55.2]   (36.6,42.8] (42.8,49]   (30.4,36.6] (30.4,36.6] (42.8,49]  
## [2089] (55.2,61.4] (42.8,49]   (17.9,24.2] (24.2,30.4] (30.4,36.6] (49,55.2]  
## [2095] (55.2,61.4] (17.9,24.2] (30.4,36.6] (17.9,24.2] (42.8,49]   (49,55.2]  
## [2101] (42.8,49]   (36.6,42.8] (49,55.2]   (42.8,49]   (42.8,49]   (49,55.2]  
## [2107] (36.6,42.8] (36.6,42.8] (55.2,61.4] (36.6,42.8] (49,55.2]   (49,55.2]  
## [2113] (42.8,49]   (42.8,49]   (30.4,36.6] (42.8,49]   (55.2,61.4] (55.2,61.4]
## [2119] (36.6,42.8] (42.8,49]   (49,55.2]   (49,55.2]   (36.6,42.8] (24.2,30.4]
## [2125] (61.4,67.6] (55.2,61.4] (30.4,36.6] (36.6,42.8] (42.8,49]   (24.2,30.4]
## [2131] (49,55.2]   (42.8,49]   (55.2,61.4] (55.2,61.4] (49,55.2]   (49,55.2]  
## [2137] (36.6,42.8] (61.4,67.6] (36.6,42.8] (36.6,42.8] (49,55.2]   (55.2,61.4]
## [2143] (42.8,49]   (36.6,42.8] (24.2,30.4] (55.2,61.4] (42.8,49]   (55.2,61.4]
## [2149] (24.2,30.4] (49,55.2]   (30.4,36.6] (61.4,67.6] (36.6,42.8] (24.2,30.4]
## [2155] (49,55.2]   (36.6,42.8] (24.2,30.4] (36.6,42.8] (55.2,61.4] (42.8,49]  
## [2161] (17.9,24.2] (30.4,36.6] (36.6,42.8] (24.2,30.4] (36.6,42.8] (42.8,49]  
## [2167] (49,55.2]   (73.8,80.1] (36.6,42.8] (30.4,36.6] (36.6,42.8] (36.6,42.8]
## [2173] (42.8,49]   (49,55.2]   (36.6,42.8] (42.8,49]   (17.9,24.2] (55.2,61.4]
## [2179] (24.2,30.4] (24.2,30.4] (30.4,36.6] (42.8,49]   (49,55.2]   (61.4,67.6]
## [2185] (55.2,61.4] (17.9,24.2] (36.6,42.8] (24.2,30.4] (36.6,42.8] (36.6,42.8]
## [2191] (42.8,49]   (42.8,49]   (36.6,42.8] (49,55.2]   (36.6,42.8] (49,55.2]  
## [2197] (55.2,61.4] (55.2,61.4] (36.6,42.8] (42.8,49]   (49,55.2]   (30.4,36.6]
## [2203] (55.2,61.4] (36.6,42.8] (30.4,36.6] (24.2,30.4] (42.8,49]   (49,55.2]  
## [2209] (30.4,36.6] (24.2,30.4] (17.9,24.2] (42.8,49]   (55.2,61.4] (36.6,42.8]
## [2215] (30.4,36.6] (42.8,49]   (36.6,42.8] (61.4,67.6] (30.4,36.6] (55.2,61.4]
## [2221] (30.4,36.6] (49,55.2]   (30.4,36.6] (30.4,36.6] (30.4,36.6] (36.6,42.8]
## [2227] (55.2,61.4] (42.8,49]   (36.6,42.8] (42.8,49]   (24.2,30.4] (55.2,61.4]
## [2233] (36.6,42.8] (36.6,42.8] (49,55.2]   (61.4,67.6] (49,55.2]   (24.2,30.4]
## [2239] (49,55.2]   (17.9,24.2] (30.4,36.6] (17.9,24.2] (42.8,49]   (42.8,49]  
## [2245] (36.6,42.8] (36.6,42.8] (61.4,67.6] (42.8,49]   (30.4,36.6] (36.6,42.8]
## [2251] (36.6,42.8] (36.6,42.8] (42.8,49]   (17.9,24.2] (55.2,61.4] (42.8,49]  
## [2257] (36.6,42.8] (36.6,42.8] (30.4,36.6] (30.4,36.6] (61.4,67.6] (42.8,49]  
## [2263] (30.4,36.6] (36.6,42.8] (61.4,67.6] (42.8,49]   (42.8,49]   (30.4,36.6]
## [2269] (49,55.2]   (61.4,67.6] (42.8,49]   (36.6,42.8] (36.6,42.8] (42.8,49]  
## [2275] (49,55.2]   (61.4,67.6] (24.2,30.4] (42.8,49]   (30.4,36.6] (36.6,42.8]
## [2281] (55.2,61.4] (36.6,42.8] (30.4,36.6] (42.8,49]   (17.9,24.2] (36.6,42.8]
## [2287] (42.8,49]   (30.4,36.6] (36.6,42.8] (42.8,49]   (42.8,49]   (30.4,36.6]
## [2293] (55.2,61.4] (30.4,36.6] (49,55.2]   (17.9,24.2] (49,55.2]   (24.2,30.4]
## [2299] (24.2,30.4] (30.4,36.6] (42.8,49]   (17.9,24.2] (36.6,42.8] (42.8,49]  
## [2305] (42.8,49]   (30.4,36.6] (49,55.2]   (49,55.2]   (67.6,73.8] (42.8,49]  
## [2311] (36.6,42.8] (42.8,49]   (17.9,24.2] (36.6,42.8] (42.8,49]   (42.8,49]  
## [2317] (24.2,30.4] (42.8,49]   (49,55.2]   (55.2,61.4] (30.4,36.6] (49,55.2]  
## [2323] (42.8,49]   (42.8,49]   (42.8,49]   (24.2,30.4] (67.6,73.8] (17.9,24.2]
## [2329] (49,55.2]   (24.2,30.4] (49,55.2]   (42.8,49]   (42.8,49]   (24.2,30.4]
## [2335] (42.8,49]   (61.4,67.6] (36.6,42.8] (17.9,24.2] (42.8,49]   (49,55.2]  
## [2341] (67.6,73.8] (42.8,49]   (67.6,73.8] (24.2,30.4] (36.6,42.8] (42.8,49]  
## [2347] (61.4,67.6] (24.2,30.4] (36.6,42.8] (49,55.2]   (49,55.2]   (30.4,36.6]
## [2353] (36.6,42.8] (30.4,36.6] (42.8,49]   (42.8,49]   (42.8,49]   (36.6,42.8]
## [2359] (30.4,36.6] (17.9,24.2] (42.8,49]   (55.2,61.4] (49,55.2]   (55.2,61.4]
## [2365] (42.8,49]   (36.6,42.8] (24.2,30.4] (30.4,36.6] (42.8,49]   (30.4,36.6]
## [2371] (30.4,36.6] (30.4,36.6] (36.6,42.8] (49,55.2]   (42.8,49]   (42.8,49]  
## [2377] (30.4,36.6] (24.2,30.4] (55.2,61.4] (49,55.2]   (36.6,42.8] (42.8,49]  
## [2383] (42.8,49]   (42.8,49]   (42.8,49]   (36.6,42.8] (30.4,36.6] (24.2,30.4]
## [2389] (30.4,36.6] (55.2,61.4] (49,55.2]   (30.4,36.6] (30.4,36.6] (36.6,42.8]
## [2395] (17.9,24.2] (49,55.2]   (30.4,36.6] (36.6,42.8] (36.6,42.8] (49,55.2]  
## [2401] (36.6,42.8] (55.2,61.4] (49,55.2]   (42.8,49]   (30.4,36.6] (17.9,24.2]
## [2407] (42.8,49]   (42.8,49]   (30.4,36.6] (24.2,30.4] (24.2,30.4] (30.4,36.6]
## [2413] (55.2,61.4] (42.8,49]   (42.8,49]   (17.9,24.2] (42.8,49]   (36.6,42.8]
## [2419] (49,55.2]   (55.2,61.4] (30.4,36.6] (55.2,61.4] (42.8,49]   (42.8,49]  
## [2425] (49,55.2]   (36.6,42.8] (24.2,30.4] (30.4,36.6] (36.6,42.8] (17.9,24.2]
## [2431] (49,55.2]   (42.8,49]   (36.6,42.8] (42.8,49]   (24.2,30.4] (42.8,49]  
## [2437] (30.4,36.6] (30.4,36.6] (49,55.2]   (30.4,36.6] (36.6,42.8] (49,55.2]  
## [2443] (36.6,42.8] (61.4,67.6] (36.6,42.8] (49,55.2]   (30.4,36.6] (30.4,36.6]
## [2449] (42.8,49]   (36.6,42.8] (42.8,49]   (42.8,49]   (49,55.2]   (61.4,67.6]
## [2455] (30.4,36.6] (55.2,61.4] (36.6,42.8] (49,55.2]   (24.2,30.4] (17.9,24.2]
## [2461] (61.4,67.6] (61.4,67.6] (24.2,30.4] (42.8,49]   (17.9,24.2] (30.4,36.6]
## [2467] (42.8,49]   (42.8,49]   (42.8,49]   (42.8,49]   (49,55.2]   (42.8,49]  
## [2473] (42.8,49]   (61.4,67.6] (55.2,61.4] (67.6,73.8] (30.4,36.6] (36.6,42.8]
## [2479] (42.8,49]   (17.9,24.2] (42.8,49]   (30.4,36.6] (42.8,49]   (24.2,30.4]
## [2485] (24.2,30.4] (36.6,42.8] (24.2,30.4] (30.4,36.6] (36.6,42.8] (42.8,49]  
## [2491] (61.4,67.6] (49,55.2]   (55.2,61.4] (42.8,49]   (36.6,42.8] (24.2,30.4]
## [2497] (42.8,49]   (36.6,42.8] (55.2,61.4] (49,55.2]   (42.8,49]   (30.4,36.6]
## [2503] (49,55.2]   (49,55.2]   (36.6,42.8] (42.8,49]   (42.8,49]   (42.8,49]  
## [2509] (42.8,49]   (42.8,49]   (30.4,36.6] (36.6,42.8] (24.2,30.4] (36.6,42.8]
## [2515] (17.9,24.2] (30.4,36.6] (30.4,36.6] (30.4,36.6] (24.2,30.4] (36.6,42.8]
## [2521] (49,55.2]   (36.6,42.8] (17.9,24.2] (55.2,61.4] (61.4,67.6] (30.4,36.6]
## [2527] (36.6,42.8] (24.2,30.4] (17.9,24.2] (24.2,30.4] (42.8,49]   (36.6,42.8]
## [2533] (42.8,49]   (49,55.2]   (36.6,42.8] (42.8,49]   (24.2,30.4] (42.8,49]  
## [2539] (49,55.2]   (30.4,36.6] (24.2,30.4] (36.6,42.8] (24.2,30.4] (55.2,61.4]
## [2545] (49,55.2]   (17.9,24.2] (42.8,49]   (55.2,61.4] (67.6,73.8] (55.2,61.4]
## [2551] (55.2,61.4] (24.2,30.4] (42.8,49]   (49,55.2]   (42.8,49]   (36.6,42.8]
## [2557] (42.8,49]   (49,55.2]   (42.8,49]   (36.6,42.8] (24.2,30.4] (49,55.2]  
## [2563] (30.4,36.6] (49,55.2]   (30.4,36.6] (30.4,36.6] (67.6,73.8] (30.4,36.6]
## [2569] (42.8,49]   (17.9,24.2] (17.9,24.2] (36.6,42.8] (36.6,42.8] (24.2,30.4]
## [2575] (24.2,30.4] (36.6,42.8] (36.6,42.8] (17.9,24.2] (36.6,42.8] (49,55.2]  
## [2581] (42.8,49]   (36.6,42.8] (36.6,42.8] (49,55.2]   (42.8,49]   (49,55.2]  
## [2587] (55.2,61.4] (24.2,30.4] (55.2,61.4] (42.8,49]   (42.8,49]   (30.4,36.6]
## [2593] (55.2,61.4] (67.6,73.8] (67.6,73.8] (49,55.2]   (42.8,49]   (36.6,42.8]
## [2599] (61.4,67.6] (24.2,30.4] (24.2,30.4] (42.8,49]   (42.8,49]   (49,55.2]  
## [2605] (42.8,49]   (36.6,42.8] (42.8,49]   (49,55.2]   (30.4,36.6] (17.9,24.2]
## [2611] (42.8,49]   (36.6,42.8] (36.6,42.8] (36.6,42.8] (17.9,24.2] (30.4,36.6]
## [2617] (24.2,30.4] (42.8,49]   (42.8,49]   (36.6,42.8] (36.6,42.8] (36.6,42.8]
## [2623] (36.6,42.8] (55.2,61.4] (36.6,42.8] (24.2,30.4] (30.4,36.6] (42.8,49]  
## [2629] (36.6,42.8] (30.4,36.6] (36.6,42.8] (17.9,24.2] (24.2,30.4] (49,55.2]  
## [2635] (36.6,42.8] (30.4,36.6] (42.8,49]   (49,55.2]   (49,55.2]   (17.9,24.2]
## [2641] (36.6,42.8] (36.6,42.8] (36.6,42.8] (24.2,30.4] (42.8,49]   (36.6,42.8]
## [2647] (42.8,49]   (49,55.2]   (36.6,42.8] (36.6,42.8] (42.8,49]   (17.9,24.2]
## [2653] (42.8,49]   (24.2,30.4] (49,55.2]   (30.4,36.6] (42.8,49]   (30.4,36.6]
## [2659] (30.4,36.6] (17.9,24.2] (55.2,61.4] (49,55.2]   (30.4,36.6] (42.8,49]  
## [2665] (42.8,49]   (42.8,49]   (30.4,36.6] (49,55.2]   (30.4,36.6] (36.6,42.8]
## [2671] (24.2,30.4] (61.4,67.6] (49,55.2]   (42.8,49]   (24.2,30.4] (36.6,42.8]
## [2677] (17.9,24.2] (73.8,80.1] (42.8,49]   (36.6,42.8] (36.6,42.8] (17.9,24.2]
## [2683] (42.8,49]   (42.8,49]   (17.9,24.2] (42.8,49]   (36.6,42.8] (42.8,49]  
## [2689] (30.4,36.6] (61.4,67.6] (36.6,42.8] (42.8,49]   (42.8,49]   (17.9,24.2]
## [2695] (61.4,67.6] (42.8,49]   (42.8,49]   (49,55.2]   (55.2,61.4] (17.9,24.2]
## [2701] (49,55.2]   (30.4,36.6] (36.6,42.8] (30.4,36.6] (30.4,36.6] (55.2,61.4]
## [2707] (36.6,42.8] (36.6,42.8] (24.2,30.4] (24.2,30.4] (42.8,49]   (24.2,30.4]
## [2713] (55.2,61.4] (55.2,61.4] (24.2,30.4] (42.8,49]   (24.2,30.4] (49,55.2]  
## [2719] (36.6,42.8] (61.4,67.6] (30.4,36.6] (49,55.2]   (36.6,42.8] (49,55.2]  
## [2725] (24.2,30.4] (36.6,42.8] (49,55.2]   (49,55.2]   (42.8,49]   (36.6,42.8]
## [2731] (36.6,42.8] (30.4,36.6] (36.6,42.8] (49,55.2]   (42.8,49]   (36.6,42.8]
## [2737] (49,55.2]   (24.2,30.4] (49,55.2]   (49,55.2]   (49,55.2]   (30.4,36.6]
## [2743] (49,55.2]   (42.8,49]   (24.2,30.4] (36.6,42.8] (24.2,30.4] (42.8,49]  
## [2749] (42.8,49]   (42.8,49]   (42.8,49]   (30.4,36.6] (30.4,36.6] (30.4,36.6]
## [2755] (49,55.2]   (36.6,42.8] (55.2,61.4] (30.4,36.6] (42.8,49]   (55.2,61.4]
## [2761] (17.9,24.2] (36.6,42.8] (55.2,61.4] (42.8,49]   (42.8,49]   (42.8,49]  
## [2767] (24.2,30.4] (49,55.2]   (24.2,30.4] (24.2,30.4] (17.9,24.2] (42.8,49]  
## [2773] (42.8,49]   (61.4,67.6] (30.4,36.6] (49,55.2]   (30.4,36.6] (17.9,24.2]
## [2779] (49,55.2]   (42.8,49]   (30.4,36.6] (30.4,36.6] (42.8,49]   (42.8,49]  
## [2785] (36.6,42.8] (55.2,61.4] (49,55.2]   (30.4,36.6] (42.8,49]   (36.6,42.8]
## [2791] (17.9,24.2] (30.4,36.6] (36.6,42.8] (42.8,49]   (42.8,49]   (55.2,61.4]
## [2797] (49,55.2]   (36.6,42.8] (49,55.2]   (36.6,42.8] (24.2,30.4] (42.8,49]  
## [2803] (36.6,42.8] (49,55.2]   (49,55.2]   (55.2,61.4] (24.2,30.4] (55.2,61.4]
## [2809] (42.8,49]   (42.8,49]   (61.4,67.6] (49,55.2]   (42.8,49]   (49,55.2]  
## [2815] (55.2,61.4] (49,55.2]   (36.6,42.8] (49,55.2]   (49,55.2]   (42.8,49]  
## [2821] (49,55.2]   (17.9,24.2] (73.8,80.1] (49,55.2]   (24.2,30.4] (42.8,49]  
## [2827] (36.6,42.8] (49,55.2]   (24.2,30.4] (61.4,67.6] (42.8,49]   (30.4,36.6]
## [2833] (61.4,67.6] (42.8,49]   (36.6,42.8] (30.4,36.6] (42.8,49]   (36.6,42.8]
## [2839] (24.2,30.4] (36.6,42.8] (42.8,49]   (36.6,42.8] (49,55.2]   (49,55.2]  
## [2845] (42.8,49]   (49,55.2]   (49,55.2]   (49,55.2]   (24.2,30.4] (24.2,30.4]
## [2851] (24.2,30.4] (42.8,49]   (30.4,36.6] (67.6,73.8] (30.4,36.6] (24.2,30.4]
## [2857] (36.6,42.8] (36.6,42.8] (36.6,42.8] (49,55.2]   (49,55.2]   (36.6,42.8]
## [2863] (24.2,30.4] (42.8,49]   (24.2,30.4] (49,55.2]   (61.4,67.6] (36.6,42.8]
## [2869] (42.8,49]   (30.4,36.6] (24.2,30.4] (30.4,36.6] (24.2,30.4] (36.6,42.8]
## [2875] (30.4,36.6] (42.8,49]   (55.2,61.4] (17.9,24.2] (49,55.2]   (30.4,36.6]
## [2881] (55.2,61.4] (36.6,42.8] (49,55.2]   (67.6,73.8] (17.9,24.2] (17.9,24.2]
## [2887] (36.6,42.8] (24.2,30.4] (24.2,30.4] (36.6,42.8] (42.8,49]   (67.6,73.8]
## [2893] (30.4,36.6] (36.6,42.8] (30.4,36.6] (30.4,36.6] (36.6,42.8] (24.2,30.4]
## [2899] (30.4,36.6] (42.8,49]   (55.2,61.4] (42.8,49]   (36.6,42.8] (36.6,42.8]
## [2905] (55.2,61.4] (24.2,30.4] (24.2,30.4] (49,55.2]   (30.4,36.6] (30.4,36.6]
## [2911] (42.8,49]   (36.6,42.8] (24.2,30.4] (55.2,61.4] (36.6,42.8] (55.2,61.4]
## [2917] (49,55.2]   (49,55.2]   (36.6,42.8] (24.2,30.4] (30.4,36.6] (36.6,42.8]
## [2923] (49,55.2]   (17.9,24.2] (36.6,42.8] (36.6,42.8] (61.4,67.6] (42.8,49]  
## [2929] (49,55.2]   (42.8,49]   (24.2,30.4] (61.4,67.6] (36.6,42.8] (55.2,61.4]
## [2935] (30.4,36.6] (30.4,36.6] (42.8,49]   (36.6,42.8] (42.8,49]   (36.6,42.8]
## [2941] (42.8,49]   (42.8,49]   (36.6,42.8] (24.2,30.4] (36.6,42.8] (24.2,30.4]
## [2947] (30.4,36.6] (24.2,30.4] (49,55.2]   (36.6,42.8] (42.8,49]   (55.2,61.4]
## [2953] (42.8,49]   (61.4,67.6] (24.2,30.4] (30.4,36.6] (49,55.2]   (24.2,30.4]
## [2959] (49,55.2]   (30.4,36.6] (17.9,24.2] (24.2,30.4] (36.6,42.8] (30.4,36.6]
## [2965] (55.2,61.4] (36.6,42.8] (24.2,30.4] (36.6,42.8] (49,55.2]   (24.2,30.4]
## [2971] (55.2,61.4] (24.2,30.4] (17.9,24.2] (49,55.2]   (42.8,49]   (49,55.2]  
## [2977] (30.4,36.6] (42.8,49]   (49,55.2]   (55.2,61.4] (36.6,42.8] (49,55.2]  
## [2983] (36.6,42.8] (55.2,61.4] (36.6,42.8] (24.2,30.4] (55.2,61.4] (30.4,36.6]
## [2989] (49,55.2]   (30.4,36.6] (49,55.2]   (24.2,30.4] (30.4,36.6] (30.4,36.6]
## [2995] (30.4,36.6] (42.8,49]   (24.2,30.4] (24.2,30.4] (24.2,30.4] (49,55.2]  
## 10 Levels: (17.9,24.2] (24.2,30.4] (30.4,36.6] (36.6,42.8] ... (73.8,80.1]
head(Wage)
##        year age           maritl     race       education             region
## 231655 2006  18 1. Never Married 1. White    1. < HS Grad 2. Middle Atlantic
## 86582  2004  24 1. Never Married 1. White 4. College Grad 2. Middle Atlantic
## 161300 2003  45       2. Married 1. White 3. Some College 2. Middle Atlantic
## 155159 2003  43       2. Married 3. Asian 4. College Grad 2. Middle Atlantic
## 11443  2005  50      4. Divorced 1. White      2. HS Grad 2. Middle Atlantic
## 376662 2008  54       2. Married 1. White 4. College Grad 2. Middle Atlantic
##              jobclass         health health_ins  logwage      wage
## 231655  1. Industrial      1. <=Good      2. No 4.318063  75.04315
## 86582  2. Information 2. >=Very Good      2. No 4.255273  70.47602
## 161300  1. Industrial      1. <=Good     1. Yes 4.875061 130.98218
## 155159 2. Information 2. >=Very Good     1. Yes 5.041393 154.68529
## 11443  2. Information      1. <=Good     1. Yes 4.318063  75.04315
## 376662 2. Information 2. >=Very Good     1. Yes 4.845098 127.11574
Wage$age_cut2 = cut(Wage$age, 2)
Wage$age_cut3 = cut(Wage$age, 3)
Wage$age_cut4 = cut(Wage$age, 4)
Wage$age_cut5 = cut(Wage$age, 5)
Wage$age_cut6 = cut(Wage$age, 6)
Wage$age_cut7 = cut(Wage$age, 7)
Wage$age_cut8 = cut(Wage$age, 8)
Wage$age_cut9 = cut(Wage$age, 9)
Wage$age_cut10 = cut(Wage$age, 10)

step_fit2 = glm(wage ~ age_cut2, data = Wage)
step_fit3 = glm(wage ~ age_cut3, data = Wage)
step_fit4 = glm(wage ~ age_cut4, data = Wage)
step_fit5 = glm(wage ~ age_cut5, data = Wage)
step_fit6 = glm(wage ~ age_cut6, data = Wage)
step_fit7 = glm(wage ~ age_cut7, data = Wage)
step_fit8 = glm(wage ~ age_cut8, data = Wage)
step_fit9 = glm(wage ~ age_cut9, data = Wage)
step_fit10 = glm(wage ~ age_cut10, data = Wage)


step_errors = 
rbind(
  cv.glm(Wage, step_fit2)$delta[1],
  cv.glm(Wage, step_fit3)$delta[1],
  cv.glm(Wage, step_fit4)$delta[1],
  cv.glm(Wage, step_fit5)$delta[1],
  cv.glm(Wage, step_fit6)$delta[1],
  cv.glm(Wage, step_fit7)$delta[1],
  cv.glm(Wage, step_fit8)$delta[1],
  cv.glm(Wage, step_fit9)$delta[1],
  cv.glm(Wage, step_fit10)$delta[1]
)

step_errors
##           [,1]
##  [1,] 1734.064
##  [2,] 1682.763
##  [3,] 1635.894
##  [4,] 1631.450
##  [5,] 1623.291
##  [6,] 1611.604
##  [7,] 1601.006
##  [8,] 1610.213
##  [9,] 1604.804
coef(summary(step_fit7))
##                     Estimate Std. Error   t value      Pr(>|t|)
## (Intercept)         80.06402   2.405222 33.287586 5.517532e-207
## age_cut7(26.9,35.7] 24.51568   2.892501  8.475600  3.617008e-17
## age_cut7(35.7,44.6] 38.59253   2.792477 13.820180  3.695152e-42
## age_cut7(44.6,53.4] 38.05482   2.812402 13.531077  1.556835e-40
## age_cut7(53.4,62.3] 39.03969   3.082094 12.666611  7.411125e-36
## age_cut7(62.3,71.1] 31.03930   4.884196  6.355048  2.400708e-10
## age_cut7(71.1,80.1] 15.99445   9.075719  1.762334  7.811488e-02

Based on the output above, 7 cuts is optimal.

step_preds = predict(glm(wage ~ cut(age, 7), data = Wage), list(age = age.grid))

plot(wage ~ age, data = Wage, col = "darkgrey")
lines(age.grid, step_preds, col = "red", lwd = 2)

10. This question relates to the College data set.

  1. Split the data into a training set and a test set. Using out-of-state tuition as the response and the other variables as the predictors, perform forward stepwise selection on the training set in order to identify a satisfactory model that uses just a subset of the predictors.
attach(College)
set.seed(1234)
# split into training and test sets
samp = sample(1:nrow(College), nrow(College)*.7)
college_train = College[samp, ]
college_test = College[-samp, ]

college_min_model = lm(Outstate ~ 1, data = college_train)
college_forward = step(college_min_model, direction = "forward", scope = formula(lm(Outstate ~ ., data = college_train)), trace = 0)

summary(college_forward)
## 
## Call:
## lm(formula = Outstate ~ Expend + Private + Room.Board + perc.alumni + 
##     Terminal + Grad.Rate + S.F.Ratio + Accept + F.Undergrad + 
##     Apps + Top10perc + Personal, data = college_train)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -6222.0 -1321.7    54.5  1330.6  4931.5 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -1.037e+03  8.653e+02  -1.199 0.231082    
## Expend       1.757e-01  2.507e-02   7.005 7.50e-12 ***
## PrivateYes   2.342e+03  2.937e+02   7.972 9.63e-15 ***
## Room.Board   8.018e-01  9.881e-02   8.115 3.40e-15 ***
## perc.alumni  4.495e+01  9.009e+00   4.989 8.23e-07 ***
## Terminal     3.417e+01  7.581e+00   4.507 8.10e-06 ***
## Grad.Rate    2.304e+01  6.680e+00   3.449 0.000608 ***
## S.F.Ratio   -7.330e+01  2.890e+01  -2.536 0.011488 *  
## Accept       7.086e-01  1.298e-01   5.460 7.32e-08 ***
## F.Undergrad -1.620e-01  4.127e-02  -3.925 9.83e-05 ***
## Apps        -2.547e-01  7.393e-02  -3.445 0.000616 ***
## Top10perc    2.560e+01  7.678e+00   3.334 0.000917 ***
## Personal    -3.064e-01  1.386e-01  -2.211 0.027452 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1956 on 530 degrees of freedom
## Multiple R-squared:  0.7656, Adjusted R-squared:  0.7603 
## F-statistic: 144.3 on 12 and 530 DF,  p-value: < 2.2e-16

The forward stepwise selection ended up keeping Expend, Private, Room.Board, perc.alumni, Grad.Rate, Terminal, Personal, Top10perc to predict out of state tuition.

  1. Fit a GAM on the training data, using out-of-state tuition as the response and the features selected in the previous step as the predictors. Plot the results, and explain your findings.
library(gam)
## Warning: package 'gam' was built under R version 4.0.5
## Loading required package: splines
## Loading required package: foreach
## Warning: package 'foreach' was built under R version 4.0.3
## Loaded gam 1.20
college_gam = gam(Outstate ~ s(Expend, 5) + Private +s(Room.Board, 5) +  s(perc.alumni, 5) + s(Grad.Rate, 5)+ s(Terminal, 5) + s(Personal, 5) + s(Top10perc, 5), data = college_train  )

par(mfrow = c(2,3))
plot(college_gam, se = TRUE, col = "blue")

Based on the plots, Expend, Room.Board, Grad.Rate, Terminal, Personal, and Top10perc have a large non linear relationship with out of state tuition.

perc.alumni seem to have a small non linear relationship with out of state tuition, but it’s not as strong as the other variables that have a larger non linear relationship.

  1. Evaluate the model obtained on the test set, and explain the results obtained.
college_preds = predict(college_gam, college_test)

# R^2
RSS <- sum((college_test$Outstate - college_preds)^2)
TSS <- sum((college_test$Outstate - mean(college_test$Outstate)) ^ 2)
1 - (RSS / TSS)   
## [1] 0.7812967
# MSE
mean((predict(college_gam, newdata = college_test) - college_test$Outstate)^2)
## [1] 3647497

The R^2 is 0.766. I would say that is a good result for the model.

The MSE is 3417197

  1. For which variables, if any, is there evidence of a non linear relationship with the response?
summary(college_gam)
## 
## Call: gam(formula = Outstate ~ s(Expend, 5) + Private + s(Room.Board, 
##     5) + s(perc.alumni, 5) + s(Grad.Rate, 5) + s(Terminal, 5) + 
##     s(Personal, 5) + s(Top10perc, 5), data = college_train)
## Deviance Residuals:
##      Min       1Q   Median       3Q      Max 
## -6547.51 -1085.57    87.26  1227.40  4468.32 
## 
## (Dispersion Parameter for gaussian family taken to be 3340139)
## 
##     Null Deviance: 8652235855 on 542 degrees of freedom
## Residual Deviance: 1690108781 on 505.9996 degrees of freedom
## AIC: 9735.334 
## 
## Number of Local Scoring Iterations: NA 
## 
## Anova for Parametric Effects
##                    Df     Sum Sq    Mean Sq   F value    Pr(>F)    
## s(Expend, 5)        1 3878394713 3878394713 1161.1478 < 2.2e-16 ***
## Private             1 1089068760 1089068760  326.0550 < 2.2e-16 ***
## s(Room.Board, 5)    1  327948204  327948204   98.1840 < 2.2e-16 ***
## s(perc.alumni, 5)   1  205042879  205042879   61.3875 2.781e-14 ***
## s(Grad.Rate, 5)     1  117596358  117596358   35.2070 5.503e-09 ***
## s(Terminal, 5)      1   26533459   26533459    7.9438  0.005014 ** 
## s(Personal, 5)      1   26307651   26307651    7.8762  0.005202 ** 
## s(Top10perc, 5)     1    1884026    1884026    0.5641  0.452980    
## Residuals         506 1690108781    3340139                        
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Anova for Nonparametric Effects
##                   Npar Df  Npar F   Pr(F)    
## (Intercept)                                  
## s(Expend, 5)            4 24.5947 < 2e-16 ***
## Private                                      
## s(Room.Board, 5)        4  1.9541 0.10030    
## s(perc.alumni, 5)       4  2.2919 0.05856 .  
## s(Grad.Rate, 5)         4  2.7311 0.02855 *  
## s(Terminal, 5)          4  2.2244 0.06528 .  
## s(Personal, 5)          4  2.0628 0.08450 .  
## s(Top10perc, 5)         4  0.3742 0.82710    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Expend, Room.Board and Terminal all have a strong non-linear relationship with out of state tuition.