Description Usage Arguments Details Value Note Author(s) References See Also Examples
Calculate operator matrices for the STL decomposition for a univariate equally-spaced design time series.
1 2 3 4 5 6 7 8 9 10 11 12 | ## Default S3 method:
stlOp(n, n.p, s.window, s.degree = 1,
t.window = NULL, t.degree = 1, fc.window = NULL, fc.degree = NULL,
l.window = nextodd(n.p), l.degree = t.degree, critfreq
= 0.05, inner = 2, n.ahead = 0, s.blend = 0, t.blend =
0, l.blend = t.blend, fc.blend = NULL, fc.name = NULL,
arma = NULL, stats = TRUE)
## S3 method for class 'stl'
stlOp(x, n.ahead=0, s.blend=0, t.blend=0,
l.blend=t.blend, critfreq=0.05, arma=NULL, stats=TRUE)
## S3 method for class 'stl2'
stlOp(x, n.ahead=0, arma=NULL, stats=TRUE)
|
n |
number of observations in the time series. |
x |
object of class |
n.p |
the periodicity of the seasonal component. |
s.window |
either the character string |
s.degree |
degree of locally-fitted polynomial in seasonal extraction. Should be 0, 1, or 2. |
t.window |
the span (in lags) of the loess window for trend extraction, which should be odd. If |
t.degree |
degree of locally-fitted polynomial in trend extraction. Should be 0, 1, or 2. |
l.window |
the span (in lags) of the loess window of the low-pass filter used for each subseries. Defaults to the smallest odd integer greater than or equal to |
l.degree |
degree of locally-fitted polynomial for the subseries low-pass filter. Should be 0, 1, or 2. |
critfreq |
the critical frequency to use for automatic calculation of smoothing windows for the trend and high-pass filter. |
n.ahead |
number of time units into the future to compute the operator matrices for. This will be used for prediction. |
fc.window |
vector of lengths of windows for loess smoothings for other trend frequency components after the original STL decomposition has been obtained. The smoothing is applied to the data with the STL seasonal component removed. A frequency component is computed by a loess fit with the window length equal to the first element of fc.window, the component is removed, another component is computed with the window length equal to the second element of fc.window, and so forth. In most cases, the values of the argument should be decreasing, that is, the frequency bands of the fitted components should increase. The robustness weights from original STL are used as weights in the loess fitting if specified. |
fc.degree |
vector of degrees of locally-fitted polynomial in the loess smoothings for the frequency components specified in fc.window. Values of 0, 1 and 2 are allowed. If the length of fc.degree is less than that of fc.window, the former is expanded to the length of the latter using rep; thus, giving the value 1 specifies a degree of 1 for all components. |
fc.name |
vector of names of the post-trend smoothing operations specified by |
inner |
integer; the number of ‘inner’ (backfitting) iterations; usually very few (2) iterations suffice. |
s.blend, t.blend, l.blend, fc.blend |
vectors of proportion of blending to degree 0 polynomials at the endpoints of the series. |
arma |
object of class |
stats |
whether or not to calculate auxiliary statistics for the overall STL fit operator matrix. |
The STL operator matrix is the matrix that yields the fitted values (seasonal + trend) through a linear operation with the observed time series. It is obtained through a series of linear filters. If post-trend smoothing is specified through fc.window, ...
, then the overall operator matrix will be the seasonal operator plus the operator for each post-trend smoothing. If ARMA modeling is specified, this will also be factored in to the calculation of the overall operator matrix.
a list of class "stlop"
.
fit |
the overall operator matrix, a list of class |
seas |
the operator matrix for just the seasonal component, an object of class |
trend |
the operator matrix for just the trend component, a list of class |
fc |
a list of operator matrices corresponding to post-trend frequency components, if specified. |
at |
the values at which the operator matrices were calculated, which will either be |
pars |
parameters used in the fitting. |
This function does a lot of n
xn
matrix multiplication. Be aware of this when choosing n
. While the loess operator matrices are calculated in C, the matrix multiplication happens in R. This is because of the speed of BLAS, which is especially good if R has been compiled with threaded BLAS.
Ryan Hafen
R. B. Cleveland, W. S. Cleveland, J.E. McRae, and I. Terpenning (1990) STL: A Seasonal-Trend Decomposition Procedure Based on Loess. Journal of Official Statistics, 6, 3-73.
W. S. Cleveland, E. Grosse and W. M. Shyu (1992) Local regression models. Chapter 8 of Statistical Models in S eds J. M. Chambers and T. J. Hastie, Wadsworth & Brooks/Cole.
stl
, plotVar
,
loessOp
, predict.stlop
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 | sop <- stlOp(50, n.p=7, s.window="periodic")
plotVar(sop)
plotVar(sop$seas)
# stl blending the trend
t.blend <- list(deg=0, span=11, blend.p=0.5, n.b=20)
sop2 <- stlOp(50, n.p=7, s.window="periodic", t.blend=t.blend)
plotVar(sop2)
plotOp(sop$fit)
# predicting ahead
sop <- stlOp(100, n.p=7, s.window=51, s.degree=1, n.ahead=7)
plotVar(sop)
# now stl + further loess smoothing, predicting ahead 7 days
# first get day-of-week component, then smooth with span 1001
# followed by smooth of span 91
n <- 200
rop <- stlOp(n, 7, s.window="periodic", t.window=39, n.ahead=7,
fc.window=c(1001, 91), fc.degree=c(1, 2), fc.blend=c(0, 0.5))
plotVar(rop)
# do same thing the hard way (without specifying fc.degree, etc.)
# just to illustrate handling elements of stlop objects
tmp <- stlOp(n, 7, s.window="periodic", t.window=39, n.ahead=7)
dow <- tmp$seas$O
fc1 <- loessOp(n, span=1001, degree=1, at=1:207)$O
fc2 <- loessOp(n, span=91, degree=2, at=1:207, blend=0.5)$O
rop2 <- dow + fc1 - fc1
fc2
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.