Learn R Programming

flam (version 3.2)

plot.flamCV: Plots Cross-Validation Curve for Object of Class "flamCV"

Description

This function plots the cross-validation curve for a series of models fit using flamCV. The cross-validation error with +/-1 standard error is plotted for each value of lambda considered in the call to flamCV with a dotted vertical line indicating the chosen lambda.

Usage

# S3 method for flamCV
plot(x, showSE = T, …)

Arguments

x

an object of class "flamCV".

showSE

a logical (TRUE or FALSE) for whether the standard errors of the curve should be plotted.

…

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

References

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

See Also

flamCV

Examples

Run this code
# NOT RUN {
#See ?'flam-package' for a full example of how to use this package

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

#fit model and select tuning parameters using 2-fold cross-validation
#note: use larger 'n.fold' (e.g., 10) in practice
flamCV.out <- flamCV(x = data$x, y = data$y, within1SE = TRUE, n.fold = 2)

#lambdas chosen is
flamCV.out$lambda.cv

#we can now plot the cross-validation error curve with standard errors
#vertical dotted line at lambda chosen by cross-validation
plot(flamCV.out)
#or without standard errors
plot(flamCV.out, showSE = FALSE)

# }
# NOT RUN {
#can choose lambda to be value with minimum CV error
#instead of lambda with CV error within 1 standard error of the minimum
flamCV.out2 <- flamCV(x = data$x, y = data$y, within1SE = FALSE, n.fold = 2)

#contrast to chosen lambda for minimum cross-validation error
#it's a less-regularized model (i.e., lambda is smaller)
plot(flamCV.out2)
# }

Run the code above in your browser using DataLab