seasonal.smooth: Smooth Seasonal Component of Time Series

Description Usage Arguments Details Value See Also Examples

Description

Extracts seasonal component of time series by fitting the data with a linear combination of smooth periodic functions.

Usage

1
seasonal.smooth(x, basis = create.fourier.basis(nbasis = 3), lambda = 0, ...)

Arguments

x

A univariate time series.

basis

A functional basis object (see basisfd). By default, use a linear combination of const, sin((2*pi)*t) and cos((2*pi)*t).

lambda

A nonnegative number specifying the amount of smoothing. By default, apply no additional smoothing.

...

Not currently used.

Details

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.

Value

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.

See Also

smooth.basisPar, fd for functional data objects, seasonal.ave for alternative seasonal extraction method.

Examples

 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")

aparamon/mar1s documentation built on May 5, 2019, 6:54 p.m.