# NOT RUN {
set.seed(1)
n <- 100; p <- 20
x <- matrix(rnorm(n * p), n, p)
beta <- matrix(c(rep(2, 5), rep(0, 15)), ncol = 1)
y <- x %*% beta + rnorm(n)
cvfit <- cv.rgam(x, y)
# predictions at the lambda.1se value
predict(cvfit, xnew = x[1:5, ])
# predictions at the lambda.min value
predict(cvfit, xnew = x[1:5, ], s = "lambda.min")
# predictions at specific lambda value
predict(cvfit, xnew = x[1:5, ], s = 0.1)
# probability predictions for binomial family
bin_y <- ifelse(y > 0, 1, 0)
cvfit2 <- cv.rgam(x, bin_y, family = "binomial")
predict(cvfit2, xnew = x[1:5, ], type = "response", s = "lambda.min")
# }
Run the code above in your browser using DataLab