In this exercise, you will further analyze the Wage
data set considered throughout this chapter, available in the ISLR2
package.
Some of the exercises are not tested by Dodona (for example the plots), but it is still useful to try them.
wage
using age
and use 10-fold cross-validation to select the optimal
degree \(d\) for the polynomial.
deltas
.i
of the for loop, fit a linear model with a polynomial of order i
. Check degree 1 to 10.cv.glm()
function, store the CV error in the i
-th element of the vector deltas.poly
.
Set the correct value for \(K\) and use the attribute delta[1]
to extract the CV error.deltas
and make a line plot.d.min.poly
.
Verify your decision by comparing it to the results of hypothesis testing using ANOVA.
fit1
has order-1 until fit5
with order-5.Perform an ANOVA analysis using the 5 model. Store it in anova.poly
.
wage
using age
, and perform cross-validation to choose the optimal number of cuts.
i
cuts in the i
-th iteration. Store the results in deltas.cut
. Check cuts 2 to 10; deltas.cut
should have NA
for cut 1.d.min.cut
.
Try to recreate the following plot of a step function with 8 cuts fitted to the training data.
wage
vs age
using all the data.age.grid
of integer values ranging from the lowest age
value in the data to the highest age
value observed.fit8
.fit8
, predict wage
for the entire sequence. Store the result in preds
.preds
on the plot.Assume that:
ISLR2
library has been loadedWage
dataset has been loaded and attachedboot
library has been loaded