# Create seasonal data with trend
t <- seq(0, 20, length.out = 400)
period <- 2 # corresponds to 40 observations
period_obs <- 40
X <- matrix(0.05 * t + sin(2 * pi * t / period) + rnorm(length(t), sd = 0.2), nrow = 1)
fd <- fdata(X, argvals = t)
# Perform STL decomposition
result <- stl.fd(fd, period = period_obs)
print(result)
# Plot the decomposition
plot(result)
# Non-robust version (faster but sensitive to outliers)
result_fast <- stl.fd(fd, period = period_obs, robust = FALSE)
Run the code above in your browser using DataLab