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

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

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.

Value

A single ggplot object.

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.

Author

Ines Ortega-Fernandez, Marta Sestelo

Examples

# \dontrun{

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
)
#> [1] "Initializing neuralGAM..."
#> Hint: To use tensorflow with `py_require()`, call `py_require("tensorflow")` at the start of the R session
#> Error in validate_activation(activation): Invalid activation 'relu'. Use a valid tf.keras activation name or an R function.
## --- Autoplot (epistemic-only) ---
# Per-term effect with CI band
autoplot(ngam, which = "terms", term = "x1", interval = "confidence")  +
  ggplot2::xlab("x1") + ggplot2::ylab("Partial effect")
#> Error: object 'ngam' not found

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

# Link panel with custom title
autoplot(ngam, which = "link")  +
  ggplot2::ggtitle("Main Title")
#> Error: object 'ngam' not found

# }