These functions implement the inner and outer loops based of the procedure to locate outliers following the approach described in Chen and Liu (1993) .
locate.outliers.oloop(y, fit, types = c("AO", "LS", "TC"),
cval = NULL, maxit.iloop = 4, maxit.oloop = 4,
delta = 0.7, n.start = 50, logfile = NULL)
locate.outliers.iloop(resid, pars, cval = 3.5,
types = c("AO", "LS", "TC"), maxit = 4, delta = 0.7, n.start = 50,
logfile = NULL)
a time series.
an Arima
or stsm
object. The output from arima
,
auto.arima
or the functions to fit a structural time series model
available in package stsm
a time series. Residuals from a time series model fitted to the data.
a list containing the parameters of the model fitted to the data.
See details in locate.outliers
.
a numeric. The critical value to determine the significance of each type of outlier.
a character vector indicating the type of outlier to be considered by the
detection procedure among the following:
innovational outliers ("IO"
), additive outliers ("AO"
),
level shifts ("LS"
), temporary changes ("TC"
)
and seasonal level shifts ("SLS"
).
a numeric. The maximum number of iterations in the inner loop.
a numeric. Same as argument as maxit
to be passed to
locate.outliers.iloop
.
a numeric. The maximum number of iterations in the outer loop.
a numeric. Parameter of the temporary change type of outlier.
a numeric. The number of warming observations added to the
input passed to the Kalman filter. Used only if pars
is related to a
structural time series model.
a character or NULL
. It is the path to the file where
tracking information is printed. Ignored if NULL
.
locate.outliers.iloop
returns a data frame defining by rows each
detected outlier. The data frame follows the same format as the output from
locate.outliers
.
locate.outliers.oloop
returns a list containing the following elements:
fit
: information from the last fitted model that will be required by
other functions in the automatic procedure (parameter estimates, residuals and
number of observations);
outliers
: a data frame defining by rows the detected outliers;
iter
: the number of iterations employed by the outer loop.
See also the details section in locate.outliers
.
The function locate.outliers.iloop
iterates around the function
locate.outliers
until no additional outliers are found or the maximum number
of iterations is reached.
After each iteration, the effect of the outliers on the residuals of the fitted model
is removed and the \(t\)-statistics are obtained again for the modified residuals.
No model selection or refit of the model is conducted within this loop.
The function locate.outliers.oloop
is the outer loop of the procedure to locate
outliers. It iterates around the function locate.outliers.iloop
.
At the end of each iteration the detected outliers are removed from the original
data. Then, the time series model is fitted (or selected) again for the adjusted series
and a new search for outliers is executed. The outer loop stops when no additional outliers
are detected.
In function locate.outliers.oloop
,
if no value is specified for argument cval
a default value based on the sample size
is used. Let \(n\) be the number of observations. If \(n \le 50\) then cval
is set
equal to \(3.0\); If \(n \ge 450\) then cval
is set equal to \(4.0\);
otherwise cval
is set equal to \(3 + 0.0025 * (n - 50)\).
Chen, C. and Liu, Lon-Mu (1993). ‘Joint Estimation of Model Parameters and Outlier Effects in Time Series’. Journal of the American Statistical Association, 88(421), pp. 284-297.
G<U+00F3>mez, V. and Maravall, A. (1996). Programs TRAMO and SEATS. Instructions for the user. Banco de Espa<U+00F1>a, Servicio de Estudios. Working paper number 9628. http://www.bde.es/f/webbde/SES/Secciones/Publicaciones/PublicacionesSeriadas/DocumentosTrabajo/96/Fich/dt9628e.pdf
G<U+00F3>mez, V. and Taguas, D. (1995). Detecci<U+00F3>n y Correcci<U+00F3>n Autom<U+00E1>tica de Outliers con TRAMO: Una Aplicaci<U+00F3>n al IPC de Bienes Industriales no Energ<U+00E9>ticos. Ministerio de Econom<U+00ED>a y Hacienda. Document number D-95006. http://www.sepg.pap.minhap.gob.es/sitios/sepg/es-ES/Presupuestos/Documentacion/Documents/DOCUMENTOS%20DE%20TRABAJO/D95006.pdf
L<U+00F3>pez-de-Lacalle, J. (2014). ‘Structural Time Series Models’. R package version 1.2. https://CRAN.R-project.org/package=stsm
Kaiser, R., and Maravall, A. (1999). Seasonal Outliers in Time Series. Banco de Espa<U+00F1>a, Servicio de Estudios. Working paper number 9915.
# NOT RUN {
# additional outliers may be detected in the inner or outlier loops
# in this case, the inner does not find further potential outliers
# and stops in the first iteration, while the outer loop detects
# a new outlier
data("hicp")
y <- log(hicp[["011600"]])
fit <- arima(y, order = c(1, 1, 0), seasonal = list(order = c(2, 0, 2)))
resid <- residuals(fit)
pars <- coefs2poly(fit)
otypes <- c("AO", "LS", "TC")
mo0 <- locate.outliers(resid, pars, types = otypes)
mo0
mo1 <- locate.outliers.iloop(resid, pars, types = otypes)
mo1
mo2 <- locate.outliers.oloop(y, fit, types = otypes)
mo2$iter
mo2$outliers
# }
Run the code above in your browser using DataLab