Description Usage Arguments Details Value See Also Examples
Extracts seasonal component of time series by fitting the data with a linear combination of smooth periodic functions.
1 | seasonal.smooth(x, basis = create.fourier.basis(nbasis = 3), lambda = 0, ...)
|
x |
A univariate time series. |
basis |
A functional basis object (see |
lambda |
A nonnegative number specifying the amount of smoothing. By default, apply no additional smoothing. |
... |
Not currently used. |
Although it is possible to specify arbitrary functional basis object,
the function will only work properly if the basis is periodical on the
unit interval. It is recommended to use a Fourier basis with default
period (create.fourier.basis
).
Positive values of lambda
imply a restriction on roughness of
the result. The more the value, the more smooth result is; see
smooth.basis
for more detailed description.
A time series object with times from 0 to 1 and the same frequency as
x
. The smoothing functional data object is stored in attribute
fd
.
smooth.basisPar
, fd
for
functional data objects, seasonal.ave
for alternative
seasonal extraction method.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | set.seed(19860306)
## Artificial example
x <- ts(sin(2*pi*(3:97)/10) + 0.5*rnorm(length(3:97)),
start = c(0, 3), frequency = 10)
fourier3 <- seasonal.smooth(x)
fourier9 <- seasonal.smooth(x, create.fourier.basis(nbasis = 9))
fourier9s<- seasonal.smooth(x, create.fourier.basis(nbasis = 9), 1E-6)
plot.default(time(x)%%1, x, xlab = "Phase")
points(fourier3, pch = 20, col = "blue")
lines(attr(fourier3, "fd"), col = "blue")
points(fourier9, pch = 20, col = "green")
lines(attr(fourier9, "fd"), col = "green")
points(fourier9s,pch = 20, col = "red")
lines(attr(fourier9s, "fd"),col = "red")
legend("bottomleft",
legend = c("Fourier-3 basis",
"Fourier-9 basis",
"Fourier-9 basis, smooth"),
col = c("blue", "green", "red"),
lty = "solid")
## Realistic example
data(nesterov.index, package = "mar1s")
x <- log(nesterov.index[, "mean"])
x[x < -10] <- -Inf
fourier3 <- seasonal.smooth(x)
fourier9 <- seasonal.smooth(x, create.fourier.basis(nbasis = 9))
fourier9s<- seasonal.smooth(x, create.fourier.basis(nbasis = 9), 2E-5)
plot.default(time(x)%%1, x, xlab = "Phase", pch = ".")
lines(attr(fourier3, "fd"), col = "blue")
lines(attr(fourier9, "fd"), col = "green")
lines(attr(fourier9s,"fd"), col = "red")
legend("topleft",
legend = c("Fourier-3 basis",
"Fourier-9 basis",
"Fourier-9 basis, smooth"),
col = c("blue", "green", "red"),
lty = "solid")
|
Loading required package: cmrutils
Loading required package: chron
Loading required package: fda
Loading required package: splines
Loading required package: Matrix
Attaching package: 'fda'
The following object is masked from 'package:graphics':
matplot
Loading required package: zoo
Attaching package: 'zoo'
The following objects are masked from 'package:base':
as.Date, as.Date.numeric
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.