# NOT RUN {
f.basis <- function(i) splines::bs(i, degree = 3)
# Parallel
library(doParallel)
cl <- makeCluster(2)
registerDoParallel(cl)
cvfit <- cv.sail(x = sailsim$x, y = sailsim$y, e = sailsim$e,
parallel = TRUE, nlambda = 10,
maxit = 100, basis = f.basis,
nfolds = 3, dfmax = 10)
stopCluster(cl)
# plot cv-error curve
plot(cvfit)
# non-zero estimated coefficients at lambda.min
predict(cvfit, type = "nonzero", s="lambda.min")
# plot main effect for X4 with a line for the truth also
plotMain(cvfit$sail.fit, x = sailsim$x, xvar = "X4",
s = cvfit$lambda.min, f.truth = sailsim$f4)
# }
Run the code above in your browser using DataLab