funbootband
computes simultaneous prediction and
confidence bands for dense time series data (e.g., gait curves
sampled on a common grid). It accepts ordinary matrix/array inputs and
internally maps them to a smooth functional representation (finite
Fourier basis by default) for calibration. It supports i.i.d. and
clustered (hierarchical) designs and uses a fast
Rcpp backend for the bootstrap.
The stable release is available on CRAN:
install.packages("funbootband")
You can install the development version of funbootband from GitHub with:
# install.packages("pak")
::pak("koda86/funbootband-cran") pak
Below we simulate smooth time-series data from a Gaussian-process model and compute both simultaneous prediction and confidence bands:
library(funbootband)
set.seed(1)
<- 200; n <- 10
T <- seq(0, 1, length.out = T)
x
# simulate smooth Gaussian-process-like curves
<- 10 * sin(2 * pi * x)
mu <- 0.12; sig <- 3
ell <- outer(x, x, function(s, t) sig^2 * exp(-(s - t)^2 / (2 * ell^2)))
Kmat <- eigen(Kmat + 1e-8 * diag(T), symmetric = TRUE)
ev <- matrix(rnorm(T * n), T, n)
Z <- mu + ev$vectors %*% (sqrt(pmax(ev$values, 0)) * Z)
Y <- Y + matrix(rnorm(T * n, sd = 0.2), T, n)
Y
<- band(Y, type = "prediction", alpha = 0.11, iid = TRUE, B = 1000L, k.coef = 50L)
fit_pred <- band(Y, type = "confidence", alpha = 0.11, iid = TRUE, B = 1000L, k.coef = 50L) fit_conf
This example illustrates the use of band()
for
clustered time-series data, where each group (cluster)
has its own mean pattern and within-cluster variation.
library(funbootband)
set.seed(2)
<- 200
T <- c(5, 5)
m <- seq(0, 1, length.out = T)
x
# cluster-specific means
<- list(
mu function(z) 8 * sin(2 * pi * z),
function(z) 8 * cos(2 * pi * z)
)
# smooth within-cluster variation
<- cbind(sin(2 * pi * x), cos(2 * pi * x))
Bm <- function(k) {
gen_curve <- rnorm(ncol(Bm), sd = c(2.0, 1.5))
sc + as.vector(Bm %*% sc)
mu[[k]](x)
}
<- lapply(seq_along(m), function(k) {
Ylist sapply(seq_len(m[k]), function(i) gen_curve(k) + rnorm(T, sd = 0.6))
})<- do.call(cbind, Ylist)
Y colnames(Y) <- unlist(mapply(
function(k, mk) paste0("C", k, "_", seq_len(mk)),
seq_along(m), m
))
<- band(Y, type = "prediction", alpha = 0.11, iid = FALSE, B = 1000L, k.coef = 50L)
fit_pred <- band(Y, type = "confidence", alpha = 0.11, iid = FALSE, B = 1000L, k.coef = 50L) fit_conf