| vem_fit | R Documentation |
Fits one or more functional curves using Bayesian basis function selection
via the Variational EM algorithm, with an Ornstein-Uhlenbeck within-curve
correlation structure. Internally calls vem_smooth to run the
VEM algorithm.
If a single value is provided for K, the model is fitted using that fixed
number of basis functions. If a vector of candidate values is supplied, the
function tune_vem_by_gcv is called to automatically select the
optimal K based on the GCV criterion. The resulting fitted object provides
methods for plot, predict, coef, and summary via the corresponding S3
methods plot.vem_fit, predict.vem_fit,
coef.vem_fit, and summary.vem_fit.
vem_fit(
y,
Xt,
K = NULL,
basis_type = c("cubic_bspline", "fourier"),
selection_metric = c("mean", "per_curve"),
threshold = 0.5,
center = FALSE,
scale = FALSE,
period = NULL,
initial_values_fn = NULL,
lambda_1 = NULL,
lambda_2 = NULL,
delta_1 = NULL,
delta_2 = NULL,
...
)
y |
Named list of numeric vectors, one per curve. |
Xt |
Numeric vector of time points, common across all curves. |
K |
Integer or integer vector of candidate basis sizes. If a single
value, fits directly at that |
basis_type |
Character. One of |
selection_metric |
Character. |
threshold |
Numeric in |
center |
Logical. If |
scale |
Logical. If |
period |
Numeric. Period for Fourier bases. Defaults to the domain
range |
initial_values_fn |
Function with signature |
lambda_1, lambda_2 |
Positive scalars. Inverse-Gamma prior hyperparameters
for |
delta_1, delta_2 |
Positive scalars. Inverse-Gamma prior hyperparameters
for |
... |
Additional arguments passed to |
An object of class "vem_fit" containing:
modelThe fitted vem_smooth object (global fit), or a
named list of per-curve model objects (composite fit).
selected_KInteger vector of length m. The K
used for each curve.
best_KThe single selected K (global fit), or a vector
(composite fit).
tuningOutput of tune_vem_by_gcv, including
the full GCV matrix and all candidate fits. NULL if a single
K was supplied.
scaling_paramsList with means and sds used
for standardization. Used by predict.vem_fit and
plot.vem_fit to back-transform predictions.
data_origThe input curves in their original scales.
basis_type, is_composite, Xt, callMetadata stored for use by S3 methods.
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
vem_smooth, plot.vem_fit,
predict.vem_fit, coef.vem_fit,
summary.vem_fit
data(toy_curves)
fit <- vem_fit(
y = toy_curves$y,
Xt = toy_curves$Xt,
K = 8
)
summary(fit)
plot(fit, curve_idx = 1)
coef(fit)
predict(fit)
# GCV tuning over a grid of K values
fit_gcv <- vem_fit(
y = toy_curves$y,
Xt = toy_curves$Xt,
K = c(6, 8, 10)
)
fit_gcv$best_K
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.