plot.flam: Plots Function Estimates for Fit of Class "flam"

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

View source: R/flam_fcns.R

Description

This function plots the estimated functions from a model estimated using flam. The user specifies the model of interest (i.e., the tuning parameters) and a plot is made for the estimated association between all non-sparse (or a chosen subset of) features and the outcome.

Usage

1
2
3
4
## S3 method for class 'flam'
plot(x, index, n.plot = 10, predictor.indicators = NULL,
predictor.labels = NULL, outcome.label = "outcome", ticks = F, 
col = "dodgerblue", n.panel.width = NULL, n.panel.height = NULL, ...)

Arguments

x

an object of class "flam".

index

the index for the model of interest to be plotted. Note that index of i corresponds to the model with tuning parameters x$all.alpha[i] and x$all.lambda[i].

n.plot

the number of predictors to be plotted (default of 10). Note that only non-sparse predictors are plotted, however, this argument is ignored if predictor.indicators is specified.

predictor.indicators

a vector indicating which predictor function estimates to plot. The vector should contain the column numbers of x$x whose function estimates are to be plotted. By default, the n.plot predictors with the largest L2 norm are plotted.

predictor.labels

a vector containing the predictor labels of the same length as predictor.indicators if specified, otherwise of length ncol(x$x). By default, "Predictor 1", "Predictor 2", ... are used.

outcome.label

the name of the outcome used in the y-axis label. By default, the label is "outcome".

ticks

a logical (TRUE or FALSE) for whether tick marks indicating the distribution of the predictor should be included at the bottom of each plot.

col

a vector of colors used to plot the function estimates. If col has length 1, then the same color is used for all predictors. Otherwise, col should indicate the color for each predictor and have the same length as predictor.indicators if specified, otherwise the number of columns of x$x.

n.panel.width

the plots will be plotted with par(mfrow=c(n.panel.height,n.panel.width)). If specified, n.panel.height must also be specified. By default, an appropriate grid of plots is used.

n.panel.height

the plots will be plotted with par(mfrow=c(n.panel.height,n.panel.width)). If specified, n.panel.width must also be specified. By default, an appropriate grid of plots is used.

...

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

Details

The estimated function fits are drawn by connecting the predictions for all of the observations in x$x. This may result in fits that appear not to be piecewise consant if only a single observation is observed for a range of x-values.

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
#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 = 10, noise = 1)
#fit model for a range of tuning parameters
flam.out <- flam(x = data$x, y = data$y, alpha.seq = c(0.8, 0.9, 1))

#we plot the predictor fits for a specific index, e.g. 25
#that is, lambda and alpha of
flam.out$all.lambda[25]; flam.out$all.alpha[25]
plot(flam.out, index = 25)
#the fit only has 5 non-sparse features

#by default, up to 10 non-sparse features with the largest L2 norms are 
#plotted, but we can plot a different number of features if desired
plot(flam.out, index = 40, n.plot = 12)
#or we can plot specific predictors of interest
plot(flam.out, index = 40, predictor.indicators = c(1:4, 6, 8, 11, 12))

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