Some of the exercises are not tested by Dodona (for example the plots), but it is still useful to try them.
Use the bs()
function to fit a regression spline to predict nox
using dis
.
Place knots at the values 4
, 7
, and 11
. Store the model in fit.bs
.
Try to replicate the following figure:
nox
vs dis
using all the data.dis.grid
of values ranging from the lowest dis
value in the data to the highest dis
value observed, in steps of 0.1
.fit.bs
, predict nox
for the entire sequence. Store the result in preds
.preds
on the plot.
rss
. Don’t overwrite your solution fit.bs
from question 4.
rss
.
Initialize the vector
rss
as a vector of length 16 with valuesNA
. If you would like to plot the RSS, exclude the first 2NA
values withrss[-c(1, 2)]
.
deltas.bs
.
Don’t overwrite your solution fit.bs
from question 4. You can ignore the warnings.
Initialize the vector
deltas.bs
as a vector of length 16 with valuesNA
. If you would like to plot the CV test error, exclude the first 2NA
values withdeltas.bs[-c(1, 2)]
.
df.min.bs
.Assume that:
MASS
library has been loadedBoston
dataset has been loaded and attachedboot
library has been loadedsplines
library has been loaded