predict.flam: Predicts Observations for a New Covariate Matrix and Fit from...

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/flam_fcns.R

Description

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

Usage

1
2
## 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

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

flam documentation built on May 2, 2019, 8:27 a.m.