plot.vem_fit: Plot a VEM Fit with Credible Band

View source: R/plot.vem_fit.R

plot.vem_fitR Documentation

Plot a VEM Fit with Credible Band

Description

Plots observed data, the posterior mean fitted curve, and an optional 95% credible band for a single curve from a vem_fit object. The credible band provides uncertainty quantification by sampling from the variational posteriors: \beta_i \sim \text{MVN}(\boldsymbol{\mu}_{\boldsymbol{\beta}_i}, \boldsymbol{\Sigma}_{\boldsymbol{\beta}_i}) and Z_{ki} \sim \text{Bernoulli}(p_{ki}). Predictions are automatically back-transformed if the model was fitted with center = TRUE or scale = TRUE.

Usage

## S3 method for class 'vem_fit'
plot(
  x,
  curve_idx = 1,
  type = c("polygon", "lines"),
  show_CI = TRUE,
  n_samples = 200,
  alpha_shade = 0.25,
  ylim = NULL,
  xlab = "t",
  ylab = "Value",
  show_basis = FALSE,
  ...
)

Arguments

x

A vem_fit object from vem_fit.

curve_idx

Integer. Index of the curve to plot. Default 1.

type

Character. Credible band style: "polygon" (shaded region) or "lines" (dashed lines). Default "polygon".

show_CI

Logical. If TRUE, compute and display the credible band. Default TRUE.

n_samples

Integer. Number of posterior draws used to construct the credible band. Default 200.

alpha_shade

Numeric in (0,1). Opacity of the shaded credible band (type = "polygon" only). Default 0.25.

ylim

Optional numeric vector of length 2. If NULL, axis limits are set to cover the data and credible band.

xlab

Character. Label for the horizontal axis. Default "t" (the evaluation point). Supply a domain-specific label where appropriate (e.g., "Time", "Age", "Frequency").

ylab

Character. Label for the vertical axis. Default "Value".

show_basis

Logical. If TRUE, adds a subplot below the main plot showing each basis function coloured by inclusion status (blue = active, grey = inactive). Default FALSE.

...

Additional graphical parameters passed to plot().

Value

Invisibly returns NULL. Called for its side effect of producing a plot.

References

da Cruz, A. C., de Souza, C. P. E., & Sousa, P. H. T. O. (2024). Fast Bayesian basis selection for functional data representation with correlated errors. arXiv:2405.20758. https://arxiv.org/abs/2405.20758

See Also

vem_fit, predict.vem_fit

Examples


  data(toy_curves)
  fit <- vem_fit(y = toy_curves$y, Xt = toy_curves$Xt, K = 8)

  # Default: shaded credible band for curve 1
  plot(fit)

  # Dashed credible band for curve 2
  plot(fit, curve_idx = 2, type = "lines")

  # With basis selection subplot
  plot(fit, curve_idx = 1, show_basis = TRUE)

  # Suppress credible band
  plot(fit, show_CI = FALSE, main = "Mean fit only")


fda.vi documentation built on June 20, 2026, 5:06 p.m.