Learn R Programming

sail (version 0.1.0)

plotMain: Plot Estimated Component Smooth Functions for Main Effects

Description

Takes a fitted sail object produced by sail() or cv.sail()$sail.fit and plots the component smooth function for a pre-specified variable at a given value of lambda and on the scale of the linear predictor. Currently only implemented for type="gaussian"

Usage

plotMain(object, x, xvar, s, f.truth, col = c("#D55E00", "#009E73"),
  legend.position = "bottomleft", rug = TRUE, ...)

Arguments

object

a fitted sail object as produced by sail() or cv.sail()$sail.fit

x

original data supplied to the original call to sail

xvar

a character corresponding to the predictor to be plotted. Only one variable name should be supplied, if more than one is supplied, only the first element will be plotted. This variable name must be in colnames(x).

s

a single value of the penalty parameter lambda at which coefficients will be extracted via the coef method for objects of class "sail". If more than one is supplied, only the first one will be used.

f.truth

true function. Only used for simulation purposes when the truth is known. The function takes as a input a numeric vector corresponding the xvar column in x of length nrow(x). A second line will be plotted for the truth and a legend is added to the plot.

col

color of the line. The first element corresponds to the color used for the estimated function and the second element is for the true function (if f.truth is specified). Default: c("#D55E00", "#009E73")

legend.position

position of the legend. Only used when f.truth is specified. Default: 'bottomleft'. Can be a single keyword from the list "bottomright", "bottom", "bottomleft", "left", "topleft", "top", "topright", "right" and "center". This places the legend on the inside of the plot frame at the given location. Partial argument matching is used.

rug

adds a rug representation (1-d plot) of the data to the plot, logical. Default: TRUE.

...

other graphical paramters passed to plot.

Value

A plot is produced and nothing is returned

Details

The linear predictor \(basis(xvar) * \beta_xvar\) is plotted against xvar, where basis is the expansion provided in the original call to sail.

See Also

coef.sail predict.sail, rug

Examples

Run this code
# NOT RUN {
f.basis <- function(i) splines::bs(i, degree = 3)
# Parallel
library(doParallel)
cl <- makeCluster(2)
registerDoParallel(cl)
cvfit <- cv.sail(x = sailsim$x, y = sailsim$y, e = sailsim$e,
                 parallel = TRUE, nlambda = 10,
                 maxit = 100, basis = f.basis,
                 nfolds = 3, dfmax = 10)
stopCluster(cl)
# plot cv-error curve
plot(cvfit)
# non-zero estimated coefficients at lambda.min
predict(cvfit, type = "nonzero", s="lambda.min")
# plot main effect for X4 with a line for the truth also
plotMain(cvfit$sail.fit, x = sailsim$x, xvar = "X4",
         s = cvfit$lambda.min, f.truth = sailsim$f4)
# }

Run the code above in your browser using DataLab