Learn R Programming

sail (version 0.1.0)

predict.cv.sail: Make predictions from a cv.sail object

Description

This function makes predictions from a cross-validated sail model, using the stored "sail.fit" object, and the optimal value chosen for lambda.

Usage

# S3 method for cv.sail
predict(object, newx, newe, s = c("lambda.1se",
  "lambda.min"), ...)

# S3 method for cv.sail coef(object, s = c("lambda.1se", "lambda.min"), ...)

Arguments

object

fitted cv.sail object

newx

matrix of new values for x at which predictions are to be made. Do not include the intercept (this function takes care of that). Must be a matrix. This argument is not used for type=c("coefficients","nonzero"). This matrix will be passed to design_sail to create the design matrix necessary for predictions. This matrix must have the same number of columns originally supplied to the sail fitting function.

newe

vector of new values for the exposure variable e. This is passed to the design_sail function.

s

Value(s) of the penalty parameter lambda at which predictions are required. Default is the value s="lambda.1se" stored on the CV object. Alternatively s="lambda.min" can be used. If s is numeric, it is taken as the value(s) of lambda to be used.

...

other arguments passed to predict.sail

Value

The object returned depends the ... argument which is passed on to the predict method for sail objects.

Details

This function makes it easier to use the results of cross-validation to make a prediction.

See Also

predict.sail

Examples

Run this code
# NOT RUN {
data("sailsim")
f.basis <- function(i) splines::bs(i, degree = 3)
library(doParallel)
cl <- makeCluster(2)
registerDoParallel(cl)
cvfit <- cv.sail(x = sailsim$x, y = sailsim$y, e = sailsim$e,
                 parallel = TRUE, nlambda = 10,
                 maxit = 20, basis = f.basis,
                 nfolds = 3, dfmax = 5)
stopCluster(cl)
predict(cvfit) # predict at "lambda.1se"
predict(cvfit, s = "lambda.min") # predict at "lambda.min"
predict(cvfit, s = 0.5) # predict at specific value of lambda
predict(cvfit, type = "nonzero") # non-zero coefficients at lambda.1se

# predict response for new data set
newx <- sailsim$x * 1.10
newe <- sailsim$e * 2
predict(cvfit, newx = newx, newe = newe, s = "lambda.min")

# }

Run the code above in your browser using DataLab