Description Usage Arguments Details Value See Also Examples
View source: R/predict.cv.rgam.R
This function returns the predictions for a new data matrix from a
cross-validated rgam
model by using the stored "glmfit
"
object and the optimal value chosen for lambda
.
1 2 3 |
object |
Fitted " |
xnew |
Matrix of new values for |
s |
Value of the penalty parameter |
... |
Other arguments to be passed to |
This function makes it easier to use the results of cross-validation to make a prediction.
Predictions which the cross-validated model makes for xnew
at
the optimal value of lambda
. Note that the default is the "lambda.1se"
for lambda, to make this function consistent with cv.glmnet
in the
glmnet
package.
The output depends on the ...
argument which is passed on to the predict
method for rgam
objects.
cv.rgam
and predict.rgam
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 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")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.