predict.flam {flam}R Documentation

Predicts Observations for a New Covariate Matrix and Fit from flam

Description

This function makes predictions from a specified covariate matrix for a fit of the class "flam" with user-specified tuning parameters.

Usage

## S3 method for class 'flam'
predict(object, new.x, lambda, alpha, ...)

Arguments

object

an object of the class "flam".

new.x

the covariate matrix for which to make predictions - the number of columns should match that of object$x.

lambda

the desired value for the tuning parameter lambda. This does not need to be a value in object$all.lambda.

alpha

the desired value for the tuning parameter alpha. This does not need to be a value in object$all.alpha.

...

additional arguments to be passed. These are ignored in this function.

Details

It is likely that new.x[,i] contains values not contained in object$x[,i]. Predictions for that particular case are taken to be a linear interpolation of the nearest neighboring values in object$x[,i], i.e., the closest smaller value and the closest larger value.

Value

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

Author(s)

Ashley Petersen

References

Petersen, A., Witten, D., and Simon, N. (2014). Fused Lasso Additive Model. arXiv preprint arXiv:1409.5391.

See Also

flam

Examples

#See ?'flam-package' for a full example of how to use this package

#generate data
set.seed(1)
data <- sim.data(n = 100, scenario = 1, zerof = 0, noise = 1)

#fit model for a range of tuning parameters
flam.out <- flam(x = data$x, y = data$y)

#we can make predictions for a covariate matrix with new observations
#choose desired alpha and lambda
alpha <- flam.out$all.alpha[15]; lambda <- flam.out$all.lambda[15]
#new.x with 20 observations and the same number of features as flam.out$x
new.data <- sim.data(n = 20, scenario = 1, zerof = 0, noise = 1)
new.x <- new.data$x
#make predictions
y.hat <- predict(flam.out, new.x = new.x, lambda = lambda, alpha = alpha)
#which can be compared to the true y
plot(new.data$y, y.hat, xlab="y", ylab=expression(hat(y)))
abline(0,1,lty=2)

#can also make predictions for any alpha and lambda:
predict(flam.out, new.x = new.x, lambda = 2, alpha = 0.9)

[Package flam version 3.2 Index]