Learn R Programming

crisp (version 1.0.0)

predict: Predicts Observations for a New Covariate Matrix using Fit from crisp or crispCV.

Description

This function makes predictions for a specified covariate matrix for a fit of the class crispCV, or class crisp with a user-specified tuning parameter.

Usage

"predict"(object, new.X, lambda.index, ...)
"predict"(object, new.X, ...)

Arguments

object
An object of class crisp or crispCV, which result from running the crisp or crispCV functions, respectively.
new.X
The covariate matrix for which to make predictions.
lambda.index
The index for the desired value of lambda, i.e., object$lambda.seq[lambda.index].
...
Additional arguments to be passed, which are ignored in this function.

Value

A vector containing the fitted y values for new.X.

Details

The ith prediction is made to be the value of object$M.hat.list[[lambda.index]] corresponding to the pair of covariates closest (in Euclidean distance) to new.X[i,].

Examples

Run this code
## Not run: 
# #See ?'crisp-package' for a full example of how to use this package
# 
# #generate data (using a very small 'n' for illustration purposes)
# set.seed(1)
# data <- sim.data(n = 15, scenario = 2)
# 
# #fit model for a range of tuning parameters, i.e., lambda values
# #lambda sequence is chosen automatically if not specified
# crisp.out <- crisp(X = data$X, y = data$y)
# #or fit model and select lambda using 2-fold cross-validation
# #note: use larger 'n.fold' (e.g., 10) in practice
# crispCV.out <- crispCV(X = data$X, y = data$y, n.fold = 2)
# 
# #we can make predictions for a covariate matrix with new observations
# #new.X with 20 observations
# new.data <- sim.data(n = 20, scenario = 2)
# new.X <- new.data$X
# #these will give the same predictions:
# yhat1 <- predict(crisp.out, new.X = new.X, lambda.index = crispCV.out$index.cv)
# yhat2 <- predict(crispCV.out, new.X = new.X)
# ## End(Not run)

Run the code above in your browser using DataLab