plotInter: Plot Interaction Effects from sail object

Description Usage Arguments Value See Also Examples

View source: R/plot.R

Description

Takes a fitted sail object produced by sail() or cv.sail()$sail.fit and plots a persp 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

1
2
3
plotInter(object, x, xvar, s, f.truth, interation.only = TRUE,
  truthonly = FALSE, npoints = 30, col = c("#56B4E9", "#D55E00"),
  title_z = "", xlab, ylab, zlab, ...)

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 two numeric vectors e.g. f(x,e) corresponding the xvar column in x of length nrow(x) and the exposure variable contained in the sail object. A second persp will be plotted for the truth

interation.only

if TRUE only the interaction part is used to calculate the linear predictor, i.e., linear predictor = E * f(X) * interaction_effects. If FALSE, then linear predictor = E * β_E + f(X) * interaction_effects + E * f(X) * interaction_effects. Default: TRUE

truthonly

only plot the truth. f.truth must be specified if this argument is set to TRUE. Default: FALSE

npoints

number of points in the grid to calculate the perspective plot. Default: 30

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")

title_z

title for the plot, Default: ”

xlab

character for xlabel. if missing, variable name is used

ylab

character for ylabel. if missing, variable name is used

zlab

character for zlabel. if missing, variable name is used

...

currently ignored

Value

A plot is produced and nothing is returned

See Also

persp coef.sail predict.sail, rug

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
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 interaction effect for X4 and the true interaction effect also
plotInter(cvfit$sail.fit, x = sailsim$x, xvar = "X3",
          f.truth = sailsim$f4.inter,
          s = cvfit$lambda.min,
          title_z = "Estimated")

sahirbhatnagar/sail documentation built on July 17, 2021, 5:10 a.m.