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

Description Usage Arguments Details Value See Also Examples

View source: R/methods.R

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

1
2
3
4
5
6
## S3 method for class 'cv.sail'
predict(object, newx, newe, s = c("lambda.1se",
  "lambda.min"), ...)

## S3 method for class '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

Details

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

Value

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

See Also

predict.sail

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
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")

sahirbhatnagar/sail documentation built on July 17, 2021, 5:10 a.m.