Title: | Automatic Univariate Time Series Modelling of many Kinds |
---|---|
Description: | Comprehensive analysis and forecasting of univariate time series using automatic time series models of many kinds. Harvey AC (1989) <doi:10.1017/CBO9781107049994>. Pedregal DJ and Young PC (2002) <doi:10.1002/9780470996430>. Durbin J and Koopman SJ (2012) <doi:10.1093/acprof:oso/9780199641178.001.0001>. Hyndman RJ, Koehler AB, Ord JK, and Snyder RD (2008) <doi:10.1007/978-3-540-71918-2>. Gómez V, Maravall A (2000) <doi:10.1002/9781118032978>. Pedregal DJ, Trapero JR and Holgado E (2024) <doi:10.1016/j.ijforecast.2023.09.004>. |
Authors: | Diego J. Pedregal [aut, cre] |
Maintainer: | Diego J. Pedregal <[email protected]> |
License: | GPL-3 |
Version: | 5.0.4 |
Built: | 2024-11-24 03:40:40 UTC |
Source: | https://github.com/cran/UComp |
Accuracy for 1 time series y and several forecasting methods py and h steps ahead py is h x nMethods x nSeries
Accuracy(py, y, s = frequency(y), collectFun = mean)
Accuracy(py, y, s = frequency(y), collectFun = mean)
py |
matrix of forecasts (h x nMethods x nForecasts) |
y |
a matrix of actual values (n x nForecasts) |
s |
seasonal period, number of observations per year |
collectFun |
aggregation function (mean, median, etc.) |
Table of results
Diego J. Pedregal
colMedians
, rowMedians
, tests
,
sumStats
, gaussTest
, ident
,
cusum
, varTest
, conv
,
armaFilter
, dif
, roots
,
zplane
, acft
, slide
,
plotSlide
, tsDisplay
,
size
## Not run: Accuracy(py, y, 12)
## Not run: Accuracy(py, y, 12)
Theoretical autocorrelation functions of ARMA models
acft(MApoly = 1, ARpoly = 1, ncoef = 38, s = 1)
acft(MApoly = 1, ARpoly = 1, ncoef = 38, s = 1)
MApoly |
coefficients of numerator polynomial in descending order |
ARpoly |
coefficients of denominator polynomial in descending order |
ncoef |
number of coefficients |
s |
seasonal period, number of observations per year |
Theoretical autocorrelation functions
Diego J. Pedregal
colMedians
, rowMedians
, tests
,
sumStats
, gaussTest
, ident
,
cusum
, varTest
, conv
,
armaFilter
, dif
, roots
,
zplane
, slide
,
plotSlide
, Accuracy
, tsDisplay
,
size
acft(c(1, -0.8), c(1, 0.8))
acft(c(1, -0.8), c(1, 0.8))
Extract AIC value of UComp object
## S3 method for class 'UComp' AIC(object, ..., k = 2)
## S3 method for class 'UComp' AIC(object, ..., k = 2)
object |
Object of class “UComp”. |
... |
Additional inputs to function. |
k |
The penalty per parameter to be used. |
Selection criteria for models with different number of
parameters, the smaller AIC the better. The formula used here is
, where
is the log-likelihood
at the optimum,
is the number of parameters plus
non-stationary states and
is the number of observations.
Mind that this formulation differs from the usual definition that
does not divide by
. This makes that AIC(m) and AIC(logLik(m))
give different results, being m an UComp object.
Diego J. Pedregal
UC
, UCmodel
, UCvalidate
, UCfilter
, UCsmooth
,
UCdisturb
, UCcomponents
## Not run: y <- log(AirPassengers) m1 <- UCmodel(y, model = "llt/equal/arma(0,0)") AIC(m1) ## End(Not run)
## Not run: y <- log(AirPassengers) m1 <- UCmodel(y, model = "llt/equal/arma(0,0)") AIC(m1) ## End(Not run)
Foreign arrivals by air in Spain in thousands of passengers (airpas).
airpas
airpas
Time series objects.
Monthly data from 1969
https://portal.mineco.gob.es/es-es/economiayempresa/EconomiaInformesMacro/Paginas/bdsice.aspx
## Not run: airpas ## End(Not run)
## Not run: airpas ## End(Not run)
Runs all relevant functions for ARIMA modelling
ARIMA( y, u = NULL, model = NULL, cnst = NULL, s = frequency(y), criterion = "bic", h = 2 * s, verbose = FALSE, lambda = 1, maxOrders = c(3, 2, 3, 2, 1, 2), bootstrap = FALSE, nSimul = 5000, fast = FALSE )
ARIMA( y, u = NULL, model = NULL, cnst = NULL, s = frequency(y), criterion = "bic", h = 2 * s, verbose = FALSE, lambda = 1, maxOrders = c(3, 2, 3, 2, 1, 2), bootstrap = FALSE, nSimul = 5000, fast = FALSE )
y |
a time series to forecast (it may be either a numerical vector or
a time series object). This is the only input required. If a vector, the additional
input |
u |
a matrix of input time series. If
the output wanted to be forecast, matrix |
model |
the model to estimate. A vector c(p,d,q,P,D,Q) containing the model orders of an ARIMA(p,d,q)x(P,D,Q)_s model. A constant may be estimated with the cnst input. Use a NULL to automatically identify the ARIMA model. |
cnst |
flag to include a constant in the model (TRUE/FALSE/NULL). Use NULL to estimate |
s |
seasonal period of time series (1 for annual, 4 for quarterly, ...) |
criterion |
information criterion for identification stage ("aic", "bic", "aicc") |
h |
forecast horizon. If the model includes inputs h is not used, the lenght of u is used instead. |
verbose |
intermediate estimation output (TRUE / FALSE) |
lambda |
Box-Cox lambda parameter (NULL: estimate) |
maxOrders |
a vector c(p,d,q,P,D,Q) containing the maximum orders of model orders to search for in the automatic identification |
bootstrap |
use bootstrap simulation for predictive distributions |
nSimul |
number of simulation runs for bootstrap simulation of predictive distributions |
fast |
fast identification (avoids post-identification checks) |
See help of ARIMAmodel
.
An object of class ARIMA
. See ARIMAmodel
.
Diego J. Pedregal
## Not run: y <- log(AirPAssengers) m1 <- ARIMA(y) m1 <- ARIMA(y, lambda = NULL) ## End(Not run)
## Not run: y <- log(AirPAssengers) m1 <- ARIMA(y) m1 <- ARIMA(y, lambda = NULL) ## End(Not run)
Estimates and forecasts ARIMA models
ARIMAestim(m)
ARIMAestim(m)
m |
an object of type |
ARIMAestim
estimates and forecasts a time series using
an ARIMA model
The same input object with the appropriate fields filled in, in particular:
p |
Estimated parameters |
yFor |
Forecasted values of output |
yForV |
Variance of forecasted values of output |
ySimul |
Bootstrap simulations for forecasting distribution evaluation |
Diego J. Pedregal
ARIMA
, ARIMAmodel
, ARIMAvalidate
,
## Not run: m1 <- ARIMAsetup(log(gdp)) m1 <- ARIMAestim(m1) ## End(Not run)
## Not run: m1 <- ARIMAsetup(log(gdp)) m1 <- ARIMAestim(m1) ## End(Not run)
Estimates and forecasts ARIMA general univariate models
ARIMAmodel( y, u = NULL, model = NULL, cnst = NULL, s = frequency(y), criterion = "bic", h = 2 * s, verbose = FALSE, lambda = 1, maxOrders = c(3, 2, 3, 2, 1, 2), bootstrap = FALSE, nSimul = 5000, fast = FALSE )
ARIMAmodel( y, u = NULL, model = NULL, cnst = NULL, s = frequency(y), criterion = "bic", h = 2 * s, verbose = FALSE, lambda = 1, maxOrders = c(3, 2, 3, 2, 1, 2), bootstrap = FALSE, nSimul = 5000, fast = FALSE )
y |
a time series to forecast (it may be either a numerical vector or
a time series object). This is the only input required. If a vector, the additional
input |
u |
a matrix of input time series. If
the output wanted to be forecast, matrix |
model |
the model to estimate. A vector c(p,d,q,P,D,Q) containing the model orders of an ARIMA(p,d,q)x(P,D,Q)_s model. A constant may be estimated with the cnst input. Use a NULL to automatically identify the ARIMA model. |
cnst |
flag to include a constant in the model (TRUE/FALSE/NULL). Use NULL to estimate |
s |
seasonal period of time series (1 for annual, 4 for quarterly, ...) |
criterion |
information criterion for identification stage ("aic", "bic", "aicc") |
h |
forecast horizon. If the model includes inputs h is not used, the lenght of u is used instead. |
verbose |
intermediate estimation output (TRUE / FALSE) |
lambda |
Box-Cox lambda parameter (NULL: estimate) |
maxOrders |
a vector c(p,d,q,P,D,Q) containing the maximum orders of model orders to search for in the automatic identification |
bootstrap |
use bootstrap simulation for predictive distributions |
nSimul |
number of simulation runs for bootstrap simulation of predictive distributions |
fast |
fast identification (avoids post-identification checks) |
ARIMAmodel
is a function for modelling and forecasting univariate
time series with Autoregressive Integrated Moving Average (ARIMA) time series models.
It sets up the model with a number of control variables that
govern the way the rest of functions in the package will work. It also estimates
the model parameters by Maximum Likelihood and forecasts the data.
An object of class ARIMA
. It is a list with fields including all the inputs and
the fields listed below as outputs. All the functions in this package fill in
part of the fields of any ARIMA
object as specified in what follows (function
ARIMA
fills in all of them at once):
After running ARIMAmodel
or ARIMA
:
p |
Estimated parameters |
yFor |
Forecasted values of output |
yForV |
Variance of forecasted values of output |
ySimul |
Bootstrap simulations for forecasting distribution evaluation |
After running ARIMAvalidate
:
table |
Estimation and validation table |
Diego J. Pedregal
## Not run: y <- log(AirPAssengers) m1 <- ARIMAmodel(y) m1 <- ARIMAmodel(y, lambda = NULL) ## End(Not run)
## Not run: y <- log(AirPAssengers) m1 <- ARIMAmodel(y) m1 <- ARIMAmodel(y, lambda = NULL) ## End(Not run)
Sets up ARIMA general models
ARIMAsetup( y, u = NULL, model = NULL, cnst = NULL, s = frequency(y), criterion = "bic", h = 2 * s, verbose = FALSE, lambda = 1, maxOrders = c(3, 2, 3, 2, 1, 2), bootstrap = FALSE, nSimul = 5000, fast = FALSE )
ARIMAsetup( y, u = NULL, model = NULL, cnst = NULL, s = frequency(y), criterion = "bic", h = 2 * s, verbose = FALSE, lambda = 1, maxOrders = c(3, 2, 3, 2, 1, 2), bootstrap = FALSE, nSimul = 5000, fast = FALSE )
y |
a time series to forecast (it may be either a numerical vector or
a time series object). This is the only input required. If a vector, the additional
input |
u |
a matrix of input time series. If
the output wanted to be forecast, matrix |
model |
the model to estimate. A vector c(p,d,q,P,D,Q) containing the model orders of an ARIMA(p,d,q)x(P,D,Q)_s model. A constant may be estimated with the cnst input. Use a NULL to automatically identify the ARIMA model. |
cnst |
flag to include a constant in the model (TRUE/FALSE/NULL). Use NULL to estimate |
s |
seasonal period of time series (1 for annual, 4 for quarterly, ...) |
criterion |
information criterion for identification stage ("aic", "bic", "aicc") |
h |
forecast horizon. If the model includes inputs h is not used, the lenght of u is used instead. |
verbose |
intermediate estimation output (TRUE / FALSE) |
lambda |
Box-Cox lambda parameter (NULL: estimate) |
maxOrders |
a vector c(p,d,q,P,D,Q) containing the maximum orders of model orders to search for in the automatic identification |
bootstrap |
use bootstrap simulation for predictive distributions |
nSimul |
number of simulation runs for bootstrap simulation of predictive distributions |
fast |
fast identification (avoids post-identification checks) |
See help of ARIMAmodel
.
An object of class ARIMA
. See ARIMAmodel
.
Diego J. Pedregal
ARIMA
, ARIMAmodel
, ARIMAvalidate
,
## Not run: y <- log(AirPAssengers) m1 <- ARIMAsetup(y) m1 <- ARIMAsetup(y, lambda = NULL) ## End(Not run)
## Not run: y <- log(AirPAssengers) m1 <- ARIMAsetup(y) m1 <- ARIMAsetup(y, lambda = NULL) ## End(Not run)
Shows a table of estimation and diagnostics results for ARIMA models
ARIMAvalidate(m)
ARIMAvalidate(m)
m |
an object of type |
The same input object with the appropriate fields filled in, in particular:
table |
Estimation and validation table |
Diego J. Pedregal
ARIMA
, ARIMAmodel
, ARIMAvalidate
,
## Not run: m1 <- ARIMAmodel(log(gdp)) m1 <- ARIMAvalidate(m1) ## End(Not run)
## Not run: m1 <- ARIMAmodel(log(gdp)) m1 <- ARIMAvalidate(m1) ## End(Not run)
AR polynomial coefficients of ARMA model
arma2tsi(MApoly, ARpoly, n = 100)
arma2tsi(MApoly, ARpoly, n = 100)
MApoly |
coefficients of numerator polynomial in descending order |
ARpoly |
coefficients of denominator polynomial in descending order |
n |
number of coefficients |
Diego J. Pedregal
Filter of time series
armaFilter(MA = 1, AR = 1, y)
armaFilter(MA = 1, AR = 1, y)
MA |
numerator polynomial |
AR |
denominator polynomial |
y |
a vector, ts or tsibble object |
Filtered time series
Diego J. Pedregal
colMedians
, rowMedians
, tests
,
sumStats
, gaussTest
, ident
,
cusum
, varTest
, conv
,
dif
, roots
,
zplane
, acft
, slide
,
plotSlide
, Accuracy
, tsDisplay
,
size
y <- armaFilter(1, c(1 , -0.8), rnorm(200))
y <- armaFilter(1, c(1 , -0.8), rnorm(200))
Inverse of Box-Cox transformation
auxInvBoxCox(y, lambda)
auxInvBoxCox(y, lambda)
y |
matrix, array or vector |
lambda |
lambda parameter of Box-Cox transformation |
Diego J. Pedregal
Extract BIC (or SBC) value of UComp object
## S3 method for class 'UComp' BIC(object, ...)
## S3 method for class 'UComp' BIC(object, ...)
object |
Object of class “UComp”. |
... |
Additional inputs to function. |
Selection criteria for models with different number of
parameters, the smaller BIC the better. The formula used here is
, where
is the log-likelihood
at the optimum,
is the number of parameters plus
non-stationary states and
is the number of observations.
Mind that this formulation differs from the usual definition that
does not divide by
. This makes that BIC(m) and BIC(logLik(m))
give different results, being m an UComp object.
Diego J. Pedregal
UC
, UCmodel
, UCvalidate
, UCfilter
, UCsmooth
,
UCdisturb
, UCcomponents
## Not run: y <- log(AirPassengers) m1 <- UCmodel(y, model = "llt/equal/arma(0,0)") BIC(m1) ## End(Not run)
## Not run: y <- log(AirPassengers) m1 <- UCmodel(y, model = "llt/equal/arma(0,0)") BIC(m1) ## End(Not run)
Runs Box-Cox transform of a time series
box.cox(x, lambda)
box.cox(x, lambda)
x |
Time series object. |
lambda |
Lambda parameter for Box-Cox transform. |
Diego J. Pedregal
inv.box.cox
, UC
, UCmodel
, UCvalidate
, UCfilter
, UCsmooth
,
UCdisturb
, UCcomponents
## Not run: y <- box.cox(AirPassengers, 0.5) plot(y) ## End(Not run)
## Not run: y <- box.cox(AirPassengers, 0.5) plot(y) ## End(Not run)
Methane concentration at Cape Grim in Australia (ch4).
ch4
ch4
Time series objects.
Monthly data from January 1992 to December 2019
## Not run: ch4 ## End(Not run)
## Not run: ch4 ## End(Not run)
Medians of matrix by columns
colMedians(x, na.rm = TRUE, ...)
colMedians(x, na.rm = TRUE, ...)
x |
a matrix |
na.rm |
boolean indicating whether to remove nans |
... |
rest of inputs |
A vector with all the medians
Diego J. Pedregal
rowMedians
, tests
,
sumStats
, gaussTest
, ident
,
cusum
, varTest
, conv
,
armaFilter
, dif
, roots
,
zplane
, acft
, slide
,
plotSlide
, Accuracy
, tsDisplay
,
size
s <- colMedians(matrix(4, 3, 2))
s <- colMedians(matrix(4, 3, 2))
1D convolution: filtering or polynomial multiplication
conv(...)
conv(...)
... |
list of vectors to convolute |
Convolution of all input vectors
Diego J. Pedregal
colMedians
, rowMedians
, tests
,
sumStats
, gaussTest
, ident
,
cusum
, varTest
,
armaFilter
, dif
, roots
,
zplane
, acft
, slide
,
plotSlide
, Accuracy
, tsDisplay
,
size
conv(c(1, -1), c(1, -2, 1)) conv(c(1, -1), c(1, 0.8))
conv(c(1, -1), c(1, -2, 1)) conv(c(1, -1), c(1, 0.8))
Cusum and cusumsq tests
cusum(y, runFromTest = FALSE)
cusum(y, runFromTest = FALSE)
y |
a vector, ts or tsibble object |
runFromTest |
internal check variable |
Diego J. Pedregal
colMedians
, rowMedians
, tests
,
sumStats
, gaussTest
, ident
,
varTest
, conv
,
armaFilter
, dif
, roots
,
zplane
, acft
, slide
,
plotSlide
, Accuracy
, tsDisplay
,
size
cusum(AirPassengers)
cusum(AirPassengers)
Discrete differencing of time series
dif(y, difs = 1, seas = 1)
dif(y, difs = 1, seas = 1)
y |
a vector, ts or tsibble object |
difs |
vector with differencing orders |
seas |
vector of seasonal periods |
Differenced time series
Diego J. Pedregal
colMedians
, rowMedians
, tests
,
sumStats
, gaussTest
, ident
,
cusum
, varTest
, conv
,
armaFilter
, roots
,
zplane
, acft
, slide
,
plotSlide
, Accuracy
, tsDisplay
,
size
dif(AirPassengers) dif(AirPassengers, 2) dif(AirPassengers, c(1, 1), c(1, 12))
dif(AirPassengers) dif(AirPassengers, 2) dif(AirPassengers, c(1, 1), c(1, 12))
Runs all relevant functions for ETS modelling
ETS( y, u = NULL, model = "???", s = frequency(y), h = 2 * s, criterion = "aicc", lambda = 1, armaIdent = FALSE, identAll = FALSE, forIntervals = FALSE, bootstrap = FALSE, nSimul = 5000, verbose = FALSE, alphaL = c(1e-08, 1 - 1e-08), betaL = alphaL, gammaL = alphaL, phiL = c(0.8, 0.98), p0 = -99999 )
ETS( y, u = NULL, model = "???", s = frequency(y), h = 2 * s, criterion = "aicc", lambda = 1, armaIdent = FALSE, identAll = FALSE, forIntervals = FALSE, bootstrap = FALSE, nSimul = 5000, verbose = FALSE, alphaL = c(1e-08, 1 - 1e-08), betaL = alphaL, gammaL = alphaL, phiL = c(0.8, 0.98), p0 = -99999 )
y |
a time series to forecast (it may be either a numerical vector or
a time series object). This is the only input required. If a vector, the additional
input |
u |
a matrix of input time series. If
the output wanted to be forecast, matrix |
model |
the model to estimate. It is a single string indicating the type of model for each component with one or two letters:
|
s |
seasonal period of time series (1 for annual, 4 for quarterly, ...) |
h |
forecast horizon. If the model includes inputs h is not used, the lenght of u is used instead. |
criterion |
information criterion for identification ("aic", "bic" or "aicc"). |
lambda |
Box-Cox lambda parameter (NULL: estimate) |
armaIdent |
check for arma models for error component (TRUE / FALSE). |
identAll |
run all models to identify the best one (TRUE / FALSE) |
forIntervals |
estimate forecasting intervals (TRUE / FALSE) |
bootstrap |
use bootstrap simulation for predictive distributions |
nSimul |
number of simulation runs for bootstrap simulation of predictive distributions |
verbose |
intermediate estimation output (TRUE / FALSE) |
alphaL |
constraints limits for alpha parameter |
betaL |
constraints limits for beta parameter |
gammaL |
constraints limits for gamma parameter |
phiL |
constraints limits for phi parameter |
p0 |
initial values for parameter search (alpha, beta, phi, gamma) with consraints:
|
See help of ETSmodel
.
An object of class ETS
. See ETSmodel
.
Diego J. Pedregal
ETSmodel
, ETSvalidate
,
ETScomponents
, ETSestim
## Not run: y <- log(AirPAssengers) m1 <- ETS(y) m1 <- ETS(y, model = "MAM") ## End(Not run)
## Not run: y <- log(AirPAssengers) m1 <- ETS(y) m1 <- ETS(y, model = "MAM") ## End(Not run)
Estimates components of ETS models
ETScomponents(m)
ETScomponents(m)
m |
an object of type |
The same input object with the appropriate fields filled in, in particular:
comp |
Estimated components in matrix form |
Diego J. Pedregal
ETS
, ETSmodel
, ETSvalidate
,
ETSestim
## Not run: m1 <- ETS(log(gdp)) m1 <- ETScomponents(m1) ## End(Not run)
## Not run: m1 <- ETS(log(gdp)) m1 <- ETScomponents(m1) ## End(Not run)
Estimates and forecasts ETS models
ETSestim(m)
ETSestim(m)
m |
an object of type |
ETSestim
estimates and forecasts a time series using an
an ETS model
The same input object with the appropriate fields filled in, in particular:
p |
Estimated parameters |
yFor |
Forecasted values of output |
yForV |
Variance of forecasted values of output |
ySimul |
Bootstrap simulations for forecasting distribution evaluation |
Diego J. Pedregal
ETS
, ETSmodel
, ETSvalidate
,
ETScomponents
## Not run: m1 <- ETSsetup(log(gdp)) m1 <- ETSestim(m1) ## End(Not run)
## Not run: m1 <- ETSsetup(log(gdp)) m1 <- ETSestim(m1) ## End(Not run)
Estimates and forecasts ETS general univariate models
ETSmodel( y, u = NULL, model = "???", s = frequency(y), h = max(2 * s, 6), criterion = "aicc", lambda = 1, armaIdent = FALSE, identAll = FALSE, forIntervals = FALSE, bootstrap = FALSE, nSimul = 5000, verbose = FALSE, alphaL = c(1e-08, 1 - 1e-08), betaL = alphaL, gammaL = alphaL, phiL = c(0.8, 0.98), p0 = -99999 )
ETSmodel( y, u = NULL, model = "???", s = frequency(y), h = max(2 * s, 6), criterion = "aicc", lambda = 1, armaIdent = FALSE, identAll = FALSE, forIntervals = FALSE, bootstrap = FALSE, nSimul = 5000, verbose = FALSE, alphaL = c(1e-08, 1 - 1e-08), betaL = alphaL, gammaL = alphaL, phiL = c(0.8, 0.98), p0 = -99999 )
y |
a time series to forecast (it may be either a numerical vector or
a time series object). This is the only input required. If a vector, the additional
input |
u |
a matrix of input time series. If
the output wanted to be forecast, matrix |
model |
the model to estimate. It is a single string indicating the type of model for each component with one or two letters:
|
s |
seasonal period of time series (1 for annual, 4 for quarterly, ...) |
h |
forecast horizon. If the model includes inputs h is not used, the lenght of u is used instead. |
criterion |
information criterion for identification ("aic", "bic" or "aicc"). |
lambda |
Box-Cox lambda parameter (NULL: estimate) |
armaIdent |
check for arma models for error component (TRUE / FALSE). |
identAll |
run all models to identify the best one (TRUE / FALSE) |
forIntervals |
estimate forecasting intervals (TRUE / FALSE) |
bootstrap |
use bootstrap simulation for predictive distributions |
nSimul |
number of simulation runs for bootstrap simulation of predictive distributions |
verbose |
intermediate estimation output (TRUE / FALSE) |
alphaL |
constraints limits for alpha parameter |
betaL |
constraints limits for beta parameter |
gammaL |
constraints limits for gamma parameter |
phiL |
constraints limits for phi parameter |
p0 |
initial values for parameter search (alpha, beta, phi, gamma) with consraints:
|
ETSmodel
is a function for modelling and forecasting univariate
time series with ExponenTial Smoothing (ETS) time series models.
It sets up the model with a number of control variables that
govern the way the rest of functions in the package will work. It also estimates
the model parameters by Maximum Likelihood and forecasts the data.
An object of class ETS
. It is a list with fields including all the inputs and
the fields listed below as outputs. All the functions in this package fill in
part of the fields of any ETS
object as specified in what follows (function
ETS
fills in all of them at once):
After running ETSmodel
or ETSestim
:
p |
Estimated parameters |
criteria |
Values for estimation criteria (LogLik, AIC, BIC, AICc) |
yFor |
Forecasted values of output |
yForV |
Variance of forecasted values of output |
ySimul |
Bootstrap simulations for forecasting distribution evaluation |
After running ETSvalidate
:
table |
Estimation and validation table |
comp |
Estimated components in matrix form |
After running ETScomponents
:
comp |
Estimated components in matrix form |
Diego J. Pedregal
ETS
, ETSvalidate
,
ETScomponents
, ETSestim
## Not run: y <- log(AirPAssengers) m1 <- ETSmodel(y) m1 <- ETSmodel(y, model = "A?A") ## End(Not run)
## Not run: y <- log(AirPAssengers) m1 <- ETSmodel(y) m1 <- ETSmodel(y, model = "A?A") ## End(Not run)
Sets up ETS general univariate models
ETSsetup( y, u = NULL, model = "???", s = frequency(y), h = 2 * s, criterion = "aicc", lambda = 1, armaIdent = FALSE, identAll = FALSE, forIntervals = FALSE, bootstrap = FALSE, nSimul = 5000, verbose = FALSE, alphaL = c(1e-08, 1 - 1e-08), betaL = alphaL, gammaL = alphaL, phiL = c(0.8, 0.98), p0 = -99999 )
ETSsetup( y, u = NULL, model = "???", s = frequency(y), h = 2 * s, criterion = "aicc", lambda = 1, armaIdent = FALSE, identAll = FALSE, forIntervals = FALSE, bootstrap = FALSE, nSimul = 5000, verbose = FALSE, alphaL = c(1e-08, 1 - 1e-08), betaL = alphaL, gammaL = alphaL, phiL = c(0.8, 0.98), p0 = -99999 )
y |
a time series to forecast (it may be either a numerical vector or
a time series object). This is the only input required. If a vector, the additional
input |
u |
a matrix of input time series. If
the output wanted to be forecast, matrix |
model |
the model to estimate. It is a single string indicating the type of model for each component with one or two letters:
|
s |
seasonal period of time series (1 for annual, 4 for quarterly, ...) |
h |
forecast horizon. If the model includes inputs h is not used, the lenght of u is used instead. |
criterion |
information criterion for identification ("aic", "bic" or "aicc"). |
lambda |
Box-Cox lambda parameter (NULL: estimate) |
armaIdent |
check for arma models for error component (TRUE / FALSE). |
identAll |
run all models to identify the best one (TRUE / FALSE) |
forIntervals |
estimate forecasting intervals (TRUE / FALSE) |
bootstrap |
use bootstrap simulation for predictive distributions |
nSimul |
number of simulation runs for bootstrap simulation of predictive distributions |
verbose |
intermediate estimation output (TRUE / FALSE) |
alphaL |
constraints limits for alpha parameter |
betaL |
constraints limits for beta parameter |
gammaL |
constraints limits for gamma parameter |
phiL |
constraints limits for phi parameter |
p0 |
initial values for parameter search (alpha, beta, phi, gamma) with consraints:
|
See help of ETSmodel
.
An object of class ETS
. See ETSmodel
.
Diego J. Pedregal
ETS
, ETSmodel
, ETSvalidate
,
ETScomponents
, ETSestim
## Not run: y <- log(AirPAssengers) m1 <- ETSsetup(y) m1 <- ETSsetup(y, model = "???") m1 <- ETSsetup(y, model = "?AA") ## End(Not run)
## Not run: y <- log(AirPAssengers) m1 <- ETSsetup(y) m1 <- ETSsetup(y, model = "???") m1 <- ETSsetup(y, model = "?AA") ## End(Not run)
Shows a table of estimation and diagnostics results for ETS models
ETSvalidate(m)
ETSvalidate(m)
m |
an object of type |
The same input object with the appropriate fields filled in, in particular:
table |
Estimation and validation table |
Diego J. Pedregal
ETS
, ETSmodel
, ETSvalidate
,
ETScomponents
## Not run: m1 <- ETSmodel(log(gdp)) m1 <- ETSvalidate(m1) ## End(Not run)
## Not run: m1 <- ETSmodel(log(gdp)) m1 <- ETSvalidate(m1) ## End(Not run)
Reorder data frame returning column col reordered according to the values in column accordingTo
extract(x, col, accordingTo = 1)
extract(x, col, accordingTo = 1)
x |
a data frame |
col |
column to be ordered |
accordingTo |
column to take as the pattern |
data frame reordered
Diego J. Pedregal
Fitted output values of ETS object
Fitted output values of PTS object
Fitted output values of TETS object
## S3 method for class 'ETS' fitted(object, ...) ## S3 method for class 'PTS' fitted(object, ...) ## S3 method for class 'TETS' fitted(object, ...)
## S3 method for class 'ETS' fitted(object, ...) ## S3 method for class 'PTS' fitted(object, ...) ## S3 method for class 'TETS' fitted(object, ...)
object |
Object of class “TETS”. |
... |
Additional inputs to function. |
See help of ETS
.
See help of PTS
.
See help of TETS
.
Diego J. Pedregal
ETS
, ETSmodel
, ETSvalidate
,
ETScomponents
, ETSestim
PTS
, PTSmodel
, PTSvalidate
,
PTScomponents
, PTSestim
TETS
, TETSmodel
, TETSvalidate
,
TETScomponents
, TETSestim
## Not run: m1 <- ETSmodel(log(gdp)) fitted(m1) ## End(Not run) ## Not run: m1 <- PTSmodel(log(AirPassengers)) fitted(m1) ## End(Not run) ## Not run: m1 <- TETSmodel(log(gdp)) fitted(m1) ## End(Not run)
## Not run: m1 <- ETSmodel(log(gdp)) fitted(m1) ## End(Not run) ## Not run: m1 <- PTSmodel(log(AirPassengers)) fitted(m1) ## End(Not run) ## Not run: m1 <- TETSmodel(log(gdp)) fitted(m1) ## End(Not run)
Gaussianity tests
gaussTest(y, runFromTests = FALSE)
gaussTest(y, runFromTests = FALSE)
y |
a vector, ts or tsibble object |
runFromTests |
internal check |
Diego J. Pedregal
colMedians
, rowMedians
, tests
,
sumStats
, ident
,
cusum
, varTest
, conv
,
armaFilter
, dif
, roots
,
zplane
, acft
, slide
,
plotSlide
, Accuracy
, tsDisplay
,
size
gaussTest(AirPassengers)
gaussTest(AirPassengers)
Quarterly real Spanish Gross Domestic Product (gdp)
gdp
gdp
Time series objects.
Quarterly since 1995
https://portal.mineco.gob.es/es-es/economiayempresa/EconomiaInformesMacro/Paginas/bdsice.aspx
## Not run: gdp ## End(Not run)
## Not run: gdp ## End(Not run)
Get initial conditions for parameters of UComp
object
getp0(y, model = "llt/equal/arma(0,0)", periods = NA)
getp0(y, model = "llt/equal/arma(0,0)", periods = NA)
y |
a time series to forecast. |
model |
any valid |
periods |
vector of fundamental period and harmonics required. |
Provides initial parameters of a given model for the time series.
They may be changed arbitrarily by the user to include as an input p0
to
UC
or UCmodel
functions (see example below).
There is no guarantee that the model will converge and selecting initial conditions
should be used with care.
A set of parameters p0 of an object of class UComp
to use as input to UC
, UCmodel
or UCsetup
.
Diego J. Pedregal
UC
, UCvalidate
, UCfilter
, UCsmooth
,
UCdisturb
, UCcomponents
,
UChp
## Not run: p0 <- getp0(log(AirPassengers), model = "llt/equal/arma(0,0)") p0[1] <- 0 # p0[1] <- NA m <- UCmodel(log(AirPassengers), model = "llt/equal/arma(0,0)", p0 = p0) ## End(Not run)
## Not run: p0 <- getp0(log(AirPassengers), model = "llt/equal/arma(0,0)") p0[1] <- 0 # p0[1] <- NA m <- UCmodel(log(AirPassengers), model = "llt/equal/arma(0,0)", p0 = p0) ## End(Not run)
Autocorrelation functions of a time series
ident(y, nCoef = min(37, floor(length(y)/4)), nPar = 0, runFromTests = FALSE)
ident(y, nCoef = min(37, floor(length(y)/4)), nPar = 0, runFromTests = FALSE)
y |
a vector, ts or tsibble object |
nCoef |
number of autocorrelation coefficients to estimate |
nPar |
number of parameters in a model if y is a residual |
runFromTests |
internal check |
A vector with all the dimensions
Diego J. Pedregal
colMedians
, rowMedians
, tests
,
sumStats
, gaussTest
,
cusum
, varTest
, conv
,
armaFilter
, dif
, roots
,
zplane
, acft
, slide
,
plotSlide
, Accuracy
, tsDisplay
,
size
ident(AirPassengers)
ident(AirPassengers)
Runs inverse of Box-Cox transform of a time series
inv.box.cox(x, lambda)
inv.box.cox(x, lambda)
x |
Transformed time series object. |
lambda |
Lambda parameter used for Box-Cox transform. |
Diego J. Pedregal
box.cox
, UC
, UCmodel
, UCvalidate
, UCfilter
, UCsmooth
,
UCdisturb
, UCcomponents
## Not run: y <- inv.box.cox(box.cox(AirPassengers, 0.5), 0.5) plot(y) ## End(Not run)
## Not run: y <- inv.box.cox(box.cox(AirPassengers, 0.5), 0.5) plot(y) ## End(Not run)
Calculates inverse of Box-Cox transformation with confidence bands, calculated as const time the standard error
invBoxCox(y, yVar, lambda, const = 2)
invBoxCox(y, yVar, lambda, const = 2)
y |
matrix, array or vector |
yVar |
matrix, array or vector of variances of y |
lambda |
lambda parameter of Box-Cox transformation |
const |
number of standard error for confidence band |
Diego J. Pedregal
Spanish Industrial Production Index (ipi).
ipi
ipi
Objeto time series.
Monthly since 1975
https://portal.mineco.gob.es/es-es/economiayempresa/EconomiaInformesMacro/Paginas/bdsice.aspx
## Not run: ipi ## End(Not run)
## Not run: ipi ## End(Not run)
Extracts arma part of modelUC model
modelUC2arma(model)
modelUC2arma(model)
model |
a UC model |
arma orders
Diego J. Pedregal
Translates modelUC to model PTS
modelUC2PTS(modelUC)
modelUC2PTS(modelUC)
modelUC |
a UC model |
a PTS model
Diego J. Pedregal
Seasonally adjusted quarterly OECD real gross domestic product (OECDgdp).
OECDgdp
OECDgdp
Time series objects.
Quarterly data from 1962 to 2019
https://portal.mineco.gob.es/es-es/economiayempresa/EconomiaInformesMacro/Paginas/bdsice.aspx
## Not run: OECDgdp ## End(Not run)
## Not run: OECDgdp ## End(Not run)
Plot zplane of ARIMA object
## S3 method for class 'ARIMA' plot(x, ...)
## S3 method for class 'ARIMA' plot(x, ...)
x |
Object of class “ARIMA”. |
... |
Additional inputs to function. |
See help of ARIMA
.
Diego J. Pedregal
ARIMA
, ARIMAmodel
, ARIMAvalidate
,
## Not run: m1 <- ARIMAmodel(log(gdp)) plot(m1) ## End(Not run)
## Not run: m1 <- ARIMAmodel(log(gdp)) plot(m1) ## End(Not run)
Plot components of ETS object
Plot components of PTS object
Plot components of TETS object
## S3 method for class 'ETS' plot(x, ...) ## S3 method for class 'PTS' plot(x, ...) ## S3 method for class 'TETS' plot(x, ...)
## S3 method for class 'ETS' plot(x, ...) ## S3 method for class 'PTS' plot(x, ...) ## S3 method for class 'TETS' plot(x, ...)
x |
Object of class “TETS”. |
... |
Additional inputs to function. |
See help of ETS
.
See help of PTS
.
See help of TETS
.
Diego J. Pedregal
ETS
, ETSmodel
, ETSvalidate
,
ETScomponents
, ETSestim
PTS
, PTSmodel
, PTSvalidate
,
PTScomponents
, PTSestim
TETS
, TETSmodel
, TETSvalidate
,
TETScomponents
, TETSestim
## Not run: m1 <- ETSmodel(log(gdp)) plot(m1) ## End(Not run) ## Not run: m1 <- PTS(log(AirPassengers)) plot(m1) ## End(Not run) ## Not run: m1 <- TETSmodel(log(gdp)) plot(m1) ## End(Not run)
## Not run: m1 <- ETSmodel(log(gdp)) plot(m1) ## End(Not run) ## Not run: m1 <- PTS(log(AirPassengers)) plot(m1) ## End(Not run) ## Not run: m1 <- TETSmodel(log(gdp)) plot(m1) ## End(Not run)
Plot of ACF and PACF
plotAcfPacf(ACF, PACF, s = 1, n = NA, runFromTest = FALSE)
plotAcfPacf(ACF, PACF, s = 1, n = NA, runFromTest = FALSE)
ACF |
variable to plot |
PACF |
second variable to plot |
s |
seasonal period |
n |
number of coefficients |
runFromTest |
internal check variable |
Diego J. Pedregal
Plot variable in bars
plotBar(ACF, s = 1, n = NA, label = "ACF")
plotBar(ACF, s = 1, n = NA, label = "ACF")
ACF |
variable to plot |
s |
seasonal period |
n |
number of coefficients |
label |
label for plot |
Handle of plot
Diego J. Pedregal
Plot summarised results from slide
plotSlide(py1, y, orig, step = 1, errorFun, collectFun = mean)
plotSlide(py1, y, orig, step = 1, errorFun, collectFun = mean)
py1 |
output from slide function |
y |
a vector or matrix of time series (the same used in slide call) |
orig |
starting forecasting origin (the same used in slide call) |
step |
observations ahead to move the forecasting origin (the same used in slide call) |
errorFun |
user function to calculate error measures |
collectFun |
aggregation function (mean, median, etc.) |
Results
Diego J. Pedregal
colMedians
, rowMedians
, tests
,
sumStats
, gaussTest
, ident
,
cusum
, varTest
, conv
,
armaFilter
, dif
, roots
,
zplane
, acft
, slide
,
Accuracy
, tsDisplay
,
size
## Not run: plotSlide(py1, AirPassengers, 100, 1, errorFun)
## Not run: plotSlide(py1, AirPassengers, 100, 1, errorFun)
Returns date of next to end time series y
plus_one(y)
plus_one(y)
y |
a ts object |
Next time stamp
Diego J. Pedregal
Forecasting using structural Unobseved Components models with prediction intervals
## S3 method for class 'UComp' predict(object, newdata = NULL, n.ahead = NULL, level = 0.95, ...)
## S3 method for class 'UComp' predict(object, newdata = NULL, n.ahead = NULL, level = 0.95, ...)
object |
Object of class “UComp”. |
newdata |
New output data to apply “UComp” object to. |
n.ahead |
Number of steps ahead to forecast or new inputs variables including their predictions. |
level |
Confidence level for prediction intervals. |
... |
Ignored. |
See help of UC
.
A matrix with the mean forecasts and lower and upper prediction intervals
Diego J. Pedregal
UC
, UCmodel
, UCvalidate
, UCfilter
, UCsmooth
,
UCdisturb
, UCcomponents
## Not run: y <- log(AirPassengers) m1 <- UCmodel(y, model = "llt/eq/arma(0,0)") f1 <- predict(m1) ## End(Not run)
## Not run: y <- log(AirPassengers) m1 <- UCmodel(y, model = "llt/eq/arma(0,0)") f1 <- predict(m1) ## End(Not run)
Prints an ARIMA object
Prints an ETS object
Prints a PTS object
Prints a TOBIT TETS object
## S3 method for class 'ARIMA' print(x, ...) ## S3 method for class 'ETS' print(x, ...) ## S3 method for class 'PTS' print(x, ...) ## S3 method for class 'TETS' print(x, ...)
## S3 method for class 'ARIMA' print(x, ...) ## S3 method for class 'ETS' print(x, ...) ## S3 method for class 'PTS' print(x, ...) ## S3 method for class 'TETS' print(x, ...)
x |
Object of class “TETS”. |
... |
Additional inputs to handle the way to print output. |
See help of ARIMA
.
See help of ETS
.
See help of PTS
.
See help of TETS
.
Diego J. Pedregal
ARIMA
, ARIMAmodel
, ARIMAvalidate
,
ETS
, ETSmodel
, ETSvalidate
,
ETScomponents
, ETSestim
PTS
, PTSmodel
, PTSvalidate
,
PTScomponents
, PTSestim
TETS
, TETSmodel
, TETSvalidate
,
TETScomponents
, TETSestim
## Not run: m1 <- ARIMAmodel(log(gdp)) print(m1) ## End(Not run) ## Not run: m1 <- ETSmodel(log(gdp)) print(m1) ## End(Not run) ## Not run: m1 <- PTSmodel(log(AirPassengers)) print(m1) ## End(Not run) ## Not run: m1 <- TETSmodel(log(gdp)) print(m1) ## End(Not run)
## Not run: m1 <- ARIMAmodel(log(gdp)) print(m1) ## End(Not run) ## Not run: m1 <- ETSmodel(log(gdp)) print(m1) ## End(Not run) ## Not run: m1 <- PTSmodel(log(AirPassengers)) print(m1) ## End(Not run) ## Not run: m1 <- TETSmodel(log(gdp)) print(m1) ## End(Not run)
Estimates, forecasts and smooth PTS general univariate models
PTS( y, u = NULL, model = "???", s = frequency(y), h = 2 * s, criterion = "aicc", lambda = 1, armaIdent = FALSE, verbose = FALSE )
PTS( y, u = NULL, model = "???", s = frequency(y), h = 2 * s, criterion = "aicc", lambda = 1, armaIdent = FALSE, verbose = FALSE )
y |
a time series to forecast (it may be either a numerical vector or
a time series object). This is the only input required. If a vector, the additional
input |
u |
a matrix of input time series. If
the output wanted to be forecast, matrix |
model |
the model to estimate. It is a single string indicating the type of model for each component with one or two letters:
|
s |
seasonal period of time series (1 for annual, 4 for quarterly, ...) |
h |
forecast horizon. If the model includes inputs h is not used, the lenght of u is used instead. |
criterion |
information criterion for identification ("aic", "bic" or "aicc"). |
lambda |
Box-Cox lambda parameter (NULL: estimate) |
armaIdent |
check for arma models for error component (TRUE / FALSE). |
verbose |
intermediate estimation output (TRUE / FALSE) |
PTS
is a function for modelling and forecasting univariate
time series according to Power-Trend-Seasonal (PTS).
It sets up the model with a number of control variables that
govern the way the rest of functions in the package work. It also estimates
the model parameters by Maximum Likelihood and forecasts the data.
Standard methods applicable to UComp objects are print, summary, plot,
fitted, residuals, logLik, AIC, BIC, coef, predict, tsdiag.
An object of class PTS
. It is a list with fields including all the inputs and
the fields listed below as outputs. All the functions in this package fill in
part of the fields of any PTS
object as specified in what follows (function
PTS
fills in all of them at once):
After running PTSmodel
or PTSestim
:
p0: Initial values for parameter search
p: Estimated parameters
lambda: Estimated Box-Cox lambda parameter
v: Estimated innovations (white noise in correctly specified models)
yFor: Forecasted values of output
yForV: Variance of forecasted values of output
After running PTSvalidate
:
table: Estimation and validation table
After running PTScomponents
:
comp: Estimated components in matrix form
Diego J. Pedregal
PTSmodel
, PTSsetup
, PTSvalidate
,
PTScomponents
, PTSestim
## Not run: m1 <- PTS(log(AirPassengers)) ## End(Not run)
## Not run: m1 <- PTS(log(AirPassengers)) ## End(Not run)
Translates PTS model to UC model
PTS2modelUC(model, armaOrders = c(0, 0))
PTS2modelUC(model, armaOrders = c(0, 0))
model |
a PTS model |
armaOrders |
arma orders of noise model |
a UC model
Diego J. Pedregal
Estimates components of PTS models
PTScomponents(m)
PTScomponents(m)
m |
an object of type |
The same input object with the appropriate fields filled in, in particular:
comp: Estimated components in matrix form
Diego J. Pedregal
PTSmodel
, PTSsetup
, PTSestim
,
PTSvalidate
, PTS
## Not run: m1 <- PTS(log(AirPassengers)) m1 <- PTScomponents(m1) ## End(Not run)
## Not run: m1 <- PTS(log(AirPassengers)) m1 <- PTScomponents(m1) ## End(Not run)
Estimates and forecasts PTS models
PTSestim(m)
PTSestim(m)
m |
an object of type |
PTSestim
estimates and forecasts a time series using an
a PTS model
The same input object with the appropriate fields filled in, in particular:
p0: Initial values for parameter search
p: Estimated parameters
lambda: Estimated Box-Cox lambda parameter
v: Estimated innovations (white noise in correctly specified models)
yFor: Forecasted values of output
yForV: Variance of forecasted values of output
Diego J. Pedregal
PTSmodel
, PTSsetup
, PTSvalidate
,
PTScomponents
, PTS
## Not run: m1 <- PTSsetup(log(AirPassengers)) m1 <- PTSestim(m1) ## End(Not run)
## Not run: m1 <- PTSsetup(log(AirPassengers)) m1 <- PTSestim(m1) ## End(Not run)
Estimates and forecasts PTS general univariate models
PTSmodel( y, u = NULL, model = "???", s = frequency(y), h = 2 * s, criterion = "aicc", lambda = 1, armaIdent = FALSE, verbose = FALSE )
PTSmodel( y, u = NULL, model = "???", s = frequency(y), h = 2 * s, criterion = "aicc", lambda = 1, armaIdent = FALSE, verbose = FALSE )
y |
a time series to forecast (it may be either a numerical vector or
a time series object). This is the only input required. If a vector, the additional
input |
u |
a matrix of input time series. If
the output wanted to be forecast, matrix |
model |
the model to estimate. It is a single string indicating the type of model for each component with one or two letters:
|
s |
seasonal period of time series (1 for annual, 4 for quarterly, ...) |
h |
forecast horizon. If the model includes inputs h is not used, the lenght of u is used instead. |
criterion |
information criterion for identification ("aic", "bic" or "aicc"). |
lambda |
Box-Cox lambda parameter (NULL: estimate) |
armaIdent |
check for arma models for error component (TRUE / FALSE). |
verbose |
intermediate estimation output (TRUE / FALSE) |
PTSmodel
is a function for modelling and forecasting univariate
time series according to Power-Trend-Seasonal (PTS).
It sets up the model with a number of control variables that
govern the way the rest of functions in the package work. It also estimates
the model parameters by Maximum Likelihood and forecasts the data.
Standard methods applicable to UComp objects are print, summary, plot,
fitted, residuals, logLik, AIC, BIC, coef, predict, tsdiag.
An object of class PTS
. It is a list with fields including all the inputs and
the fields listed below as outputs. All the functions in this package fill in
part of the fields of any PTS
object as specified in what follows (function
PTS
fills in all of them at once):
After running PTSmodel
or PTSestim
:
p0: Initial values for parameter search
p: Estimated parameters
lambda: Estimated Box-Cox lambda parameter
v: Estimated innovations (white noise in correctly specified models)
yFor: Forecasted values of output
yForV: Variance of forecasted values of output
After running PTSvalidate
:
table: Estimation and validation table
After running PTScomponents
:
comp: Estimated components in matrix form
Diego J. Pedregal
PTS
, PTSsetup
, PTSvalidate
,
PTScomponents
, PTSestim
## Not run: m1 <- PTSmodel(log(AirPassengers)) ## End(Not run)
## Not run: m1 <- PTSmodel(log(AirPassengers)) ## End(Not run)
Run up PTS general univariate MSOE models
PTSsetup( y, u = NULL, model = "???", s = frequency(y), h = 2 * s, criterion = "aic", lambda = 1, armaIdent = FALSE, verbose = FALSE )
PTSsetup( y, u = NULL, model = "???", s = frequency(y), h = 2 * s, criterion = "aic", lambda = 1, armaIdent = FALSE, verbose = FALSE )
y |
a time series to forecast (it may be either a numerical vector or
a time series object). This is the only input required. If a vector, the additional
input |
u |
a matrix of input time series. If
the output wanted to be forecast, matrix |
model |
the model to estimate. It is a single string indicating the type of model for each component with one or two letters:
|
s |
seasonal period of time series (1 for annual, 4 for quarterly, ...) |
h |
forecast horizon. If the model includes inputs h is not used, the lenght of u is used instead. |
criterion |
information criterion for identification ("aic", "bic" or "aicc"). |
lambda |
Box-Cox lambda parameter (NULL: estimate) |
armaIdent |
check for arma models for error component (TRUE / FALSE). |
verbose |
intermediate estimation output (TRUE / FALSE) |
See help of PTS
.
An object of class PTS
. It is a list with fields including all the inputs and
the fields listed below as outputs. All the functions in this package fill in
part of the fields of any PTS
object as specified in what follows (function
PTS
fills in all of them at once):
After running PTSmodel
or PTSestim
:
p0: Initial values for parameter search
p: Estimated parameters
lambda: Estimated Box-Cox lambda parameter
v: Estimated innovations (white noise in correctly specified models)
yFor: Forecasted values of output
yForV: Variance of forecasted values of output
After running PTSvalidate
:
table: Estimation and validation table
After running PTScomponents
:
comp: Estimated components in matrix form
Standard methods applicable to PTS objects are print, summary, plot, fitted, residuals, logLik, AIC, BIC, coef, predict, tsdiag.
Diego J. Pedregal
PTS
, PTSmodel
, PTSvalidate
,
PTScomponents
, PTSestim
## Not run: m1 <- PTSsetup(log(AirPassengers)) ## End(Not run)
## Not run: m1 <- PTSsetup(log(AirPassengers)) ## End(Not run)
Shows a table of estimation and diagnostics results for PTS models
PTSvalidate(m, verbose = TRUE)
PTSvalidate(m, verbose = TRUE)
m |
an object of type |
verbose |
verbose mode TRUE/FALSE |
The same input object with the appropriate fields filled in, in particular:
table: Estimation and validation table
Diego J. Pedregal
PTSmodel
, PTSsetup
, PTSestim
,
PTScomponents
, PTS
## Not run: m1 <- PTSmodel(log(AirPassengers)) m1 <- PTSvalidate(m1) ## End(Not run)
## Not run: m1 <- PTSmodel(log(AirPassengers)) m1 <- PTSvalidate(m1) ## End(Not run)
Remove nans at beginning or end of vector
removeNaNs(x)
removeNaNs(x)
x |
a vector or a ts object |
vector with nans removed (only those at beginning or end)
Diego J. Pedregal
Residuals of ETS object
Residuals of PTS object
Residuals of TETS object
## S3 method for class 'ETS' residuals(object, ...) ## S3 method for class 'PTS' residuals(object, ...) ## S3 method for class 'TETS' residuals(object, ...)
## S3 method for class 'ETS' residuals(object, ...) ## S3 method for class 'PTS' residuals(object, ...) ## S3 method for class 'TETS' residuals(object, ...)
object |
Object of class “TETS”. |
... |
Additional inputs to function. |
See help of ETS
.
See help of PTS
.
See help of TETS
.
Diego J. Pedregal
ETS
, ETSmodel
, ETSvalidate
,
ETScomponents
, ETSestim
PTS
, PTSmodel
, PTSvalidate
,
PTScomponents
, PTSestim
TETS
, TETSmodel
, TETSvalidate
,
TETScomponents
, TETSestim
## Not run: m1 <- ETSmodel(log(gdp)) residuals(m1) ## End(Not run) ## Not run: m1 <- PTSmodel(log(AirPassengers)) residuals(m1) ## End(Not run) ## Not run: m1 <- TETSmodel(log(gdp)) residuals(m1) ## End(Not run)
## Not run: m1 <- ETSmodel(log(gdp)) residuals(m1) ## End(Not run) ## Not run: m1 <- PTSmodel(log(AirPassengers)) residuals(m1) ## End(Not run) ## Not run: m1 <- TETSmodel(log(gdp)) residuals(m1) ## End(Not run)
Roots of polynomial
roots(x)
roots(x)
x |
coefficients of polynomial in descending order |
Roots of polynomial
Diego J. Pedregal
colMedians
, rowMedians
, tests
,
sumStats
, gaussTest
, ident
,
cusum
, varTest
, conv
,
armaFilter
, dif
,
zplane
, acft
, slide
,
plotSlide
, Accuracy
, tsDisplay
,
size
roots(c(1, -2 ,1)) roots(conv(c(1, -1), c(1, 0.8)))
roots(c(1, -2 ,1)) roots(conv(c(1, -1), c(1, 0.8)))
Medians of matrix by rows
rowMedians(x, na.rm = TRUE, ...)
rowMedians(x, na.rm = TRUE, ...)
x |
a matrix |
na.rm |
boolean indicating whether to remove nans |
... |
rest of inputs |
A vector with all the medians
Diego J. Pedregal
colMedians
, tests
,
sumStats
, gaussTest
, ident
,
cusum
, varTest
, conv
,
armaFilter
, dif
, roots
,
zplane
, acft
, slide
,
plotSlide
, Accuracy
, tsDisplay
,
size
s <- rowMedians(matrix(4, 3, 2))
s <- rowMedians(matrix(4, 3, 2))
Sales index for food of large retailers in Spain
sales
sales
Time series objects.
Monthly data from January 1995 to December 2019
https://portal.mineco.gob.es/es-es/economiayempresa/EconomiaInformesMacro/Paginas/bdsice.aspx
## Not run: sales ## End(Not run)
## Not run: sales ## End(Not run)
size of vectors or matrices
Size of vector, matrix or array
size(y) size(y)
size(y) size(y)
y |
a vector, matrix or array |
A vector with all the dimensions
Diego J. Pedregal
colMedians
, rowMedians
, tests
,
sumStats
, gaussTest
, ident
,
cusum
, varTest
, conv
,
armaFilter
, dif
, roots
,
zplane
, acft
, slide
,
plotSlide
, Accuracy
, tsDisplay
s <- size(matrix(4, 3, 2)) s <- size(rep(4, 3)) s <- size(array(4, c(3, 2, 2)))
s <- size(matrix(4, 3, 2)) s <- size(rep(4, 3)) s <- size(array(4, c(3, 2, 2)))
Rolling forecasting of a matrix of time series
slide( y, orig, forecFun, ..., h = 12, step = 1, output = TRUE, window = NA, parallel = FALSE )
slide( y, orig, forecFun, ..., h = 12, step = 1, output = TRUE, window = NA, parallel = FALSE )
y |
a vector or matrix of time series |
orig |
starting forecasting origin |
forecFun |
user function that implements forecasting methods |
... |
rest of inputs to forecFun function |
h |
forecasting horizon |
step |
observations ahead to move the forecasting origin |
output |
output TRUE/FALSE |
window |
fixed window width in number of observations (NA for non fixed) |
parallel |
run forecasts in parallel |
Takes a time series and run forecasting methods implemented in function forecFun h steps ahead along the time series y, starting at forecasting origin orig, and moving step observations ahead. Forecasts may be run in parallel by setting parallel to TRUE. A fixed window width may be specified with input window. The output is of dimensions (h, nOrigs, nModels, nSeries)
A vector with all the dimensions
Diego J. Pedregal
colMedians
, rowMedians
, tests
,
sumStats
, gaussTest
, ident
,
cusum
, varTest
, conv
,
armaFilter
, dif
, roots
,
zplane
, acft
,
plotSlide
, Accuracy
, tsDisplay
,
size
## Not run: slide(AirPassengers, 100, forecFun)
## Not run: slide(AirPassengers, 100, forecFun)
Auxiliary function run from slide
slideAux( y, orig, forecFun, h = 12, step = 1, output = TRUE, graph = TRUE, window = NA, parallel = FALSE, ... )
slideAux( y, orig, forecFun, h = 12, step = 1, output = TRUE, graph = TRUE, window = NA, parallel = FALSE, ... )
y |
a vector or matrix of time series |
orig |
starting forecasting origin |
forecFun |
user function that implements forecasting methods |
h |
forecasting horizon |
step |
observations ahead to move the forecasting origin |
output |
output TRUE/FALSE |
graph |
fraphical output TRUE/FALSE |
window |
fixed window width in number of observations (NA for non fixed) |
parallel |
run forecasts in parallel |
... |
rest of inputs to forecFun function |
Next time stamp
Diego J. Pedregal
Prints an ARIMA object on screen
## S3 method for class 'ARIMA' summary(object, ...)
## S3 method for class 'ARIMA' summary(object, ...)
object |
Object of class “ARIMA”. |
... |
Additional inputs to function. |
See help of ARIMA
.
Diego J. Pedregal
ARIMA
, ARIMAmodel
, ARIMAvalidate
,
## Not run: m1 <- ARIMAmodel(log(gdp)) summary(m1) ## End(Not run)
## Not run: m1 <- ARIMAmodel(log(gdp)) summary(m1) ## End(Not run)
Prints an ETS object on screen
## S3 method for class 'ETS' summary(object, ...)
## S3 method for class 'ETS' summary(object, ...)
object |
Object of class “ETS”. |
... |
Additional inputs to function. |
See help of ETS
.
Diego J. Pedregal
ETS
, ETSmodel
, ETSvalidate
,
ETScomponents
, ETSestim
## Not run: m1 <- ETSmodel(log(gdp)) summary(m1) ## End(Not run)
## Not run: m1 <- ETSmodel(log(gdp)) summary(m1) ## End(Not run)
Prints an PTS object on screen
## S3 method for class 'PTS' summary(object, ...)
## S3 method for class 'PTS' summary(object, ...)
object |
Object of class “PTS”. |
... |
Additional inputs to function. |
See help of PTS
.
Diego J. Pedregal
PTS
, PTSmodel
, PTSvalidate
,
PTScomponents
, PTSestim
## Not run: m1 <- PTSmodel(log(AirPassengers)) summary(m1) ## End(Not run)
## Not run: m1 <- PTSmodel(log(AirPassengers)) summary(m1) ## End(Not run)
Prints a TOBIT TETS object on screen
## S3 method for class 'TETS' summary(object, ...)
## S3 method for class 'TETS' summary(object, ...)
object |
Object of class “TETS”. |
... |
Additional inputs to function. |
See help of TETS
.
Diego J. Pedregal
TETS
, TETSmodel
, TETSvalidate
,
TETScomponents
, TETSestim
## Not run: m1 <- TETSmodel(log(gdp)) summary(m1) ## End(Not run)
## Not run: m1 <- TETSmodel(log(gdp)) summary(m1) ## End(Not run)
Summary statistics of a matrix of variables
sumStats(y, decimals = 5)
sumStats(y, decimals = 5)
y |
a vector, matrix of time series |
decimals |
number of decimals for table |
Position, dispersion, skewness, kurtosis, etc.
Table of values
Diego J. Pedregal
colMedians
, rowMedians
, tests
,
gaussTest
, ident
,
cusum
, varTest
, conv
,
armaFilter
, dif
, roots
,
zplane
, acft
, slide
,
plotSlide
, Accuracy
, tsDisplay
,
size
s <- sumStats(AirPassengers)
s <- sumStats(AirPassengers)
Tests on a time series
tests( y, parts = 1/3, nCoef = min(25, length(x)/4), nPar = 0, s = frequency(y), avoid = 16 )
tests( y, parts = 1/3, nCoef = min(25, length(x)/4), nPar = 0, s = frequency(y), avoid = 16 )
y |
a vector, ts or tsibble object |
parts |
proportion of sample to include in ratio of variances test |
nCoef |
number of autocorrelation coefficients to estimate |
nPar |
number of parameters in a model if y is a residual |
s |
seasonal period, number of observations per year |
avoid |
number of observations to avoid at beginning of sample to eliminate initial effects |
Multiple tests on a time series, including summary statistics, autocorrelation, Gaussianity and heteroskedasticity,
Diego J. Pedregal
colMedians
, rowMedians
,
sumStats
, gaussTest
, ident
,
cusum
, varTest
, conv
,
armaFilter
, dif
, roots
,
zplane
, acft
, slide
,
plotSlide
, Accuracy
, tsDisplay
,
size
tests(AirPassengers)
tests(AirPassengers)
Runs all relevant functions for TETS modelling
TETS( y, u = NULL, model = "???", s = frequency(y), h = 2 * s, criterion = "aicc", forIntervals = FALSE, bootstrap = FALSE, nSimul = 5000, verbose = FALSE, alphaL = c(0, 1), betaL = alphaL, gammaL = alphaL, phiL = c(0.8, 0.98), p0 = -99999, Ymin = -Inf, Ymax = Inf )
TETS( y, u = NULL, model = "???", s = frequency(y), h = 2 * s, criterion = "aicc", forIntervals = FALSE, bootstrap = FALSE, nSimul = 5000, verbose = FALSE, alphaL = c(0, 1), betaL = alphaL, gammaL = alphaL, phiL = c(0.8, 0.98), p0 = -99999, Ymin = -Inf, Ymax = Inf )
y |
a time series to forecast (it may be either a numerical vector or
a time series object). This is the only input required. If a vector, the additional
input |
u |
a matrix of input time series. If
the output wanted to be forecast, matrix |
model |
the model to estimate. It is a single string indicating the type of model for each component with one or two letters:
|
s |
seasonal period of time series (1 for annual, 4 for quarterly, ...) |
h |
forecast horizon. If the model includes inputs h is not used, the lenght of u is used instead. |
criterion |
information criterion for identification ("aic", "bic" or "aicc"). |
forIntervals |
estimate forecasting intervals (TRUE / FALSE) |
bootstrap |
use bootstrap simulation for predictive distributions |
nSimul |
number of simulation runs for bootstrap simulation of predictive distributions |
verbose |
intermediate estimation output (TRUE / FALSE) |
alphaL |
constraints limits for alpha parameter |
betaL |
constraints limits for beta parameter |
gammaL |
constraints limits for gamma parameter |
phiL |
constraints limits for phi parameter |
p0 |
initial values for parameter search (alpha, beta, phi, gamma, sigma2) with consraints: |
Ymin |
scalar or vector of time varying censoring values from below |
Ymax |
scalar or vector of time varying censoring values from above
|
See help of TETSmodel
.
An object of class TETS
. See TETSmodel
.
Diego J. Pedregal
TETSmodel
, TETSvalidate
,
TETScomponents
, TETSestim
## Not run: y <- log(AirPAssengers) m1 <- TETS(y) m1 <- TETS(y, model = "MAM") ## End(Not run)
## Not run: y <- log(AirPAssengers) m1 <- TETS(y) m1 <- TETS(y, model = "MAM") ## End(Not run)
Estimates components of TOBIT TETS models
TETScomponents(m)
TETScomponents(m)
m |
an object of type |
The same input object with the appropriate fields filled in, in particular:
comp |
Estimated components in matrix form |
Diego J. Pedregal
TETS
, TETSmodel
, TETSvalidate
,
TETSestim
## Not run: m1 <- TETS(log(gdp)) m1 <- TETScomponents(m1) ## End(Not run)
## Not run: m1 <- TETS(log(gdp)) m1 <- TETScomponents(m1) ## End(Not run)
Estimates and forecasts TOBIT TETS models
TETSestim(m)
TETSestim(m)
m |
an object of type |
TETSestim
estimates and forecasts a time series using an
a TOBIT TETS model
The same input object with the appropriate fields filled in, in particular:
p |
Estimated parameters |
yFor |
Forecasted values of output |
yForV |
Variance of forecasted values of output |
ySimul |
Bootstrap simulations for forecasting distribution evaluation |
Diego J. Pedregal
TETS
, TETSmodel
, TETSvalidate
,
TETScomponents
## Not run: m1 <- TETSsetup(log(gdp)) m1 <- TETSestim(m1) ## End(Not run)
## Not run: m1 <- TETSsetup(log(gdp)) m1 <- TETSestim(m1) ## End(Not run)
Estimates and forecasts TOBIT TETS general univariate models
TETSmodel( y, u = NULL, model = "???", s = frequency(y), h = max(2 * s, 6), criterion = "aicc", forIntervals = FALSE, bootstrap = FALSE, nSimul = 5000, verbose = FALSE, alphaL = c(0, 1), betaL = alphaL, gammaL = alphaL, phiL = c(0.8, 0.98), p0 = -99999, Ymin = -Inf, Ymax = Inf )
TETSmodel( y, u = NULL, model = "???", s = frequency(y), h = max(2 * s, 6), criterion = "aicc", forIntervals = FALSE, bootstrap = FALSE, nSimul = 5000, verbose = FALSE, alphaL = c(0, 1), betaL = alphaL, gammaL = alphaL, phiL = c(0.8, 0.98), p0 = -99999, Ymin = -Inf, Ymax = Inf )
y |
a time series to forecast (it may be either a numerical vector or
a time series object). This is the only input required. If a vector, the additional
input |
u |
a matrix of input time series. If
the output wanted to be forecast, matrix |
model |
the model to estimate. It is a single string indicating the type of model for each component with one or two letters:
|
s |
seasonal period of time series (1 for annual, 4 for quarterly, ...) |
h |
forecast horizon. If the model includes inputs h is not used, the lenght of u is used instead. |
criterion |
information criterion for identification ("aic", "bic" or "aicc"). |
forIntervals |
estimate forecasting intervals (TRUE / FALSE) |
bootstrap |
use bootstrap simulation for predictive distributions |
nSimul |
number of simulation runs for bootstrap simulation of predictive distributions |
verbose |
intermediate estimation output (TRUE / FALSE) |
alphaL |
constraints limits for alpha parameter |
betaL |
constraints limits for beta parameter |
gammaL |
constraints limits for gamma parameter |
phiL |
constraints limits for phi parameter |
p0 |
initial values for parameter search (alpha, beta, phi, gamma, sigma2) with consraints: |
Ymin |
scalar or vector of time varying censoring values from below |
Ymax |
scalar or vector of time varying censoring values from above
|
TETSmodel
is a function for modelling and forecasting univariate
time series with TOBIT ExponenTial Smoothing (TETS) time series models.
It sets up the model with a number of control variables that
govern the way the rest of functions in the package will work. It also estimates
the model parameters by Maximum Likelihood and forecasts the data.
An object of class TETS
. It is a list with fields including all the inputs and
the fields listed below as outputs. All the functions in this package fill in
part of the fields of any TETS
object as specified in what follows (function
TETS
fills in all of them at once):
After running TETSmodel
or TETSestim
:
p |
Estimated parameters |
criteria |
Values for estimation criteria (LogLik, AIC, BIC, AICc) |
yFor |
Forecasted values of output |
yForV |
Variance of forecasted values of output |
ySimul |
Bootstrap simulations for forecasting distribution evaluation |
After running TETSvalidate
:
table |
Estimation and validation table |
comp |
Estimated components in matrix form |
After running TETScomponents
:
comp |
Estimated components in matrix form |
Diego J. Pedregal
TETS
, TETSvalidate
,
TETScomponents
, TETSestim
## Not run: y <- log(AirPAssengers) m1 <- TETSmodel(y) m1 <- TETSmodel(y, model = "A?A") ## End(Not run)
## Not run: y <- log(AirPAssengers) m1 <- TETSmodel(y) m1 <- TETSmodel(y, model = "A?A") ## End(Not run)
Sets up TOBIT TETS general univariate models
TETSsetup( y, u = NULL, model = "???", s = frequency(y), h = 2 * s, criterion = "aicc", forIntervals = FALSE, bootstrap = FALSE, nSimul = 5000, verbose = FALSE, alphaL = c(0, 1), betaL = alphaL, gammaL = alphaL, phiL = c(0.8, 0.98), p0 = -99999, Ymin = -Inf, Ymax = Inf )
TETSsetup( y, u = NULL, model = "???", s = frequency(y), h = 2 * s, criterion = "aicc", forIntervals = FALSE, bootstrap = FALSE, nSimul = 5000, verbose = FALSE, alphaL = c(0, 1), betaL = alphaL, gammaL = alphaL, phiL = c(0.8, 0.98), p0 = -99999, Ymin = -Inf, Ymax = Inf )
y |
a time series to forecast (it may be either a numerical vector or
a time series object). This is the only input required. If a vector, the additional
input |
u |
a matrix of input time series. If
the output wanted to be forecast, matrix |
model |
the model to estimate. It is a single string indicating the type of model for each component with one or two letters:
|
s |
seasonal period of time series (1 for annual, 4 for quarterly, ...) |
h |
forecast horizon. If the model includes inputs h is not used, the lenght of u is used instead. |
criterion |
information criterion for identification ("aic", "bic" or "aicc"). |
forIntervals |
estimate forecasting intervals (TRUE / FALSE) |
bootstrap |
use bootstrap simulation for predictive distributions |
nSimul |
number of simulation runs for bootstrap simulation of predictive distributions |
verbose |
intermediate estimation output (TRUE / FALSE) |
alphaL |
constraints limits for alpha parameter |
betaL |
constraints limits for beta parameter |
gammaL |
constraints limits for gamma parameter |
phiL |
constraints limits for phi parameter |
p0 |
initial values for parameter search (alpha, beta, phi, gamma, sigma2) with consraints: |
Ymin |
scalar or vector of time varying censoring values from below |
Ymax |
scalar or vector of time varying censoring values from above
|
See help of TETSmodel
.
An object of class TETS
. See TETSmodel
.
Diego J. Pedregal
TETS
, TETSmodel
, TETSvalidate
,
TETScomponents
, TETSestim
## Not run: y <- log(AirPAssengers) m1 <- TETSsetup(y) m1 <- TETSsetup(y, model = "???") m1 <- TETSsetup(y, model = "?AA") ## End(Not run)
## Not run: y <- log(AirPAssengers) m1 <- TETSsetup(y) m1 <- TETSsetup(y, model = "???") m1 <- TETSsetup(y, model = "?AA") ## End(Not run)
Shows a table of estimation and diagnostics results for TOBIT TETS models
TETSvalidate(m)
TETSvalidate(m)
m |
an object of type |
The same input object with the appropriate fields filled in, in particular:
table |
Estimation and validation table |
Diego J. Pedregal
TETS
, TETSmodel
, TETSvalidate
,
TETScomponents
## Not run: m1 <- TETSmodel(log(gdp)) m1 <- TETSvalidate(m1) ## End(Not run)
## Not run: m1 <- TETSmodel(log(gdp)) m1 <- TETSvalidate(m1) ## End(Not run)
Displays time series plot with autocorrelation functions
tsDisplay(y, nCoef = 25, nPar = 0, s = NA)
tsDisplay(y, nCoef = 25, nPar = 0, s = NA)
y |
a vector, ts or tsibble object |
nCoef |
number of autocorrelation coefficients to estimate |
nPar |
number of parameters in a model if y is a residual |
s |
seasonal period, number of observations per year |
Diego J. Pedregal
colMedians
, rowMedians
, tests
,
sumStats
, gaussTest
, ident
,
cusum
, varTest
, conv
,
armaFilter
, dif
, roots
,
zplane
, acft
, slide
,
plotSlide
, Accuracy
,
size
tsDisplay(AirPassengers)
tsDisplay(AirPassengers)
Runs all relevant functions for UC modelling
UC( y, u = NULL, model = "?/none/?/?", h = 9999, lambda = 1, outlier = 9999, tTest = FALSE, criterion = "aic", periods = NA, verbose = FALSE, stepwise = FALSE, p0 = -9999.9, arma = TRUE, TVP = NULL, trendOptions = "none/rw/llt/dt", seasonalOptions = "none/equal/different", irregularOptions = "none/arma(0,0)" )
UC( y, u = NULL, model = "?/none/?/?", h = 9999, lambda = 1, outlier = 9999, tTest = FALSE, criterion = "aic", periods = NA, verbose = FALSE, stepwise = FALSE, p0 = -9999.9, arma = TRUE, TVP = NULL, trendOptions = "none/rw/llt/dt", seasonalOptions = "none/equal/different", irregularOptions = "none/arma(0,0)" )
y |
a time series to forecast (it may be either a numerical vector or
a time series object). This is the only input required. If a vector, the additional
input |
u |
a matrix of external regressors included only in the observation equation.
(it may be either a numerical vector or a time series object). If the output wanted
to be forecast, matrix |
model |
the model to estimate. It is a single string indicating the type of model for each component. It allows two formats "trend/seasonal/irregular" or "trend/cycle/seasonal/irregular". The possibilities available for each component are:
|
h |
forecast horizon. If the model includes inputs h is not used, the lenght of u is used instead. |
lambda |
Box-Cox transformation lambda, NULL for automatic estimation |
outlier |
critical level of outlier tests. If NA it does not carry out any outlier detection (default). A positive value indicates the critical minimum t test for outlier detection in any model during identification. Three types of outliers are identified, namely Additive Outliers (AO), Level Shifts (LS) and Slope Change (SC). |
tTest |
augmented Dickey Fuller test for unit roots used in stepwise algorithm (TRUE / FALSE). The number of models to search for is reduced, depending on the result of this test. |
criterion |
information criterion for identification ("aic", "bic" or "aicc"). |
periods |
vector of fundamental period and harmonics required. |
verbose |
intermediate results shown about progress of estimation (TRUE / FALSE). |
stepwise |
stepwise identification procedure (TRUE / FALSE). |
p0 |
initial parameter vector for optimisation search. |
arma |
check for arma models for irregular components (TRUE / FALSE). |
TVP |
vector of zeros and ones to indicate TVP parameters. |
trendOptions |
trend models to select amongst (e.g., "rw/llt"). |
seasonalOptions |
seasonal models to select amongst (e.g., "none/differentt"). |
irregularOptions |
irregular models to select amongst (e.g., "none/arma(0,1)"). |
UC
is a function for modelling and forecasting univariate
time series according to Unobserved Components models (UC).
It sets up the model with a number of control variables that
govern the way the rest of functions in the package work. It also estimates
the model parameters by Maximum Likelihood, forecasts the data, performs smoothing,
estimates model disturbances, estimates components and shows statistical diagnostics.
Standard methods applicable to UComp objects are print, summary, plot,
fitted, residuals, logLik, AIC, BIC, coef, predict, tsdiag.
An object of class UComp
. It is a list with fields including all the inputs and
the fields listed below as outputs. All the functions in this package fill in
part of the fields of any UComp
object as specified in what follows (function
UC
fills in all of them at once):
After running UCmodel
or UCestim
:
p: Estimated parameters
v: Estimated innovations (white noise in correctly specified models)
yFor: Forecasted values of output
yForV: Forecasted values +- one standard error
criteria: Value of criteria for estimated model
iter: Number of iterations in estimation
grad: Gradient at estimated parameters
covp: Covariance matrix of parameters
After running UCvalidate
:
table: Estimation and validation table
After running UCcomponents
:
comp: Estimated components in matrix form
compV: Estimated components variance in matrix form
After running UCfilter
, UCsmooth
or UCdisturb
:
yFit: Fitted values of output
yFitV: Variance of fitted values of output
a: State estimates
P: Variance of state estimates
aFor: Forecasts of states
PFor: Forecasts of states variances
After running UCdisturb
:
eta: State perturbations estimates
eps: Observed perturbations estimates
Diego J. Pedregal
UC
, UCvalidate
, UCfilter
, UCsmooth
,
UCdisturb
, UCcomponents
,
UChp
## Not run: y <- log(AirPassengers) m1 <- UC(y) m1 <- UC(y, model = "llt/different/arma(0,0)") ## End(Not run)
## Not run: y <- log(AirPassengers) m1 <- UC(y) m1 <- UC(y, model = "llt/different/arma(0,0)") ## End(Not run)
Estimates unobserved components of UC models Standard methods applicable to UComp objects are print, summary, plot, fitted, residuals, logLik, AIC, BIC, coef, predict, tsdiag.
UCcomponents(sys)
UCcomponents(sys)
sys |
an object of type |
The same input object with the appropriate fields filled in, in particular:
comp: Estimated components in matrix form
compV: Estimated components variance in matrix form
Diego J. Pedregal
UC
, UCmodel
, UCvalidate
, UCfilter
,
UCsmooth
, UCdisturb
,
UChp
## Not run: m1 <- UC(log(AirPassengers)) m1 <- UCcomponents(m1) ## End(Not run)
## Not run: m1 <- UC(log(AirPassengers)) m1 <- UCcomponents(m1) ## End(Not run)
Runs the Disturbance Smoother for UC models
Standard methods applicable to UComp
objects are print, summary, plot,
fitted, residuals, logLik, AIC, BIC, coef, predict, tsdiag.
UCdisturb(sys)
UCdisturb(sys)
sys |
an object of type |
The same input object with the appropriate fields filled in, in particular:
yFit: Fitted values of output
yFitV: Variance of fitted values of output
a: State estimates
P: Variance of state estimates (diagonal of covariance matrices)
eta: State perturbations estimates
eps: Observed perturbations estimates
Diego J. Pedregal
UC
, UCmodel
, UCvalidate
, UCfilter
,
UCsmooth
, UCcomponents
,
UChp
## Not run: m1 <- UC(log(AirPassengers)) m1 <- UCdisturb(m1) ## End(Not run)
## Not run: m1 <- UC(log(AirPassengers)) m1 <- UCdisturb(m1) ## End(Not run)
Estimates and forecasts UC models
UCestim(sys)
UCestim(sys)
sys |
an object of type |
UCestim
estimates and forecasts a time series using an
UC model.
The optimization method is a BFGS quasi-Newton algorithm with a
backtracking line search using Armijo conditions.
Parameter names in output table are the following:
Damping: Damping factor for DT trend.
Level: Variance of level disturbance.
Slope: Variance of slope disturbance.
Rho(#): Damping factor of cycle #.
Period(#): Estimated period of cycle #.
Var(#): Variance of cycle #.
Seas(#): Seasonal harmonic with period #.
Irregular: Variance of irregular component.
AR(#): AR parameter of lag #.
MA(#): MA parameter of lag #.
AO#: Additive outlier in observation #.
LS#: Level shift outlier in observation #.
SC#: Slope change outlier in observation #.
Beta(#): Beta parameter of input #.
Cnst: Constant.
Standard methods applicable to UComp objects are print, summary, plot, fitted, residuals, logLik, AIC, BIC, coef, predict, tsdiag.
The same input object with the appropriate fields filled in, in particular:
p: Estimated transformed parameters
v: Estimated innovations (white noise in correctly specified models)
yFor: Forecast values of output
yForV: Forecasted values variance
criteria: Value of criteria for estimated model
covp: Covariance matrix of estimated transformed parameters
grad: Gradient of log-likelihood at the optimum
iter: Estimation iterations
Diego J. Pedregal
UC
, UCmodel
, UCvalidate
, UCfilter
,
UCsmooth
, UCdisturb
, UCcomponents
,
UChp
## Not run: m1 <- UCsetup(log(AirPassengers)) m1 <- UCestim(m1) ## End(Not run)
## Not run: m1 <- UCsetup(log(AirPassengers)) m1 <- UCestim(m1) ## End(Not run)
Runs the Kalman Filter for UC models
Standard methods applicable to UComp
objects are print, summary, plot,
fitted, residuals, logLik, AIC, BIC, coef, predict, tsdiag.
UCfilter(sys)
UCfilter(sys)
sys |
an object of type |
The same input object with the appropriate fields filled in, in particular:
yFit: Fitted values of output
yFitV: Variance of fitted values of output
a: State estimates
P: Variance of state estimates (diagonal of covariance matrices)
Diego J. Pedregal
UC
, UCmodel
, UCvalidate
,
UCsmooth
, UCdisturb
, UCcomponents
,
UChp
## Not run: m1 <- UC(log(AirPassengers)) m1 <- UCfilter(m1) ## End(Not run)
## Not run: m1 <- UC(log(AirPassengers)) m1 <- UCfilter(m1) ## End(Not run)
Hodrick-Prescott filter estimation
UChp(y, lambda = 1600)
UChp(y, lambda = 1600)
y |
A time series object |
lambda |
Smoothing constant (default: 1600) |
The cycle estimation
Diego J. Pedregal
UC
, UCmodel
, UCvalidate
, UCfilter
,
UCsmooth
, UCcomponents
, UCdisturb
## Not run: cycle <- UChp(USgdp) plot(cycle) ## End(Not run)
## Not run: cycle <- UChp(USgdp) plot(cycle) ## End(Not run)
Estimates and forecasts UC general univariate models
UCmodel( y, u = NULL, model = "?/none/?/?", h = 9999, lambda = 1, outlier = 9999, tTest = FALSE, criterion = "aic", periods = NA, verbose = FALSE, stepwise = FALSE, p0 = -9999.9, arma = TRUE, TVP = NULL, trendOptions = "none/rw/llt/dt", seasonalOptions = "none/equal/different", irregularOptions = "none/arma(0,0)" )
UCmodel( y, u = NULL, model = "?/none/?/?", h = 9999, lambda = 1, outlier = 9999, tTest = FALSE, criterion = "aic", periods = NA, verbose = FALSE, stepwise = FALSE, p0 = -9999.9, arma = TRUE, TVP = NULL, trendOptions = "none/rw/llt/dt", seasonalOptions = "none/equal/different", irregularOptions = "none/arma(0,0)" )
y |
a time series to forecast (it may be either a numerical vector or
a time series object). This is the only input required. If a vector, the additional
input |
u |
a matrix of external regressors included only in the observation equation.
(it may be either a numerical vector or a time series object). If the output wanted
to be forecast, matrix |
model |
the model to estimate. It is a single string indicating the type of model for each component. It allows two formats "trend/seasonal/irregular" or "trend/cycle/seasonal/irregular". The possibilities available for each component are:
|
h |
forecast horizon. If the model includes inputs h is not used, the lenght of u is used instead. |
lambda |
Box-Cox transformation lambda, NULL for automatic estimation |
outlier |
critical level of outlier tests. If NA it does not carry out any outlier detection (default). A positive value indicates the critical minimum t test for outlier detection in any model during identification. Three types of outliers are identified, namely Additive Outliers (AO), Level Shifts (LS) and Slope Change (SC). |
tTest |
augmented Dickey Fuller test for unit roots used in stepwise algorithm (TRUE / FALSE). The number of models to search for is reduced, depending on the result of this test. |
criterion |
information criterion for identification ("aic", "bic" or "aicc"). |
periods |
vector of fundamental period and harmonics required. |
verbose |
intermediate results shown about progress of estimation (TRUE / FALSE). |
stepwise |
stepwise identification procedure (TRUE / FALSE). |
p0 |
initial parameter vector for optimisation search. |
arma |
check for arma models for irregular components (TRUE / FALSE). |
TVP |
vector of zeros and ones to indicate TVP parameters. |
trendOptions |
trend models to select amongst (e.g., "rw/llt"). |
seasonalOptions |
seasonal models to select amongst (e.g., "none/differentt"). |
irregularOptions |
irregular models to select amongst (e.g., "none/arma(0,1)"). |
UCmodel
is a function for modelling and forecasting univariate
time series according to Unobserved Components models (UC).
It sets up the model with a number of control variables that
govern the way the rest of functions in the package work. It also estimates
the model parameters by Maximum Likelihood and forecasts the data.
Standard methods applicable to UComp objects are print, summary, plot,
fitted, residuals, logLik, AIC, BIC, coef, predict, tsdiag.
An object of class UComp
. It is a list with fields including all the inputs and
the fields listed below as outputs. All the functions in this package fill in
part of the fields of any UComp
object as specified in what follows (function
UC
fills in all of them at once):
After running UCmodel
or UCestim
:
p: Estimated parameters
v: Estimated innovations (white noise in correctly specified models)
yFor: Forecasted values of output
yForV: Forecasted values +- one standard error
criteria: Value of criteria for estimated model
iter: Number of iterations in estimation
grad: Gradient at estimated parameters
covp: Covariance matrix of parameters
After running UCvalidate
:
table: Estimation and validation table
After running UCcomponents
:
comp: Estimated components in matrix form
compV: Estimated components variance in matrix form
After running UCfilter
, UCsmooth
or UCdisturb
:
yFit: Fitted values of output
yFitV: Variance of fitted values of output
a: State estimates
P: Variance of state estimates
aFor: Forecasts of states
PFor: Forecasts of states variances
After running UCdisturb
:
eta: State perturbations estimates
eps: Observed perturbations estimates
Diego J. Pedregal
UC
, UCvalidate
, UCfilter
, UCsmooth
,
UCdisturb
, UCcomponents
,
UChp
## Not run: y <- log(AirPassengers) m1 <- UCmodel(y) m1 <- UCmodel(y, model = "llt/equal/arma(0,0)") ## End(Not run)
## Not run: y <- log(AirPassengers) m1 <- UCmodel(y) m1 <- UCmodel(y, model = "llt/equal/arma(0,0)") ## End(Not run)
Package for time series modelling and forecasting of times series models inspired on different sources:
Unobserved Components models due to A.C. Harvey (Basic Structural Model: BSM), enhanced with automatic identification tools by Diego J. Pedregal.
ExponenTial Smoothing by R.J. Hyndman and colaborators.
ARIMA models by V. Gómez and A. Maravall
Tobit ETS models by Pedregal, Trapero and Holgado
The package is designed for automatic identification among a wide range of possible models. The models may include exogenous variables. ARMA irregular components and automatic detection of outliers in some instances.
Harvey AC (1989). Forecasting, Structural Time Series Models and the Kalman Filter. Cam- bridge University Press.
de Jong, P & Penzer, J (1998). Diagnosing Shocks in Time Series, Journal of the American Statistical Association, 93, 442, 796-806.
Pedregal, DJ, & Young, PC (2002). Statistical approaches to modelling and forecasting time series. In M. Clements, & D. Hendry (Eds.), Companion to economic forecasting (pp. 69–104). Oxford: Blackwell Publishers.
Durbin J, Koopman SJ (2012). Time Series Analysis by State Space Methods. 38. Oxford University Press.
Proietti T and Luati A (2013). Maximum likelihood estimation of time series models: the Kalman filter and beyond, in Handbook of research methods and applications in empirical macroeconomics, ed. Nigar Hashimzade and Michael Thornton, E. Elgar, UK.
Hyndman RJ, Koehler AB, Ord JK and Snyder RD (2008), Forecasting with exponential smoothing, The State Sapce approach, Berlin, Springer-Verlag.
Gómez V and Maravall, A (2000), Automatic methods for univariate series. In Peña, D., Tiao, G.C. and Tsay R.S., A course in time series analyis. Wiley.
Trapero JR, Holgado E, Pedregal DJ (2024), Demand forecasting under lost sales stock policies, International Journal of Forecasting, 40, 1055-1068.
Diego J. Pedregal
Diego J. Pedregal
Sets up UC general univariate models
UCsetup( y, u = NULL, model = "?/none/?/?", h = 9999, lambda = 1, outlier = 9999, tTest = FALSE, criterion = "aic", periods = NA, verbose = FALSE, stepwise = FALSE, p0 = -9999.9, arma = FALSE, TVP = NULL, trendOptions = "none/rw/llt/dt", seasonalOptions = "none/equal/different", irregularOptions = "none/arma(0,0)" )
UCsetup( y, u = NULL, model = "?/none/?/?", h = 9999, lambda = 1, outlier = 9999, tTest = FALSE, criterion = "aic", periods = NA, verbose = FALSE, stepwise = FALSE, p0 = -9999.9, arma = FALSE, TVP = NULL, trendOptions = "none/rw/llt/dt", seasonalOptions = "none/equal/different", irregularOptions = "none/arma(0,0)" )
y |
a time series to forecast (it may be either a numerical vector or
a time series object). This is the only input required. If a vector, the additional
input |
u |
a matrix of external regressors included only in the observation equation.
(it may be either a numerical vector or a time series object). If the output wanted
to be forecast, matrix |
model |
the model to estimate. It is a single string indicating the type of model for each component. It allows two formats "trend/seasonal/irregular" or "trend/cycle/seasonal/irregular". The possibilities available for each component are:
|
h |
forecast horizon. If the model includes inputs h is not used, the lenght of u is used instead. |
lambda |
Box-Cox transformation lambda, NULL for automatic estimation |
outlier |
critical level of outlier tests. If NA it does not carry out any outlier detection (default). A positive value indicates the critical minimum t test for outlier detection in any model during identification. Three types of outliers are identified, namely Additive Outliers (AO), Level Shifts (LS) and Slope Change (SC). |
tTest |
augmented Dickey Fuller test for unit roots used in stepwise algorithm (TRUE / FALSE). The number of models to search for is reduced, depending on the result of this test. |
criterion |
information criterion for identification ("aic", "bic" or "aicc"). |
periods |
vector of fundamental period and harmonics required. |
verbose |
intermediate results shown about progress of estimation (TRUE / FALSE). |
stepwise |
stepwise identification procedure (TRUE / FALSE). |
p0 |
initial parameter vector for optimisation search. |
arma |
check for arma models for irregular components (TRUE / FALSE). |
TVP |
vector of zeros and ones to indicate TVP parameters. |
trendOptions |
trend models to select amongst (e.g., "rw/llt"). |
seasonalOptions |
seasonal models to select amongst (e.g., "none/differentt"). |
irregularOptions |
irregular models to select amongst (e.g., "none/arma(0,1)"). |
See help of UC
.
An object of class UComp
. It is a list with fields including all the inputs and
the fields listed below as outputs. All the functions in this package fill in
part of the fields of any UComp
object as specified in what follows (function
UC
fills in all of them at once):
After running UCmodel
or UCestim
:
p: Estimated parameters
v: Estimated innovations (white noise in correctly specified models)
yFor: Forecasted values of output
yForV: Variance of forecasts
criteria: Value of criteria for estimated model
iter: Number of iterations in estimation
grad: Gradient at estimated parameters
covp: Covariance matrix of parameters
After running UCvalidate
:
table: Estimation and validation table
After running UCcomponents
:
comp: Estimated components in matrix form
compV: Estimated components variance in matrix form
After running UCfilter
, UCsmooth
or UCdisturb
:
yFit: Fitted values of output
yFitV: Estimated fitted values variance
a: State estimates
P: Variance of state estimates
aFor: Forecasts of states
PFor: Forecasts of states variances
After running UCdisturb
:
eta: State perturbations estimates
eps: Observed perturbations estimates
Standard methods applicable to UComp objects are print, summary, plot, fitted, residuals, logLik, AIC, BIC, coef, predict, tsdiag.
Diego J. Pedregal
UC
, UCmodel
, UCvalidate
, UCfilter
, UCsmooth
,
UCdisturb
, UCcomponents
,
UChp
## Not run: y <- log(AirPassengers) m1 <- UCsetup(y) m1 <- UCsetup(y, outlier = 4) m1 <- UCsetup(y, model = "llt/equal/arma(0,0)") m1 <- UCsetup(y, model = "?/?/?/?") m1 <- UCsetup(y, model = "llt/?/equal/?", outlier = 4) ## End(Not run)
## Not run: y <- log(AirPassengers) m1 <- UCsetup(y) m1 <- UCsetup(y, outlier = 4) m1 <- UCsetup(y, model = "llt/equal/arma(0,0)") m1 <- UCsetup(y, model = "?/?/?/?") m1 <- UCsetup(y, model = "llt/?/equal/?", outlier = 4) ## End(Not run)
Runs the Fixed Interval Smoother for UC models
Standard methods applicable to UComp
objects are print, summary, plot,
fitted, residuals, logLik, AIC, BIC, coef, predict, tsdiag.
UCsmooth(sys)
UCsmooth(sys)
sys |
an object of type |
The same input object with the appropriate fields filled in, in particular:
yFit: Fitted values of output
yFitV: Variance of fitted values of output
a: State estimates
P: Variance of state estimates (diagonal of covariance matrices)
Diego J. Pedregal
UC
, UCmodel
, UCvalidate
, UCfilter
,
UCdisturb
, UCcomponents
,
UChp
## Not run: m1 <- UC(log(AirPassengers)) m1 <- UCsmooth(m1) ## End(Not run)
## Not run: m1 <- UC(log(AirPassengers)) m1 <- UCsmooth(m1) ## End(Not run)
Shows a table of estimation and diagnostics results for UC models. Equivalent to print or summary. The table shows information in four sections: Firstly, information about the model estimated, the relevant periods of the seasonal component included, and further information about convergence. Secondly, parameters with their names are provided, the asymptotic standard errors, the ratio of the two, and the gradient at the optimum. One asterisk indicates concentrated-out parameters and two asterisks signals parameters constrained during estimation. Thirdly, information criteria and the value of the log-likelihood. Finally, diagnostic statistics about innovations, namely, the Ljung-Box Q test of absense of autocorrelation statistic for several lags, the Jarque-Bera gaussianity test, and a standard ratio of variances test.
UCvalidate(sys, printScreen = TRUE)
UCvalidate(sys, printScreen = TRUE)
sys |
an object of type |
printScreen |
print to screen or just return output table |
The same input object with the appropriate fields filled in, in particular:
table: Estimation and validation table
Diego J. Pedregal
UC
, UCmodel
, UCfilter
,
UCsmooth
, UCdisturb
, UCcomponents
,
UChp
## Not run: m1 <- UC(log(gdp)) m1 <- UCvalidate(m1) ## End(Not run)
## Not run: m1 <- UC(log(gdp)) m1 <- UCvalidate(m1) ## End(Not run)
Ratio of variances test
varTest(y, parts = 1/3)
varTest(y, parts = 1/3)
y |
a vector, ts or tsibble object |
parts |
portion of sample to estimate variances |
Table with test results
Diego J. Pedregal
colMedians
, rowMedians
, tests
,
sumStats
, gaussTest
, ident
,
cusum
, conv
,
armaFilter
, dif
, roots
,
zplane
, acft
, slide
,
plotSlide
, Accuracy
, tsDisplay
,
size
varTest(AirPassengers)
varTest(AirPassengers)
Real-imaginary plane to show roots of digital filters (ARMA)
zplane(MApoly = 1, ARpoly = 1)
zplane(MApoly = 1, ARpoly = 1)
MApoly |
coefficients of numerator polynomial in descending order |
ARpoly |
coefficients of denominator polynomial in descending order |
Shows the real-imaginary plane to show zeros (roots of numerator or MA polynomial) and poles (roots of denominator of AR polynomial). Unit roots and real vs imaginary roots can be seen by eye
Diego J. Pedregal
colMedians
, rowMedians
, tests
,
sumStats
, gaussTest
, ident
,
cusum
, varTest
, conv
,
armaFilter
, dif
, roots
,
acft
, slide
,
plotSlide
, Accuracy
, tsDisplay
,
size
zplane(c(1, -2, 1), c(1, -0.8))
zplane(c(1, -2, 1), c(1, -0.8))