Description Usage Arguments Details Value Author(s) References See Also Examples
This function makes predictions from a specified covariate matrix for a fit of the class "flam" with user-specified tuning parameters.
1 2 |
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 |
lambda |
the desired value for the tuning parameter lambda. This does not need to be a value in |
alpha |
the desired value for the tuning parameter alpha. This does not need to be a value in |
... |
additional arguments to be passed. These are ignored in this function. |
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.
A vector containing the fitted y values for new.x
.
Ashley Petersen
Petersen, A., Witten, D., and Simon, N. (2014). Fused Lasso Additive Model. arXiv preprint arXiv:1409.5391.
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.