Generate predictions from a fitted neuralGAM model. Supported types:

  • type = "link" (default): linear predictor on the link scale.

  • type = "response": predictions on the response scale.

  • type = "terms": per-term contributions to the linear predictor (no intercept).

Uncertainty estimation via MC Dropout (epistemic only)

  • If se.fit = TRUE, standard errors (SE) of the fitted mean are returned (mgcv-style via Monte Carlo Dropout).

  • For type = "response", SEs are mapped to the response scale by the delta method: \(se_\mu = |d\mu/d\eta| \cdot se_\eta\).

  • interval = "confidence" returns CI bands derived from SEs; prediction intervals are not supported.

  • For type = "terms", interval="confidence" returns per-term CI matrices (and se.fit when requested).

Details

  • Epistemic SEs (CIs) are obtained via Monte Carlo Dropout. When type != "terms" and SEs/CIs are requested in the presence of smooth terms, uncertainty is aggregated jointly to capture cross-term covariance in a single MC pass set. Otherwise, per-term variances are used (parametric variances are obtained from stats::predict(..., se.fit=TRUE)).

  • For type="terms", epistemic SEs and CI matrices are returned when requested.

  • PIs are not defined on the link scale and are not supported.

# S3 method for class 'neuralGAM'
predict(
  object,
  newdata = NULL,
  type = c("link", "response", "terms"),
  terms = NULL,
  se.fit = FALSE,
  interval = c("none", "confidence"),
  level = 0.95,
  forward_passes = 150,
  verbose = 1,
  ...
)

Arguments

object

A fitted neuralGAM object.

newdata

Optional data.frame/list of covariates at which to predict. If omitted, the training data cached in the object are used.

type

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

terms

If type = "terms", character vector of term names to include. If NULL, all terms are returned. Intercept is not included (as in mgcv).

se.fit

Logical; if TRUE, return SEs of the fitted mean (epistemic). Default FALSE. For type="terms", returns a matrix of per-term SEs when available.

interval

One of c("none","confidence") (default "none"). For type="terms", setting interval="confidence" returns per-term CI matrices.

level

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

forward_passes

Integer; number of MC-dropout forward passes when computing epistemic uncertainty.

verbose

Integer (0/1). Default 1.

...

Other options (passed on to internal predictors).

Value

  • type="terms":

    • interval="none": matrix of per-term contributions; if se.fit=TRUE, a list with $fit, $se.fit.

    • interval="confidence": a list with matrices $fit, $se.fit, $lwr, $upr.

  • type="link" or type="response":

    • interval="none": vector (or list with $fit, $se.fit if se.fit=TRUE).

    • interval="confidence": data.frame with fit, lwr, upr.

Author

Ines Ortega-Fernandez, Marta Sestelo

Examples

# \dontrun{

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

ngam0 <- neuralGAM(
  y ~ s(x1) + x2 + s(x3),
  data = train, family = "gaussian",
  num_units = 128, uncertainty_method = "epistemic"
)
#> [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.
link_ci  <- predict(ngam0, type = "link", interval = "confidence",
                    level = 0.95, forward_passes = 10)
#> Error: object 'ngam0' not found
resp_ci  <- predict(ngam0, type = "response", interval = "confidence",
                    level = 0.95, forward_passes = 10)
#> Error: object 'ngam0' not found
trm_se   <- predict(ngam0, type = "terms",
                    se.fit = TRUE, forward_passes = 10)
#> Error: object 'ngam0' not found
# }