ALE.gam: Create Accumulated Local Effects (ALE) for GAMs

View source: R/ALE_gam.R

ALE.gamR Documentation

Create Accumulated Local Effects (ALE) for GAMs

Description

Create Accumulated Local Effects (ALE) for GAMs

Usage

## S3 method for class 'gam'
ALE(
  o,
  x,
  newdata = NULL,
  type = "link",
  nbin = 40,
  bins = NULL,
  oind = 1,
  center = 1,
  ...
)

Arguments

o

a fitted GAM model.

x

the name of the variable along which we want to produce the ALE effect.

newdata

optional argument indicating the data to be used to produce the ALE effect. If NULL the data contained in o will be used.

type

if set to "link" (the default option) the model output will be the linear predictor, if set to "response" the model output is on the scale of the response.

nbin

number of intervals into which the predictor range is divided when calculating the ALE effects. Ignored for factor predictors of if the bins argument is provided.

bins

a grid defining the interval into which the predictor should be binned. Determined automatically by default. Ignored for factor predictors.

oind

relevant only when the model o has multiple linear predictors (e.g. for GAMLSS models or for multinom regression). oind is the index of the output variable used for the ALE effect (i.e., only predict(o)[ , oind].

center

if set to 0 the ALE effect is not centered and the effect is equal to zero at the smallest value on x-grid. If set to 1 (default) the effect is centered as done in Apley and Zhu, 2016. That is, an estimate of the expected value of the uncentered effect is subtracted, so the effect is centered similarly to smooth effects in GAMs. If set to 2, the expected value of the model output at the smallest value on the x-grid is added to the uncentered effect.

...

extra arguments that will be passed to predict and vcov.

Value

An object of class ALEXD, where X is the number of dimensions, which can be plotted using plot.ALEXD (only X=1 is provided at the moment).

Author(s)

Matteo Fasiolo and Christian Capezza, with some internal code having been adapted from the ALEPlot package of Dan Apley.

References

Apley, D.W., and Zhu, J, 2016. Visualizing the effects of predictor variables in black box supervised learning models. arXiv preprint arXiv:1612.08468.

See Also

plot.ALE1D

Examples

# Example using Tweedie distribution
library(mgcViz)
set.seed(3)
n<-400
## Simulate data...
dat <- gamSim(1,n=n,dist="poisson",scale=.2)
dat$y <- rTweedie(exp(dat$f),p=1.3,phi=.5) ## Tweedie response

## Fit a fixed p Tweedie, with wrong link ...
b <- gam(list(y~s(x0)+s(x1)+s(x2)+s(x3),~1,~1), family=twlss(), data=dat)

plot(ALE(b, "x2", type = "response", oind = 1))

# With manually chosen bins
plot(ALE(b, "x2", type = "response", oind = 1, 
         bins = c(0.1, 0.25, 0.5, 0.6, 0.9, 0.95, 0.99, 1)))


mgcViz documentation built on Oct. 6, 2023, 5:09 p.m.

Related to ALE.gam in mgcViz...