# Generate mixed data: some seasonal, some polynomial
set.seed(42)
t <- seq(0, 10, length.out = 100)
# 3 seasonal curves
X_seasonal <- matrix(0, 3, 100)
for (i in 1:3) {
X_seasonal[i, ] <- sin(2 * pi * t / 2.5) + rnorm(100, sd = 0.2)
}
# 3 polynomial curves
X_poly <- matrix(0, 3, 100)
for (i in 1:3) {
X_poly[i, ] <- 0.1 * t^2 - t + rnorm(100, sd = 0.5)
}
fd <- fdata(rbind(X_seasonal, X_poly), argvals = t)
# Auto-select optimal basis for each curve
result <- select.basis.auto(fd)
print(result)
# Should detect: first 3 as Fourier, last 3 as P-spline
table(result$basis.type)
Run the code above in your browser using DataLab