Learn R Programming

neuralGAM (version 2.0.1)

autoplot.neuralGAM: Autoplot method for neuralGAM objects (epistemic-only)

Description

Produce effect/diagnostic plots from a fitted neuralGAM model. Supported panels:

  • which = "response": fitted response vs. index, with optional epistemic confidence intervals (CI).

  • which = "link": linear predictor (link scale) vs. index, with optional CI.

  • which = "terms": single per-term contribution \(g_j(x_j)\) on the link scale, with optional CI band for the smooth (epistemic).

Usage

# S3 method for neuralGAM
autoplot(
  object,
  newdata = NULL,
  which = c("response", "link", "terms"),
  interval = c("none", "confidence"),
  level = 0.95,
  forward_passes = 150,
  term = NULL,
  rug = TRUE,
  ...
)

Value

A single ggplot object.

Arguments

object

A fitted neuralGAM object.

newdata

Optional data.frame/list of covariates. If omitted, training data are used.

which

One of c("response","link","terms"). Default "response".

interval

One of c("none","confidence"). Default "confidence".

level

Coverage level for confidence intervals (e.g., 0.95). Default 0.95.

forward_passes

Integer. Number of MC-dropout forward passes used when uncertainty_method %in% c("epistemic","both").

term

Single term name to plot when which = "terms".

rug

Logical; if TRUE (default), add rugs to continuous term plots.

...

Additional arguments passed to predict.neuralGAM.

Author

Ines Ortega-Fernandez, Marta Sestelo

Details

Uncertainty semantics (epistemic only)

  • CI: Uncertainty about the fitted mean.

  • For the response, SEs are mapped via the delta method;

  • For terms, bands are obtained as \(\hat g_j \pm z \cdot SE(\hat g_j)\) on the link scale.

Examples

Run this code
if (FALSE) {

library(neuralGAM)
dat <- sim_neuralGAM_data()
train <- dat$train
test  <- dat$test

ngam <- neuralGAM(
  y ~ s(x1) + x2 + s(x3),
  data = train, family = "gaussian", num_units = 128,
  uncertainty_method = "epistemic", forward_passes = 10
)
## --- Autoplot (epistemic-only) ---
# Per-term effect with CI band
autoplot(ngam, which = "terms", term = "x1", interval = "confidence")  +
  ggplot2::xlab("x1") + ggplot2::ylab("Partial effect")

# Request a different number of forward passes or CI level:
autoplot(ngam, which = "terms", term = "x1", interval = "confidence",
forward_passes = 15, level = 0.7)
# Response panel
autoplot(ngam, which = "response")

# Link panel with custom title
autoplot(ngam, which = "link")  +
  ggplot2::ggtitle("Main Title")

}

Run the code above in your browser using DataLab