| Title: | Transfer Function and ARIMA Models |
|---|---|
| Description: | Build customized transfer function and ARIMA models with multiple operators and parameter restrictions. Provides tools for model identification, estimation using exact or conditional maximum likelihood, diagnostic checking, automatic outlier detection, calendar effects, forecasting, and seasonal adjustment. The new version also supports unobserved component ARIMA model specification and estimation for structural time series analysis. |
| Authors: | Jose L. Gallego [aut, cre] |
| Maintainer: | Jose L. Gallego <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 0.4.1 |
| Built: | 2026-06-01 10:24:41 UTC |
| Source: | https://github.com/gallegoj/tfarima |
The tfarima package provides classes and methods to build customized transfer function and ARIMA models with multiple operators and parameter restrictions. It includes functions for model identification, estimation using exact or conditional maximum likelihood, diagnostic checking, automatic outlier detection, calendar effects, forecasting, and seasonal adjustment.
The current version extends the functionality by incorporating the estimation of unobserved components in ARIMA models through the UCARIMA representation and structural time series models.
Jose Luis Gallego [email protected]
Bell, W. R. and Hillmer, S. C. (1983). Modeling Time Series with Calendar Variation. Journal of the American Statistical Association, 78(383), 526–534.
Box, G. E. P., Jenkins, G. M., Reinsel, G. C., and Ljung, G. M. (2015). Time Series Analysis: Forecasting and Control. John Wiley & Sons, Hoboken.
Box, G. E. P., Pierce, D. A., and Newbold, D. A. (1987). Estimating Trend and Growth Rates in Seasonal Time Series. Journal of the American Statistical Association, 82(397), 276–282.
Box, G. E. P. and Tiao, G. C. (1975). Intervention Analysis with Applications to Economic and Environmental Problems. Journal of the American Statistical Association, 70(349), 70–79.
Chen, C. and Liu, L. (1993). Joint Estimation of Model Parameters and Outlier Effects in Time Series. Journal of the American Statistical Association, 88(421), 284–297.
Thompson, H. E. and Tiao, G. C. (1971). Analysis of Telephone Data: A Case Study of Forecasting Seasonal Time Series. Bell Journal of Economics, 2(2), 515–541.
add_um creates a univariate (ARIMA) model from the addition or
substraction of two univariate (arima) models.
add_um(um1, um2, add = TRUE, tol = 1e-05)add_um(um1, um2, add = TRUE, tol = 1e-05)
um1, um2
|
Two "um" S3 objects. |
add |
logical. If FALSE, the second model is substracted from the first one. |
tol |
tolerance to check if a value is null. |
A "um" S3 object.
The + and - operators can also be used to add or substract ARIMA models.
um1 <- um(i = "(1 - B)", ma = "(1 - 0.8B)") um2 <- um(i = "(1 - B12)", ma = "(1 - 0.8B^12)") um3 <- add_um(um1, um2) um4 <- um3 - um2um1 <- um(i = "(1 - B)", ma = "(1 - 0.8B)") um2 <- um(i = "(1 - B12)", ma = "(1 - 0.8B^12)") um3 <- add_um(um1, um2) um4 <- um3 - um2
AIC for fitted state space models
## S3 method for class 'ssm' AIC(object, k = 2, ...)## S3 method for class 'ssm' AIC(object, k = 2, ...)
object |
an object of class |
k |
numeric, penalty per parameter (default is 2). |
... |
additional arguments. |
The AIC value, or NULL if model is not fitted.
Computes Akaike's Information Criterion (AIC) and Bayesian Information Criterion (BIC) for transfer function models.
## S3 method for class 'tfm' AIC(object, ..., k = 2) ## S3 method for class 'tfm' BIC(object, ...)## S3 method for class 'tfm' AIC(object, ..., k = 2) ## S3 method for class 'tfm' BIC(object, ...)
object |
A fitted |
... |
Additional |
k |
Numeric. Penalty per parameter. Default is 2 for AIC.
Use |
AIC = -2*logLik + k*npar, where npar is the number of parameters. Lower values indicate better fit penalized for complexity.
If one model: numeric value of AIC/BIC. If multiple models: data frame with columns df (degrees of freedom) and AIC for each model.
## Not run: model1 <- tfm(output, inputs = tf1, noise = noise1) model2 <- tfm(output, inputs = tf2, noise = noise2) # Single model AIC AIC(model1) # Compare models AIC(model1, model2) # BIC BIC(model1) ## End(Not run)## Not run: model1 <- tfm(output, inputs = tf1, noise = noise1) model2 <- tfm(output, inputs = tf2, noise = noise2) # Single model AIC AIC(model1) # Compare models AIC(model1, model2) # BIC BIC(model1) ## End(Not run)
Creates a seasonal ARIMA model with the structure popularized by Box and Jenkins using airline passenger data: (0,1,1)x(0,1,1)s.
airline(z, bc = FALSE, sma = c("standard", "generalized", "factorized"), ...)airline(z, bc = FALSE, sma = c("standard", "generalized", "factorized"), ...)
z |
A |
bc |
Logical. If TRUE, applies Box-Cox (log) transformation. |
sma |
Character. Specification for seasonal MA operator. Options are: standard, generalized or factorized. See manual for more details. |
... |
Additional arguments passed to |
This is a convenience function equivalent to: um(z, bc = bc, i
= list(1, c(1, s)), ma = list(1, c(1, s)), ...) where s = frequency(z).
A um object with airline model specification.
as.lagpol converts a numeric vector c(1, -a_1, ..., -a_d)
into a lag polynomial .
as.lagpol(pol, p = 1, coef.name = "a")as.lagpol(pol, p = 1, coef.name = "a")
pol |
the numeric vector to be converted into an object of class lag polynomial. |
p |
the exponent of the lag polynomial, positive integer. |
coef.name |
name prefix for coefficients, character. |
An object of class lagpol.
as.lagpol(c(1, -0.8)) as.lagpol(c(1, 0, 0, 0, -0.8))as.lagpol(c(1, -0.8)) as.lagpol(c(1, 0, 0, 0, -0.8))
as.ssm finds the structural form for an ARIMA model from its the
eventual forecast function.
## S3 method for class 'ucarima' as.ssm(object, ...) as.ssm(object, ...) ## S3 method for class 'um' as.ssm( object, z = NULL, msoe = TRUE, H = NULL, cform = TRUE, tol = 1.490116e-08, nonadm = c("quadprog", "nnls", "none"), envir = NULL, ... )## S3 method for class 'ucarima' as.ssm(object, ...) as.ssm(object, ...) ## S3 method for class 'um' as.ssm( object, z = NULL, msoe = TRUE, H = NULL, cform = TRUE, tol = 1.490116e-08, nonadm = c("quadprog", "nnls", "none"), envir = NULL, ... )
object |
an object of class |
... |
other arguments. |
z |
an optional time series. |
msoe |
logical, TRUE for multiple source of errors and FALSE for single source of error. |
H |
an optional matrix to reduce the number of variances. |
cform |
logical. TRUE for contemporaneous form and FALSE for future form. |
tol |
tolerance to check if the elements of b and C are zero. |
nonadm |
character, the method to overcome nonadmissibility: non-linear least squares, quadratic programming or none. |
envir |
environment, see " |
An object of class ssm
airl <- um(i = list(1, c(1, 12)), ma = "(1 - 0.8B)(1 - 0.8B12)") ssm1 <- as.ssm(airl, index = c(1, 0, rep(2, 11))) ssm1airl <- um(i = list(1, c(1, 12)), ma = "(1 - 0.8B)(1 - 0.8B12)") ssm1 <- as.ssm(airl, index = c(1, 0, rep(2, 11))) ssm1
Coerce an object to class "ucarima"
as.ucarima(object, ...)as.ucarima(object, ...)
object |
An object to be coerced. |
... |
Further arguments passed to or from methods. |
An object of class "ucarima".
Converts an object of class "um" (univariate model) to its equivalent
"ucarima" representation, i.e., the ARIMA-model-based decomposition of
unobserved components (trend, seasonal, cycle, irregular, etc.) implied by
the univariate ARIMA structure, following the approach of Hillmer and Tiao
(1982).
## S3 method for class 'um' as.ucarima( object, ar = NULL, i = NULL, single = FALSE, canonical = FALSE, cwfact = c("roots", "iter", "best"), pfrac = c("gcd", "solve"), tol = 1e-05, envir = parent.frame(), ... )## S3 method for class 'um' as.ucarima( object, ar = NULL, i = NULL, single = FALSE, canonical = FALSE, cwfact = c("roots", "iter", "best"), pfrac = c("gcd", "solve"), tol = 1e-05, envir = parent.frame(), ... )
object |
An object of class |
ar |
Autoregressive lag polynomial for the signal component. |
i |
Integration lag polynomial for the signal component. |
single |
Logical. If |
canonical |
Logical. If |
cwfact |
Method for Cramer-Wold factorization: |
pfrac |
Method for partial fraction decomposition: |
tol |
Numerical tolerance for zero and unit values. Default is
|
envir |
Environment for evaluation. |
... |
Additional arguments. |
The UCARIMA decomposition expresses a univariate ARIMA model as the sum of independent component ARIMA models (trend, seasonal, cycle, irregular, etc.) obtained through the factorization of its spectral density. This provides a model-based interpretation of signal extraction and seasonal adjustment.
Hillmer, S. C., & Tiao, G. C. (1982). An ARIMA-model-based approach to seasonal adjustment. Journal of the American Statistical Association, 77(377), 63–70.
Burman, J. P. (1980). Seasonal adjustment by signal extraction. Journal of the Royal Statistical Society: Series A, 143(3), 321–337.
Godolphin, E. J. (1976). On the Cramer–Wold factorization. Biometrika, 63(2), 367–372. doi:10.1093/biomet/63.2.367
Tunnicliffe Wilson, G. (1969). Factorization of the covariance generating function of a pure moving average process. SIAM Journal on Numerical Analysis, 6(1), 1–7. doi:10.1137/0706001
arima into um.as.um converts an object of class arima into an object
of class um.
as.um(arima, ...)as.um(arima, ...)
arima |
an object of class |
... |
additional arguments. |
An object of class um.
z <- AirPassengers a <- arima(log(z), order = c(0,1,1), seasonal = list(order = c(0,1,1), frequency = 12)) um1 <- as.um(a)z <- AirPassengers a <- arima(log(z), order = c(0,1,1), seasonal = list(order = c(0,1,1), frequency = 12)) um1 <- as.um(a)
autocorr computes the simple/partial autocorrelations of an ARMA model.
## S3 method for class 'ucarima' autocorr(x, ...) autocorr(x, ...) ## S3 method for class 'um' autocorr(x, lag.max = 10, par = FALSE, ...)## S3 method for class 'ucarima' autocorr(x, ...) autocorr(x, ...) ## S3 method for class 'um' autocorr(x, lag.max = 10, par = FALSE, ...)
x |
an object of class |
... |
additional arguments. |
lag.max |
maximum lag for autocovariances. |
par |
logical. If TRUE partial autocorrelations are computed. |
A numeric vector.
The I polynomial is ignored.
ar1 <- um(ar = "1-0.8B") autocorr(ar1, lag.max = 13) autocorr(ar1, lag.max = 13, par = TRUE)ar1 <- um(ar = "1-0.8B") autocorr(ar1, lag.max = 13) autocorr(ar1, lag.max = 13, par = TRUE)
autocov computes the autocovariances of an ARMA model.
## S3 method for class 'ssm' autocov(mdl, lag.max = NULL, arma = TRUE, varphi = FALSE, tol = 1e-04, ...) ## S3 method for class 'ucarima' autocov(mdl, ma = FALSE, ...) autocov(mdl, ...) ## S3 method for class 'um' autocov(mdl, lag.max = 10, ...)## S3 method for class 'ssm' autocov(mdl, lag.max = NULL, arma = TRUE, varphi = FALSE, tol = 1e-04, ...) ## S3 method for class 'ucarima' autocov(mdl, ma = FALSE, ...) autocov(mdl, ...) ## S3 method for class 'um' autocov(mdl, lag.max = 10, ...)
mdl |
an object of class |
lag.max |
maximum lag for autocovariances. |
arma |
logical. If TRUE, the autocovariances for the stationary ARMA model of the reduced form are computed. Otherwise, the autocovariances are only computed for the MA part. |
varphi |
logical. If TRUE, the varphi polynomial of the reduced form is also returned. |
tol |
tolerance to check if a root is close to one. |
... |
additional arguments. |
ma |
logical; if true, autocovariances are computed for the MA model. By default, ma = FALSE and autocovariances are computed for the ARMA model. |
A numeric vector.
The I polynomial is ignored.
# Local level model ssm1 <- ssm(b = 1, C = 1, S = diag(c(irr = 0.8, lvl = 0.04))) autocov(ssm1) ar1 <- um(ar = "1-0.8B") autocov(ar1, lag.max = 13)# Local level model ssm1 <- ssm(b = 1, C = 1, S = diag(c(irr = 0.8, lvl = 0.04))) autocov(ssm1) ar1 <- um(ar = "1-0.8B") autocov(ar1, lag.max = 13)
Computes MA polynomial coefficients and error variance from autocovariances.
autocov2MA(x, method = c("roots", "acov"), tol = 1e-05)autocov2MA(x, method = c("roots", "acov"), tol = 1e-05)
x |
Numeric vector of autocovariances (length q). |
method |
Estimation method: "roots" (Godolphin 1976) or "acov" (Wilson 1969). Default is "roots". |
tol |
Tolerance for zero autocovariance. Default 1e-5. |
Named vector: c(s2, ma0=1, ma1=-theta1, ..., maq=-thetaq).
Godolphin, E. J. (1976). On the Cramer-Wold factorization. Biometrika, 63(2), 367-372. doi:10.1093/biomet/63.2.367
Tunnicliffe Wilson, G. (1969). Factorization of the covariance generating function of a pure moving average process. SIAM Journal on Numerical Analysis, 6(1), 1-7. doi:10.1137/0706001
ma1 <- um(ma = "1 - 0.8B", sig2 = 0.5) autocov2MA(autocov(ma1, 1)) autocov2MA(autocov(ma1, 1), method = "acov")ma1 <- um(ma = "1 - 0.8B", sig2 = 0.5) autocov2MA(autocov(ma1, 1)) autocov2MA(autocov(ma1, 1), method = "acov")
Monthly U.S. retail sales for building material and supplies dealers (NAICS code 4441), in millions of dollars, seasonally adjusted. Source: U.S. Census Bureau, Monthly Retail Trade Survey (via FRED).
BuildingMatBuildingMat
A time series object of class ts with frequency 12,
starting in January 1992 and ending in December 2024.
U.S. Census Bureau, Monthly Retail Trade Survey. FRED series code: MRTSSM4441USS.
calendar extends the ARIMA model um by including a set of
deterministic variables to capture the calendar variation in a monthly time
series. Two equivalent representations are available: (i) D0, D1, ..., D6,
(ii) L, D1-D0, ..., D6-D0 where D0, D2, ..., D6 are deterministic variables
representing the number of Sundays, Mondays, ..., Saturdays, L = D0 + D1 + ...
+ D6 is the of the month. Alternatively, the Leap Year indicator (LPY) can be
included instead of L. The seven trading days can also be compacted into two
variables: week days and weekends. Optionally, a deterministic variable to
estimate the Easter effect can also be included, see "easter".
## S3 method for class 'ssm' calendar( mdl, form = c("dif", "td", "td7", "td6", "wd"), ref = 0, lom = TRUE, lpyear = TRUE, easter = FALSE, len = 4, easter.mon = FALSE, n.ahead = 0, p.value = 1, envir = NULL, ... ) ## S3 method for class 'tfm' calendar( mdl, y = NULL, form = c("dif", "td", "td7", "td6", "wd"), ref = 0, lom = TRUE, lpyear = TRUE, easter = FALSE, len = 4, easter.mon = FALSE, n.ahead = 0, p.value = 1, envir = parent.frame(), ... ) calendar(mdl, ...) ## S3 method for class 'um' calendar( mdl, y = NULL, form = c("dif", "td", "td7", "td6", "wd"), ref = 0, lom = TRUE, lpyear = TRUE, easter = FALSE, len = 4, easter.mon = FALSE, n.ahead = 0, p.value = 1, envir = parent.frame(), ... )## S3 method for class 'ssm' calendar( mdl, form = c("dif", "td", "td7", "td6", "wd"), ref = 0, lom = TRUE, lpyear = TRUE, easter = FALSE, len = 4, easter.mon = FALSE, n.ahead = 0, p.value = 1, envir = NULL, ... ) ## S3 method for class 'tfm' calendar( mdl, y = NULL, form = c("dif", "td", "td7", "td6", "wd"), ref = 0, lom = TRUE, lpyear = TRUE, easter = FALSE, len = 4, easter.mon = FALSE, n.ahead = 0, p.value = 1, envir = parent.frame(), ... ) calendar(mdl, ...) ## S3 method for class 'um' calendar( mdl, y = NULL, form = c("dif", "td", "td7", "td6", "wd"), ref = 0, lom = TRUE, lpyear = TRUE, easter = FALSE, len = 4, easter.mon = FALSE, n.ahead = 0, p.value = 1, envir = parent.frame(), ... )
mdl |
|
form |
representation for calendar effects: (1) |
ref |
a integer indicating the the reference day. By default, ref = 0. |
lom, lpyear
|
a logical value indicating whether or not to include the lom/lead year indicator. |
easter |
logical. If |
len |
the length of the Easter, integer. |
easter.mon |
logical. TRUE indicates that Easter Monday is a public holiday. |
n.ahead |
a positive integer to extend the sample period of the
deterministic variables with |
p.value |
estimates with a p-value greater than p.value are omitted. |
envir |
environment in which the function arguments are evaluated. If NULL the calling environment of this function will be used. |
... |
other arguments. |
y |
a time series. |
An object of class "tfm".
W. R. Bell & S. C. Hillmer (1983) Modeling Time Series with Calendar Variation, Journal of the American Statistical Association, 78:383, 526-534, DOI: 10.1080/01621459.1983.10478005
data(rsales) um1 <- um(rsales, i = list(1, c(1, 12)), ma = list(1, c(1, 12)), bc = TRUE) tfm1 <- calendar(um1)data(rsales) um1 <- um(rsales, i = list(1, c(1, 12)), ma = list(1, c(1, 12)), bc = TRUE) tfm1 <- calendar(um1)
'CalendarVar()' creates a set of deterministic regressors to capture calendar effects (trading/working days, length-of-month, leap-year and Easter).
CalendarVar( x, form = c("dif", "td", "td7", "td6", "wd", "null"), ref = 0, lom = TRUE, lpyear = TRUE, easter = FALSE, len = 4, easter.mon = FALSE, n.ahead = 0 )CalendarVar( x, form = c("dif", "td", "td7", "td6", "wd", "null"), ref = 0, lom = TRUE, lpyear = TRUE, easter = FALSE, len = 4, easter.mon = FALSE, n.ahead = 0 )
x |
A 'ts' object used to determine start, length and frequency. |
form |
Character selecting the set of calendar variables: '"dif"' (differences wrt reference day), '"td"' (6 dummies + lom; omits reference), '"td7"' (7 dummies), '"td6"' (6 dummies; omits reference), '"wd"' (weekdays vs weekend), or '"null"' (no trading-day regressors). |
ref |
Non-negative integer (0–6) indicating the reference day (0 = Sunday, 1 = Monday, …, 6 = Saturday). Ignored unless 'form' needs it. |
lom |
Logical. If 'TRUE' include a length-of-month regressor. |
lpyear |
Logical. If 'TRUE' include a leap-year regressor. |
easter |
Logical. If 'TRUE' include an Easter regressor. |
len |
Integer duration for Easter effect (days). Typical values: 4–8. |
easter.mon |
Logical. 'TRUE' if Holy Monday is a public holiday. |
n.ahead |
Integer. Extra observations to extend the sample (forecast horizon). |
An object of class 'ts' or 'mts' with the requested regressors.
Bell, W.R. and Hillmer, S.C. (1983) “Modeling time series with calendar variation”, *Journal of the American Statistical Association*, 78, 526–534.
X <- CalendarVar(AirPassengers, form = "wd", easter = TRUE, len = 5)X <- CalendarVar(AirPassengers, form = "wd", easter = TRUE, len = 5)
ccf displays ccf between prewhitened inputs and residuals.
ccf.tfm( x, lag.max = NULL, method = c("exact", "cond"), envir = parent.frame(), ... )ccf.tfm( x, lag.max = NULL, method = c("exact", "cond"), envir = parent.frame(), ... )
x |
a |
lag.max |
number of lags. |
method |
Exact/conditional residuals. |
envir |
environment in which the function arguments are evaluated. |
... |
additional arguments. |
Extracts the estimated coefficients from a fitted transfer function model
of class tfm. This is a method for the generic coef
function.
## S3 method for class 'tfm' coef(object, ...)## S3 method for class 'tfm' coef(object, ...)
object |
An object of class |
... |
Further arguments (currently unused). |
A named numeric vector with the estimated coefficients of the model, including regression coefficients, transfer function parameters, and noise model parameters.
## Not run: mdl <- tfm(y, xreg = X, noise = um()) coef(mdl) ## End(Not run)## Not run: mdl <- tfm(y, xreg = X, noise = um()) coef(mdl) ## End(Not run)
Extract coefficients from UCM objects
## S3 method for class 'ucm' coef(object, ...)## S3 method for class 'ucm' coef(object, ...)
object |
an object of class |
... |
currently unused. |
A named numeric vector of model coefficients.
coef extracts the "coefficients" from a um object.
## S3 method for class 'um' coef(object, ...)## S3 method for class 'um' coef(object, ...)
object |
a |
... |
other arguments. |
A numeric vector.
cwfact performs the Cramer-Wold factorization of the generating
autocovariance function of a pure moving average (MA) process, expressed as:
where
and
cwfact( g, th = NULL, method = c("roots", "wilson", "best"), tol = 1e-08, iter.max = 500 )cwfact( g, th = NULL, method = c("roots", "wilson", "best"), tol = 1e-08, iter.max = 500 )
g |
A numeric vector with the autocovariance coefficients |
th |
Optional numeric vector with initial values for the MA coefficients
|
method |
A character string specifying the factorization method to use.
Options are |
tol |
A numeric tolerance for convergence (only used for |
iter.max |
Maximum number of iterations for the Wilson method. Default
is |
The factorization can be computed by finding the roots of the polynomial
, or using the iterative Wilson (1969) algorithm as implemented by
Laurie (1981).
The implementation for method = "laurie" is a custom R
adaptation of Algorithm AS 175 from Laurie (1981).
A numeric vector containing the moving average coefficients
c(theta_0, ..., theta_q).
Wilson, G. T. (1969). Factorization of the covariance generating function of a pure moving average process. SIAM Journal on Numerical Analysis, 6(1), 1–7.
Laurie, D. P. (1981). Cramer-Wold Factorization. Journal of the Royal Statistical Society Series C: Applied Statistics, 31(1), 86–93.
g <- autocov(um(ma = "1 - 0.8B"), lag.max = 1) cwfact(g, method = "roots") cwfact(g, method = "wilson")g <- autocov(um(ma = "1 - 0.8B"), lag.max = 1) cwfact(g, method = "roots") cwfact(g, method = "wilson")
Estimates the unobserved components of a time series (trend, seasonal, cycle, stationary, and irregular) based on the structure of an underlying model. The estimation can be carried out through the UCARIMA representation, the state-space model (SSM) form, or via forward/backward forecasts.
## S3 method for class 'ssm' decomp(mdl, tol = 1e-05, ...) ## S3 method for class 'tfm' decomp( mdl, y = NULL, method = c("mixed", "forecast", "backcast"), envir = NULL, ... ) ## S3 method for class 'ucarima' decomp(mdl, ...) decomp(mdl, ...) ## S3 method for class 'um' decomp( mdl, z = NULL, method = c("ucarima", "ucarima0", "ssm", "ssm0", "mixed", "forecast", "backcast"), envir = parent.frame(), ... ) ## S3 method for class 'um' decomp( mdl, z = NULL, method = c("ucarima", "ucarima0", "ssm", "ssm0", "mixed", "forecast", "backcast"), envir = parent.frame(), ... )## S3 method for class 'ssm' decomp(mdl, tol = 1e-05, ...) ## S3 method for class 'tfm' decomp( mdl, y = NULL, method = c("mixed", "forecast", "backcast"), envir = NULL, ... ) ## S3 method for class 'ucarima' decomp(mdl, ...) decomp(mdl, ...) ## S3 method for class 'um' decomp( mdl, z = NULL, method = c("ucarima", "ucarima0", "ssm", "ssm0", "mixed", "forecast", "backcast"), envir = parent.frame(), ... ) ## S3 method for class 'um' decomp( mdl, z = NULL, method = c("ucarima", "ucarima0", "ssm", "ssm0", "mixed", "forecast", "backcast"), envir = parent.frame(), ... )
mdl |
An object of class |
tol |
numeric tolerance for classifying eigenvalues. |
... |
Additional arguments passed to internal methods. |
y |
an object of class |
method |
Character string specifying the decomposition method. Options are:
|
envir |
environment in which the function arguments are evaluated. If NULL the calling environment of this function will be used. |
z |
an object of class |
The function applies the corresponding internal routines to estimate
the components depending on the chosen method. For UCARIMA-based
methods, the Wiener–Kolmogorov filter is used. For state-space approaches,
a Kalman smoother is applied.
A data.frame with the estimated unobserved components.
Z <- AirPassengers um1 <- um(Z, i = list(1, c(1, 12)), ma = list(1, c(1, 12)), bc = TRUE) uc1 <- decomp(um1, method = "ucarima")Z <- AirPassengers um1 <- um(Z, i = list(1, c(1, 12)), ma = list(1, c(1, 12)), bc = TRUE) uc1 <- decomp(um1, method = "ucarima")
For objects of class ucarima, this method calls diagchk.um
internally to perform diagnostic checking.
diagchk displays tools for diagnostic checking.
## S3 method for class 'ssm' diagchk(mdl, lag.max = NULL, lags.at = NULL, freq.at = NULL, std = TRUE, ...) ## S3 method for class 'ucarima' diagchk(mdl, ...) diagchk(mdl, ...) ## S3 method for class 'um' diagchk( mdl, z = NULL, method = c("exact", "cond"), lag.max = NULL, lags.at = NULL, freq.at = NULL, std = TRUE, envir = NULL, ... )## S3 method for class 'ssm' diagchk(mdl, lag.max = NULL, lags.at = NULL, freq.at = NULL, std = TRUE, ...) ## S3 method for class 'ucarima' diagchk(mdl, ...) diagchk(mdl, ...) ## S3 method for class 'um' diagchk( mdl, z = NULL, method = c("exact", "cond"), lag.max = NULL, lags.at = NULL, freq.at = NULL, std = TRUE, envir = NULL, ... )
mdl |
an object of class |
lag.max |
integer; maximum number of lags for ACF/PACF. |
lags.at |
numeric vector; specific lags in ACF/PACF plots. |
freq.at |
numeric vector; specific frequencies in (cum) periodogram plot. |
std |
logical; if TRUE standardized residuals are used. |
... |
additional arguments. |
z |
optional, an object of class |
method |
character; "exact" or "conditional" residuals. |
envir |
environment in which the function arguments are evaluated. If NULL the calling environment of this function will be used. |
# Local level model b <- 1 C <- as.matrix(1) ssm1 <- ssm(Nile, b, C, S = diag(c(irr = 15127.7, lvl = 1453.2))) diagchk(ssm1) z <- AirPassengers airl <- um(z, i = list(1, c(1,12)), ma = list(1, c(1,12)), bc = TRUE) diagchk(airl)# Local level model b <- 1 C <- as.matrix(1) ssm1 <- ssm(Nile, b, C, S = diag(c(irr = 15127.7, lvl = 1453.2))) diagchk(ssm1) z <- AirPassengers airl <- um(z, i = list(1, c(1,12)), ma = list(1, c(1,12)), bc = TRUE) diagchk(airl)
Produces diagnostic plots for residuals of a fitted transfer function model.
## S3 method for class 'tfm' diagchk( mdl, y = NULL, method = c("exact", "cond"), lag.max = NULL, lags.at = NULL, freq.at = NULL, std = TRUE, envir = NULL, ... )## S3 method for class 'tfm' diagchk( mdl, y = NULL, method = c("exact", "cond"), lag.max = NULL, lags.at = NULL, freq.at = NULL, std = TRUE, envir = NULL, ... )
mdl |
A fitted |
y |
Optional |
method |
Character: "exact" or "cond" for residual calculation. |
lag.max |
Maximum lag for ACF/PACF plots. |
lags.at |
Specific lags to display in ACF/PACF. |
freq.at |
Specific frequencies for cumulative periodogram. |
std |
Logical. If TRUE, standardizes residuals. |
envir |
Environment for evaluation. NULL uses calling environment. |
... |
Additional arguments passed to |
Generates five diagnostic plots: time series plot of residuals,
histogram, ACF, PACF, and cumulative periodogram. Uses the ide
function for plotting.
display shows graphs characterizing one or a list of ARMA models.
display(um, ...) ## S3 method for class 'um' display( um, lag.max = 25, n.freq = 501, log.spec = FALSE, lags.at = NULL, graphs = c("acf", "pacf", "spec"), byrow = FALSE, eq = TRUE, cex = 1.25, ... ) ## Default S3 method: display(um, ...)display(um, ...) ## S3 method for class 'um' display( um, lag.max = 25, n.freq = 501, log.spec = FALSE, lags.at = NULL, graphs = c("acf", "pacf", "spec"), byrow = FALSE, eq = TRUE, cex = 1.25, ... ) ## Default S3 method: display(um, ...)
um |
an object of class |
... |
additional arguments. |
lag.max |
number of lags for ACF/PACF. |
n.freq |
number of frequencies for the spectrum. |
log.spec |
logical. If TRUE log spectrum is computed. |
lags.at |
the lags of the ACF/PACF at which tick-marks are to be drawn. |
graphs |
vector of graphs. |
byrow |
orientation of the graphs. |
eq |
logical. If TRUE the model equation is used as title. |
cex |
double. Font size for equation text. |
um1 <- um(ar = "(1 - 0.8B)(1 - 0.8B^12)") um2 <- um(ma = "(1 - 0.8B)(1 - 0.8B^12)") display(list(um1, um2))um1 <- um(ar = "(1 - 0.8B)(1 - 0.8B^12)") um2 <- um(ma = "(1 - 0.8B)(1 - 0.8B^12)") display(list(um1, um2))
easter extends the ARIMA model um by including a regression
variable to capture the Easter effect.
easter(um, ...) ## S3 method for class 'um' easter( um, z = NULL, len = 4, easter.mon = FALSE, n.ahead = 0, envir = NULL, ... )easter(um, ...) ## S3 method for class 'um' easter( um, z = NULL, len = 4, easter.mon = FALSE, n.ahead = 0, envir = NULL, ... )
um |
an object of class |
... |
other arguments. |
z |
a time series. |
len |
a positive integer specifying the duration of the Easter. |
easter.mon |
logical. If TRUE Easter Monday is also taken into account. |
n.ahead |
a positive integer to extend the sample period of the
Easter regression variable with |
envir |
environment in which the function arguments are evaluated. If NULL the calling environment of this function will be used. |
An object of class "tfm".
data(rsales) um1 <- um(rsales, i = list(1, c(1, 12)), ma = list(1, c(1, 12)), bc = TRUE) tfm1 <- easter(um1)data(rsales) um1 <- um(rsales, i = list(1, c(1, 12)), ma = list(1, c(1, 12)), bc = TRUE) tfm1 <- easter(um1)
equation prints the equation of an object of class um.
## S3 method for class 'ucarima' equation(x, ...) equation(x, ...) ## S3 method for class 'um' equation( x, unscramble = FALSE, digits = 4, z = "z", a = "a", width = NULL, ... )## S3 method for class 'ucarima' equation(x, ...) equation(x, ...) ## S3 method for class 'um' equation( x, unscramble = FALSE, digits = 4, z = "z", a = "a", width = NULL, ... )
x |
an object of class |
... |
additional arguments. |
unscramble |
logical. If TRUE, AR, I and MA polynomials are unscrambled. |
digits |
integer. Number of significant digits. |
z |
character. Symbol for time series. |
a |
character. Symbol for error. |
width |
integer. Maximum width for line wrapping. If NULL, uses console width. |
equation(um(ar = "(1 - 0.8B)"))equation(um(ar = "(1 - 0.8B)"))
factorize .
factorize(um, ...) ## S3 method for class 'um' factorize(um, full = TRUE, ...)factorize(um, ...) ## S3 method for class 'um' factorize(um, full = TRUE, ...)
um |
an object of class |
... |
additional arguments. |
full |
logical value. If TRUE, lag polynomials are completely factorized. Otherwise, they are factored isolating positive real roots and grouping the remaining roots. |
factorize(um(ar = "(1 - 0.8B)"))factorize(um(ar = "(1 - 0.8B)"))
factors extracts the simplifying factors of a polynomial in the lag
operator by replacing, if needed, its approximate unit or real roots to exact
unit or real roots.
factors(lp, ...) ## S3 method for class 'lagpol' factors(lp, full = TRUE, tol = 1e-05, expand = FALSE, ...)factors(lp, ...) ## S3 method for class 'lagpol' factors(lp, full = TRUE, tol = 1e-05, expand = FALSE, ...)
lp |
an object of class |
... |
additional arguments. |
full |
logical value. If TRUE, the lag polynomial is completely factored. Otherwise, it is factored separating positive real roots from the others. |
tol |
tolerance for nonzero coefficients. |
expand |
logical value to indicate whether or not the factored lag polynomial must be expanded. |
factors returns a list with the simplifying factors of the lag
polynomial or the expanded polynomial.
factors( as.lagpol(c(1, rep(0, 11), -1)) )factors( as.lagpol(c(1, rep(0, 11), -1)) )
fit fits the univariate model to the time series z.
## S3 method for class 'ssm' fit( mdl, z = NULL, updateSSM, param, show.iter = FALSE, tol = 1e-04, method = "BFGS", ... ) fit(mdl, ...) ## S3 method for class 'um' fit( mdl, z = NULL, method = c("exact", "cond"), optim.method = "BFGS", show.iter = FALSE, envir = NULL, ... )## S3 method for class 'ssm' fit( mdl, z = NULL, updateSSM, param, show.iter = FALSE, tol = 1e-04, method = "BFGS", ... ) fit(mdl, ...) ## S3 method for class 'um' fit( mdl, z = NULL, method = c("exact", "cond"), optim.method = "BFGS", show.iter = FALSE, envir = NULL, ... )
mdl |
|
z |
a time series. |
updateSSM |
user function to update the parameters of the SS model. The function must take a model object and a parameter vector as inputs and return an updated model object. |
param |
a numeric vector of named parameters passed to the
|
show.iter |
logical value to show or hide the estimates at the different iterations. |
tol |
numeric. Tolerance to check if a root is close to one. |
method |
Exact/conditional maximum likelihood. |
... |
additional arguments for the |
optim.method |
the |
envir |
environment in which the function arguments are evaluated. If NULL the calling environment of this function will be used. |
An object of class "ssm" with the estimated parameters.
An object of class "um" with the estimated parameters.
The um function estimates the corresponding ARIMA model when a time
series is provided. The fit function is useful to fit a model to
several time series, for example, in a Monte Carlo study.
# Predefined local level model ucm1 <- ucm(Nile, uc = "llm", fit = FALSE) ucm1 <- fit(ucm1) ucm1 # User defined local level model ssm1 <- ssm(Nile, b = 1, C = 1, S = diag(c(1, 0.5)) ) param <- c(irr = var(Nile), lvl = var(diff(Nile))) updateSSM <- function(mdl, param) { mdl$S[1,1] <- param[1] mdl$S[2,2] <- param[2] mdl } fit(ssm1, updateSSM = updateSSM, param = param) z <- AirPassengers airl <- um(i = list(1, c(1, 12)), ma = list(1, c(1, 12)), bc = TRUE) airl <- fit(airl, z)# Predefined local level model ucm1 <- ucm(Nile, uc = "llm", fit = FALSE) ucm1 <- fit(ucm1) ucm1 # User defined local level model ssm1 <- ssm(Nile, b = 1, C = 1, S = diag(c(1, 0.5)) ) param <- c(irr = var(Nile), lvl = var(diff(Nile))) updateSSM <- function(mdl, param) { mdl$S[1,1] <- param[1] mdl$S[2,2] <- param[2] mdl } fit(ssm1, updateSSM = updateSSM, param = param) z <- AirPassengers airl <- um(i = list(1, c(1, 12)), ma = list(1, c(1, 12)), bc = TRUE) airl <- fit(airl, z)
Estimates the parameters of a transfer function model of class tfm by
(conditional or exact) maximum likelihood.
## S3 method for class 'tfm' fit( mdl, y = NULL, method = c("exact", "cond"), optim.method = "BFGS", show.iter = FALSE, fit.noise = TRUE, envir = NULL, ... )## S3 method for class 'tfm' fit( mdl, y = NULL, method = c("exact", "cond"), optim.method = "BFGS", show.iter = FALSE, fit.noise = TRUE, envir = NULL, ... )
mdl |
An object of class |
y |
Optional |
method |
Character string specifying likelihood method: "exact" for exact maximum likelihood or "cond" for conditional maximum likelihood. Default is "exact". |
optim.method |
Character. Optimization method passed to
|
show.iter |
Logical. If |
fit.noise |
Logical. If |
envir |
Environment in which the function arguments are evaluated. If
|
... |
Additional arguments. |
An updated object of class tfm containing fitted parameters,
estimated innovation variance, and optimization details.
## Not run: data(seriesJ) Y <- seriesJ$Y - mean(seriesJ$Y) X <- seriesJ$X - mean(seriesJ$X) umx <- um(X, ar = 3) umy <- fit(umx, Y) tfx <- tfest(Y, X, delay = 3, p = 2, q = 2, um.x = umx, um.y = umy) tfmy <- tfm(Y, inputs = tfx, noise = um(ar = 2), fit = FALSE) tfmy_fit <- fit(tfmy) ## End(Not run)## Not run: data(seriesJ) Y <- seriesJ$Y - mean(seriesJ$Y) X <- seriesJ$X - mean(seriesJ$X) umx <- um(X, ar = 3) umy <- fit(umx, Y) tfx <- tfest(Y, X, delay = 3, p = 2, q = 2, um.x = umx, um.y = umy) tfmy <- tfm(Y, inputs = tfx, noise = um(ar = 2), fit = FALSE) tfmy_fit <- fit(tfmy) ## End(Not run)
Estimates the parameters of a UCARIMA model using maximum likelihood.
## S3 method for class 'ucarima' fit(mdl, z = NULL, method = "BFGS", show.iter = FALSE, envir = NULL, ...)## S3 method for class 'ucarima' fit(mdl, z = NULL, method = "BFGS", show.iter = FALSE, envir = NULL, ...)
mdl |
An object of class |
z |
Optional. A time series object ( |
method |
Character string specifying the optimization method passed to
|
show.iter |
Logical. If |
envir |
Environment where the estimation is evaluated. If |
... |
Additional arguments passed to |
An updated ucarima object with estimated parameters,
log-likelihood, and convergence information.
# Define a local level model with trend and irregular components trend <- um(i = 1, sig2 = c(s2t = 0.5)) irreg <- um(sig2 = c(s2i = 1)) # Create and estimate the UCARIMA model uca <- ucarima(ucm = list(trend = trend, irreg = irreg)) uca_fitted <- fit(uca, Nile)# Define a local level model with trend and irregular components trend <- um(i = 1, sig2 = c(s2t = 0.5)) irreg <- um(sig2 = c(s2i = 1)) # Create and estimate the UCARIMA model uca <- ucarima(ucm = list(trend = trend, irreg = irreg)) uca_fitted <- fit(uca, Nile)
ide displays graphs useful to identify a tentative ARIMA model for a
time series.
ide( Y, transf = list(), order.polreg = 0, lag.max = NULL, lags.at = NULL, freq.at = NULL, wn.bands = TRUE, graphs = c("plot", "acf", "pacf"), set.layout = TRUE, byrow = TRUE, main = "", plot.abline.args = NULL, plot.points.args = NULL, envir = NULL, ... )ide( Y, transf = list(), order.polreg = 0, lag.max = NULL, lags.at = NULL, freq.at = NULL, wn.bands = TRUE, graphs = c("plot", "acf", "pacf"), set.layout = TRUE, byrow = TRUE, main = "", plot.abline.args = NULL, plot.points.args = NULL, envir = NULL, ... )
Y |
Univariate or multivariate time series. |
transf |
Data transformations, list(bc = F, d = 0, D = 0, S = F), where bc is the Box-Cox logarithmic transformation, d and D are the number of nonseasonal and seasonal differences, and S is the annual sum operator. |
order.polreg |
an integer indicating the order of a polynomial trend. |
lag.max |
number of autocorrelations. |
lags.at |
the lags of the ACF/PACF at which tick-marks are to be drawn. |
freq.at |
the frequencies of the (cum) periodogram at at which tick-marks are to be drawn. |
wn.bands |
logical. If TRUE confidence intervals for sample autocorrelations are computed assuming a white noise series. |
graphs |
graphs to be shown: plot, hist, acf, pacf, pgram, cpgram (cummulative periodogram), rm (range-median). |
set.layout |
logical. If TRUE the layout is set by the function, otherwise it is set by the user. |
byrow |
logical. If TRUE the layout is filled by rows, otherwise it is filled by columns. |
main |
title of the graph. |
plot.abline.args |
Add straight lines to time series plot. |
plot.points.args |
Add points to time series plot. |
envir |
environment in which the function arguments are evaluated. If NULL the calling environment of this function will be used. |
... |
additional arguments. |
Y <- AirPassengers ide(Y, graphs = c("plot", "rm")) ide(Y, transf = list(list(bc = TRUE, S = TRUE), list(bc = TRUE, d = 1, D = 1)))Y <- AirPassengers ide(Y, graphs = c("plot", "rm")) ide(Y, transf = list(list(bc = TRUE, S = TRUE), list(bc = TRUE, d = 1, D = 1)))
init_kf computes the starting values x0 and P0 by generalized least
squares using the first n observations.
init_kf(mdl, z = NULL, n = 0)init_kf(mdl, z = NULL, n = 0)
mdl |
an object of class |
z |
optional time series if it differs from model series. |
n |
integer, number of observations used to estimate the initial conditions. If n < d (dimension of state vector), it defaults to length(z). |
A list with components:
x0 |
initial state vector estimate |
P0 |
covariance matrix of the initial state estimate |
intervention estimates the effect of a intervention at a known time.
## S3 method for class 'tfm' intervention( mdl, y = NULL, type, time, n.ahead = 0, envir = parent.frame(), ... ) intervention(mdl, ...) ## S3 method for class 'um' intervention( mdl, y = NULL, type, time, n.ahead = 0, envir = parent.frame(), ... )## S3 method for class 'tfm' intervention( mdl, y = NULL, type, time, n.ahead = 0, envir = parent.frame(), ... ) intervention(mdl, ...) ## S3 method for class 'um' intervention( mdl, y = NULL, type, time, n.ahead = 0, envir = parent.frame(), ... )
mdl |
|
y |
a "ts" object, optional. |
type |
the type intervention (pulse, step, ramp) or the type of outlier (AO, LS, TC, IO). |
time |
the date of the intervention, in format c(year, season). |
n.ahead |
a positive integer to extend the sample period of the
intervention variable with |
envir |
the environment in which to look for the time series z when it is passed as a character string. |
... |
additional arguments. |
an object of class "tfm" or a table.
'InterventionVar()' creates pulse, step, or ramp variables at a given date.
InterventionVar(Y, date, type = c("P", "S", "R"), n.ahead = 0)InterventionVar(Y, date, type = c("P", "S", "R"), n.ahead = 0)
Y |
A 'ts' object used to determine start, length and frequency. |
date |
Either a single positive index within the sample, or a vector 'c(year, month)' for monthly series. For non-seasonal series, 'c(year)' is also accepted. |
type |
One of '"P"' (pulse), '"S"' (step), or '"R"' (ramp = cumulative step). |
n.ahead |
Integer. Extra observations to extend the sample. |
A 'ts' intervention variable.
Box, G.E.P. and Tiao, G.C. (1975) “Intervention analysis with applications to economic and environmental problems”, *JASA*, 70(349), 70–79.
# Pulse at March 1958: P <- InterventionVar(AirPassengers, date = c(1958, 3), type = "P") # Or by index within the extended sample (here no extension): P2 <- InterventionVar(AirPassengers, date = 123, type = "P")# Pulse at March 1958: P <- InterventionVar(AirPassengers, date = c(1958, 3), type = "P") # Or by index within the extended sample (here no extension): P2 <- InterventionVar(AirPassengers, date = 123, type = "P")
inv inverts a lag polynomial until the indicated lag.
inv(lp, ...) ## S3 method for class 'lagpol' inv(lp, lag.max = 10, ...)inv(lp, ...) ## S3 method for class 'lagpol' inv(lp, lag.max = 10, ...)
lp |
an object of class |
... |
additional arguments. |
lag.max |
largest order of the inverse lag polynomial. |
inv returns a numeric vector with the coefficients
of the inverse lag polynomial truncated at lag.max.
inv(as.lagpol(c(1, 1.2, -0.8)))inv(as.lagpol(c(1, 1.2, -0.8)))
Computes and plots the impulse response function (IRF) or step response function (SRF) of a transfer function.
irf(tf, lag.max = 10, cum = FALSE, plot = TRUE)irf(tf, lag.max = 10, cum = FALSE, plot = TRUE)
tf |
An object of class "tf". |
lag.max |
Integer. Maximum number of lags to compute (default 10). |
cum |
Logical. If TRUE computes step response function (cumulative), if FALSE computes impulse response function (default FALSE). |
plot |
Logical. If TRUE creates a plot, if FALSE returns values only (default TRUE). |
If plot = FALSE, a named numeric vector with IRF/SRF values.
If plot = TRUE, creates a plot and returns nothing (invisibly).
# Create transfer function x <- rep(0, 100); x[50] <- 1 tfx <- tf(x, w0 = 0.8, ar = "(1 - 0.5B)") # Plot impulse response function irf(tfx, lag.max = 15) # Get step response values without plot srf_values <- irf(tfx, lag.max = 10, cum = TRUE, plot = FALSE)# Create transfer function x <- rep(0, 100); x[50] <- 1 tfx <- tf(x, w0 = 0.8, ar = "(1 - 0.5B)") # Plot impulse response function irf(tfx, lag.max = 15) # Get step response values without plot srf_values <- irf(tfx, lag.max = 10, cum = TRUE, plot = FALSE)
kf computes the innovations and the conditional states with the Kalman
filter algorithm.
kf(mdl, z = NULL, x0 = NULL, P0 = NULL, filtered = FALSE, ...)kf(mdl, z = NULL, x0 = NULL, P0 = NULL, filtered = FALSE, ...)
mdl |
an object of class |
z |
time series to be filtered when it differs from the model series. |
x0 |
initial state vector. |
P0 |
covariance matrix of x1. |
filtered |
logical. If TRUE, the filtered states x_{t|t} and their covariance matrices P_{t|t} are returned. Otherwise, the forecasted states x_{t|t-1} and thier covariance matrices P_{t|t-1} are returned. |
... |
additional arguments. |
A list with the innovations, the conditional states and their covariance matrices.
ks computes smoothed states and their covariance matrices.
ks(mdl, x0 = NULL, P0 = NULL)ks(mdl, x0 = NULL, P0 = NULL)
mdl |
an object of class |
x0 |
initial state vector. |
P0 |
covariance matrix of x0. |
lagpol creates a lag polynomial of the form:
This class of lag polynomials is defined by:
the base lag polynomial ,
the exponent 'p' of the base lag polynomial (default is 'p = 1'),
the spacing parameter 's' in sparse lag polynomials (default is 's = 1'),
the vector of 'd' coefficients 'c(coef_1, ..., coef_d)', which can be mathematical expresions dependent on 'k' parameters 'c(param_1, ..., param_k)'.
lagpol(param = NULL, s = 1, p = 1, lags = NULL, coef = NULL)lagpol(param = NULL, s = 1, p = 1, lags = NULL, coef = NULL)
param |
a vector/list of named parameters. These parameters can be used within the coefficient expressions. |
s |
an integer specifying the lag spacing or seasonal period. |
p |
an integer specifying the exponent applied to the base lag polynomial. |
lags |
an optional vector of lags for sparse polynomials. If |
coef |
an optional vector of mathematical expressions defining the
coefficients of the lag polynomial. If |
lagpol An object of class 'lagpol' with the following
components:
coefvector of coefficients c(coef_1, ..., coef_p) provided to create the lag polynomial.
polbase lag polynomial vector:
.
Pollag polynomial raised to the power 'p'. If 'p = 1', this equals 'pol'.
# Simple AR(1) lag polynomial: 1 - 0.8B lagpol(param = c(phi = 0.8)) # AR(2) lag polynomial with seasonal lag s = 4: 1 - 1.2B^4 + 0.6B^8 lagpol(param = c(phi1 = 1.2, phi2 = -0.6), s = 4) # Integration operator squared: (1 - B)^2 = 1 - 2B + B^2 lagpol(param = c(delta = 1), p = 2) # Lag polynomial using explicit coefficients lagpol(coef = c("1"), p = 2) # (1 - B)^2 = 1 - 2B + B^2 # Custom coefficients defined by mathematical expressions lagpol(param = c(theta = 0.8), coef = c("2*cos(pi/6)*sqrt(theta)", "-theta"))# Simple AR(1) lag polynomial: 1 - 0.8B lagpol(param = c(phi = 0.8)) # AR(2) lag polynomial with seasonal lag s = 4: 1 - 1.2B^4 + 0.6B^8 lagpol(param = c(phi1 = 1.2, phi2 = -0.6), s = 4) # Integration operator squared: (1 - B)^2 = 1 - 2B + B^2 lagpol(param = c(delta = 1), p = 2) # Lag polynomial using explicit coefficients lagpol(coef = c("1"), p = 2) # (1 - B)^2 = 1 - 2B + B^2 # Custom coefficients defined by mathematical expressions lagpol(param = c(theta = 0.8), coef = c("2*cos(pi/6)*sqrt(theta)", "-theta"))
'lagpol0' is a flexible constructor for lagpol objects.
It accepts multiple input formats: polynomial orders ,
literal equations (e.g., ), or seasonal specifications for
special lag polynomials like .
lagpol0(op, type, envir = parent.frame())lagpol0(op, type, envir = parent.frame())
op |
Polynomial specification in one of these formats:
|
type |
Operator type: |
envir |
Environment for argument evaluation. Defaults to parent frame. |
List of lagpol objects.
# AR(1) polynomial lagpol0(op = 1, type = "ar") # From literal equation lagpol0(op = "1 - 0.8B", type = "ar") # Multiple polynomials at once lagpol0(op = list(1, "1 - 0.5B"), type = "ma") # Seasonal polynomial lagpol0(op = "12", type = "ar") # Custom orders with seasonal component lagpol0(op = c(2, 12, 1), type = "ar")# AR(1) polynomial lagpol0(op = 1, type = "ar") # From literal equation lagpol0(op = "1 - 0.8B", type = "ar") # Multiple polynomials at once lagpol0(op = list(1, "1 - 0.5B"), type = "ma") # Seasonal polynomial lagpol0(op = "12", type = "ar") # Custom orders with seasonal component lagpol0(op = c(2, 12, 1), type = "ar")
logLik.ssm computes the exact or conditional log-likelihood of a state
space model.
## S3 method for class 'ssm' logLik(object, method = c("exact", "cond"), ...)## S3 method for class 'ssm' logLik(object, method = c("exact", "cond"), ...)
object |
an object of class |
method |
character. Either "exact" or "conditional" maximum likelihood. |
... |
additional parameters. |
The log-likelihood value.
# Local level model b <- 1 C <- as.matrix(1) ssm1 <- ssm(Nile, b, C, S = diag(c(irr = 15127.7, lvl = 1453.2))) logLik(ssm1)# Local level model b <- 1 C <- as.matrix(1) ssm1 <- ssm(Nile, b, C, S = diag(c(irr = 15127.7, lvl = 1453.2))) logLik(ssm1)
Computes the log-likelihood for a fitted transfer function model.
## S3 method for class 'tfm' logLik( object, y = NULL, method = c("exact", "cond"), envir = parent.frame(), ... )## S3 method for class 'tfm' logLik( object, y = NULL, method = c("exact", "cond"), envir = parent.frame(), ... )
object |
A fitted |
y |
Optional |
method |
Character: "exact" estimates presample values; "cond" fixes presample values at zero. |
envir |
Environment for evaluation. |
... |
Additional arguments (currently unused). |
Numeric value of the log-likelihood.
logLik computes the exact or conditional log-likelihood of object of
the class um.
## S3 method for class 'um' logLik(object, z = NULL, method = c("exact", "cond"), ...)## S3 method for class 'um' logLik(object, z = NULL, method = c("exact", "cond"), ...)
object |
an object of class |
z |
an object of class |
method |
exact or conditional. |
... |
additional arguments. |
The exact or conditional log-likelihood.
modify modifies an object of class um or tfm
by adding and/or removing lag polynomials.
## S3 method for class 'tfm' modify( mdl, ar = NULL, i = NULL, ma = NULL, mu = NULL, sig2 = NULL, bc = NULL, ... ) modify(mdl, ...) ## S3 method for class 'um' modify( mdl, ar = NULL, i = NULL, ma = NULL, mu = NULL, sig2 = NULL, bc = NULL, ... )## S3 method for class 'tfm' modify( mdl, ar = NULL, i = NULL, ma = NULL, mu = NULL, sig2 = NULL, bc = NULL, ... ) modify(mdl, ...) ## S3 method for class 'um' modify( mdl, ar = NULL, i = NULL, ma = NULL, mu = NULL, sig2 = NULL, bc = NULL, ... )
mdl |
an object of class |
ar |
list of stationary AR lag polynomials. |
i |
list of nonstationary AR (I) polynomials. |
ma |
list of MA polynomials. |
mu |
mean of the stationary time series. |
sig2 |
variance of the error. |
bc |
logical. If TRUE logs are taken. |
... |
additional arguments. |
An object of class um or um.
um1 <- um(ar = "(1 - 0.8B)") um2 <- modify(um1, ar = list(0, "(1 - 0.9B)"), ma = "(1 - 0.5B)")um1 <- um(ar = "(1 - 0.8B)") um2 <- modify(um1, ar = list(0, "(1 - 0.9B)"), ma = "(1 - 0.5B)")
nabla multiplies the I polynomials of an object of
the um class.
## S3 method for class 'ucarima' nabla(x, i = NULL, lp = TRUE, ...) nabla(x, ...) ## S3 method for class 'um' nabla(x, ...)## S3 method for class 'ucarima' nabla(x, i = NULL, lp = TRUE, ...) nabla(x, ...) ## S3 method for class 'um' nabla(x, ...)
x |
an object of class |
i |
integer. Omit this component model. |
lp |
logical indicating the type of return: |
... |
additional arguments. |
A numeric vector c(1, a1, ..., ad)
This function returns the member variable um$nabla.
um1 <- um(i = "(1 - B)(1 - B^12)") nabla(um1)um1 <- um(i = "(1 - B)(1 - B^12)") nabla(um1)
Computes the noise series (output minus fitted signal) from a transfer function model.
## S3 method for class 'ssm' noise(mdl, diff = TRUE, exp = FALSE, ...) noise(mdl, ...) ## S3 method for class 'tfm' noise(mdl, y = NULL, diff = TRUE, exp = FALSE, envir = parent.frame(), ...)## S3 method for class 'ssm' noise(mdl, diff = TRUE, exp = FALSE, ...) noise(mdl, ...) ## S3 method for class 'tfm' noise(mdl, y = NULL, diff = TRUE, exp = FALSE, envir = parent.frame(), ...)
mdl |
A |
diff |
Logical. If TRUE (default), returns differenced noise series (stationary). If FALSE, returns noise in original scale. |
exp |
Logical. If TRUE, applies exponential transformation (inverse
of log). Only relevant when |
... |
Additional arguments. |
y |
Optional |
envir |
Environment for evaluation. NULL uses calling environment. |
The noise represents the component of the output not explained by the
transfer functions and exogenous regressors. When diff = TRUE,
the differencing operator from the noise model is applied, resulting in
a stationary series suitable for ARMA modeling.
A ts object containing the noise series, computed as
output minus all transfer function and regressor effects.
signal.tfm, residuals.tfm, tfm
outlierDates shows the indeces and dates of outliers.
outlierDates(x, c = 3)outlierDates(x, c = 3)
x |
an |
c |
critical value to determine whether or not an observation is an outlier. |
A table with the indices, dates and z-scores of the outliers.
outliers performs a detection of four types of anomalies (AO, TC, LS
and IO) in a time series described by an ARIMA model. If the dates of the
outliers are unknown, an iterative detection process like that proposed by
Chen and Liu (1993) is conducted.
## S3 method for class 'ssm' outliers( mdl, types = c("AO", "LS", "TC"), dates = NULL, c = 3, calendar = FALSE, easter = FALSE, resid = c("exact", "cond"), n.ahead = 0, p.value = 1, ... ) ## S3 method for class 'tfm' outliers( mdl, y = NULL, types = c("AO", "LS", "TC", "IO"), dates = NULL, c = 3, calendar = FALSE, easter = FALSE, resid = c("exact", "cond"), n.ahead = 0, p.value = 1, tc.fix = TRUE, envir = parent.frame(), ... ) ## S3 method for class 'ucarima' outliers( mdl, types = c("AO", "LS", "TC"), dates = NULL, c = 3, calendar = FALSE, easter = FALSE, resid = c("exact", "cond"), n.ahead = 0, p.value = 1, ... ) outliers(mdl, ...) ## S3 method for class 'um' outliers( mdl, y = NULL, types = c("AO", "LS", "TC", "IO"), dates = NULL, c = 3, calendar = FALSE, easter = FALSE, resid = c("exact", "cond"), n.ahead = 0, p.value = 1, tc.fix = TRUE, envir = NULL, ... )## S3 method for class 'ssm' outliers( mdl, types = c("AO", "LS", "TC"), dates = NULL, c = 3, calendar = FALSE, easter = FALSE, resid = c("exact", "cond"), n.ahead = 0, p.value = 1, ... ) ## S3 method for class 'tfm' outliers( mdl, y = NULL, types = c("AO", "LS", "TC", "IO"), dates = NULL, c = 3, calendar = FALSE, easter = FALSE, resid = c("exact", "cond"), n.ahead = 0, p.value = 1, tc.fix = TRUE, envir = parent.frame(), ... ) ## S3 method for class 'ucarima' outliers( mdl, types = c("AO", "LS", "TC"), dates = NULL, c = 3, calendar = FALSE, easter = FALSE, resid = c("exact", "cond"), n.ahead = 0, p.value = 1, ... ) outliers(mdl, ...) ## S3 method for class 'um' outliers( mdl, y = NULL, types = c("AO", "LS", "TC", "IO"), dates = NULL, c = 3, calendar = FALSE, easter = FALSE, resid = c("exact", "cond"), n.ahead = 0, p.value = 1, tc.fix = TRUE, envir = NULL, ... )
mdl |
|
types |
a vector with the initials of the outliers to be detected, c("AO", "LS", "TC", "IO"). |
dates |
a list of dates c(year, season). If |
c |
a positive constant to compare the z-ratio of the effect of an
observation and decide whether or not it is an outlier. This argument is
only used when |
calendar |
logical; if true, calendar effects are also estimated. |
easter |
logical; if true, Easter effect is also estimated. |
resid |
type of residuals (exact or conditional) used to identify outliers. |
n.ahead |
a positive integer to extend the sample period of the
intervention variables with |
p.value |
estimates with a p-value greater than p.value are omitted. |
... |
other arguments. |
y |
an object of class |
tc.fix |
a logical value indicating if the AR coefficient in the transfer function of the TC is estimated or fix. |
envir |
environment in which the function arguments are evaluated. If NULL the calling environment of this function will be used. |
an object of class "tfm" or a table.
data(rsales) um1 <- um(rsales, i = list(1, c(1, 12)), ma = list(1, c(1, 12)), bc = TRUE) outliers(um1)data(rsales) um1 <- um(rsales, i = list(1, c(1, 12)), ma = list(1, c(1, 12)), bc = TRUE) outliers(um1)
output filters the input using the transfer function.
output(object, ...) ## S3 method for class 'tf' output(object, ...)output(object, ...) ## S3 method for class 'tf' output(object, ...)
object |
an object of the S3 class "tf". |
... |
additional arguments. |
A "ts" object
pccf displays cross correlation function between input and output
after prewhitening both through a univariate model.
pccf( x, y, um.x = NULL, um.y = NULL, lag.max = NULL, plot = TRUE, envir = NULL, main = NULL, nu.weights = FALSE, ... )pccf( x, y, um.x = NULL, um.y = NULL, lag.max = NULL, plot = TRUE, envir = NULL, main = NULL, nu.weights = FALSE, ... )
x |
input, a 'ts' object or a numeric vector. |
y |
output, a 'ts' object or a numeric vector. |
um.x |
univariate model for input. |
um.y |
univariate model for output. |
lag.max |
number of lags, integer. |
plot |
logical value to indicate if the ccf graph must be graphed or computed. |
envir |
environment in which the function arguments are evaluated. If NULL the calling environment of this function will be used. |
main |
title of the graph. |
nu.weights |
logical. If TRUE the coefficients of the IRF are computed instead of the cross-correlations. |
... |
additional arguments. |
The estimated cross correlations are displayed in a graph or returned into a numeric vector.
phi multiplies the AR polynomials of an object of
the um class.
## S3 method for class 'ucarima' phi(x, i = NULL, ar = TRUE, lp = TRUE, ...) phi(x, ...) ## S3 method for class 'um' phi(x, ...)## S3 method for class 'ucarima' phi(x, i = NULL, ar = TRUE, lp = TRUE, ...) phi(x, ...) ## S3 method for class 'um' phi(x, ...)
x |
an object of class |
i |
integer. Omit this component model. |
ar |
logical. If TRUE, the common AR polynomial is included. |
lp |
logical indicating the type of return: |
... |
additional arguments. |
A numeric vector c(1, a1, ..., ad)
This function returns the member variable um$phi.
um1 <- um(ar = "(1 - 0.8B)(1 - 0.5B)") phi(um1)um1 <- um(ar = "(1 - 0.8B)(1 - 0.5B)") phi(um1)
pi.weights computes the pi-weights of an AR(I)MA model.
pi.weights(um, ...) ## S3 method for class 'um' pi.weights(um, lag.max = 10, var.pi = FALSE, ...)pi.weights(um, ...) ## S3 method for class 'um' pi.weights(um, lag.max = 10, var.pi = FALSE, ...)
um |
an object of class |
... |
additional arguments. |
lag.max |
largest AR(Inf) coefficient required. |
var.pi |
logical. If TRUE (FALSE), the I polynomials is considered (ignored). |
A numeric vector.
um1 <- um(i = "(1 - B)(1 - B^12)", ma = "(1 - 0.8B)(1 - 0.8B^12)") pi.weights(um1, var.pi = TRUE)um1 <- um(i = "(1 - B)(1 - B^12)", ma = "(1 - 0.8B)(1 - 0.8B^12)") pi.weights(um1, var.pi = TRUE)
Evaluate the k-th derivative of a polynomial at point z
polyderivEvalR(pol, z, k = 0)polyderivEvalR(pol, z, k = 0)
pol |
Numeric vector of polynomial coefficients in ascending order (pol[1] = constant term, pol[2] = coefficient of z, etc.) |
z |
Numeric value where the polynomial (or its derivative) is evaluated. |
k |
Integer. Derivative order (0 = original polynomial). |
Numeric value of the k-th derivative of P(z).
pol <- c(1, 2, 3, 4) # P(z) = 1 + 2z + 3z² + 4z³ polyderivEvalR(pol, 2, 0) # 49 polyderivEvalR(pol, 2, 1) # 62pol <- c(1, 2, 3, 4) # P(z) = 1 + 2z + 3z² + 4z³ polyderivEvalR(pol, 2, 0) # 49 polyderivEvalR(pol, 2, 1) # 62
predict.ssm generates forecasts from fitted state space models by
converting to univariate ARIMA or transfer function models and using their
prediction methods.
## S3 method for class 'ssm' predict(object, ...)## S3 method for class 'ssm' predict(object, ...)
object |
an object of class |
... |
additional arguments passed to |
An object of class predict.um or predict.tfm.
Predict transfer function
## S3 method for class 'tf' predict(object, n.ahead, ...)## S3 method for class 'tf' predict(object, n.ahead, ...)
object |
Transfer function object. |
n.ahead |
Periods to predict. |
... |
Unused. |
Point forecast for input.
Computes point forecasts and prediction intervals for transfer function models.
## S3 method for class 'tfm' predict( object, newdata = NULL, y = NULL, ori = NULL, n.ahead = NULL, level = 0.95, i = NULL, envir = NULL, ... )## S3 method for class 'tfm' predict( object, newdata = NULL, y = NULL, ori = NULL, n.ahead = NULL, level = 0.95, i = NULL, envir = NULL, ... )
object |
A fitted |
newdata |
Optional matrix or vector of future values for exogenous regressors and inputs. Rows correspond to forecast horizon, columns to predictors. |
y |
Optional |
ori |
Forecast origin (observation index). Default is last observation. |
n.ahead |
Number of steps ahead to forecast. Default is series frequency. |
level |
Confidence level(s) for prediction intervals (0-1). Default is 0.95. Can be a vector for multiple intervals. |
i |
Optional differencing operator (lagpol) to apply before forecasting. |
envir |
Environment for evaluation. NULL uses calling environment. |
... |
Additional arguments (currently unused). |
Future values for transfer function inputs can be provided in three ways:
(1) extending input series beyond output length, (2) automatic forecasting
from associated um models, or (3) via the newdata argument.
If Box-Cox transformation was used, forecasts are back-transformed and intervals adjusted accordingly.
Object of class predict.tfm containing:
z |
Complete series including forecasts |
rmse |
Root mean square error for each forecast |
low, upp
|
Lower and upper prediction interval bounds (matrices) |
level |
Confidence level(s) used |
dates |
Time points for all observations |
ori, ori.date
|
Forecast origin (index and date) |
n.ahead |
Number of forecasts |
predict computes point and interval predictions for a time series
from models of class um.
## S3 method for class 'um' predict( object, z = NULL, ori = NULL, n.ahead = 1, level = 0.95, i = NULL, envir = NULL, ... )## S3 method for class 'um' predict( object, z = NULL, ori = NULL, n.ahead = 1, level = 0.95, i = NULL, envir = NULL, ... )
object |
an object of class |
z |
an object of class |
ori |
the origin of prediction. By default, it is the last observation. |
n.ahead |
number of steps ahead. |
level |
confidence level. |
i |
transformation of the series |
envir |
environment in which the function arguments are evaluated. If NULL the calling environment of this function will be used. |
... |
additional arguments. |
An object of class "predict.um".
Z <- AirPassengers um1 <- um(Z, i = list(1, c(1, 12)), ma = list(1, c(1, 12)), bc = TRUE) p <- predict(um1, n.ahead = 12) p plot(p, n.back = 60)Z <- AirPassengers um1 <- um(Z, i = list(1, c(1, 12)), ma = list(1, c(1, 12)), bc = TRUE) p <- predict(um1, n.ahead = 12) p plot(p, n.back = 60)
Prints objects of class lagpol.
## S3 method for class 'lagpol' print(x, digits = 2, width = getOption("width"), ...)## S3 method for class 'lagpol' print(x, digits = 2, width = getOption("width"), ...)
x |
An object of class |
digits |
Integer. Number of significant digits to display. Default is 2. |
width |
Integer. Maximum number of characters per line. Default is the console width. |
... |
Additional arguments (currently unused). |
Invisibly returns the lagpol object.
ssm objectsPrint method for ssm objects
## S3 method for class 'ssm' print(x, ...)## S3 method for class 'ssm' print(x, ...)
x |
an object of class |
... |
further arguments passed to or from other methods. |
Invisibly returns NULL.
print.summary.ssm prints a detailed summary of the results of the
estimation of a ssm object.
## S3 method for class 'summary.ssm' print(x, stats = TRUE, digits = max(3L, getOption("digits") - 3L), ...)## S3 method for class 'summary.ssm' print(x, stats = TRUE, digits = max(3L, getOption("digits") - 3L), ...)
x |
an object of class |
stats |
logical. If |
digits |
integer. Number of significant digits to display for numeric values. |
... |
additional arguments. |
Invisible NULL.
Print method for objects of class summary.tfm.
## S3 method for class 'summary.tfm' print( x, stats = TRUE, short = FALSE, digits = max(3L, getOption("digits") - 3L), ... )## S3 method for class 'summary.tfm' print( x, stats = TRUE, short = FALSE, digits = max(3L, getOption("digits") - 3L), ... )
x |
A |
stats |
Logical. If TRUE, prints diagnostic statistics. |
short |
Logical. If TRUE, prints abbreviated output. |
digits |
Number of significant digits. |
... |
Additional arguments. |
Print method for objects of class summary.um.
## S3 method for class 'summary.um' print( x, stats = TRUE, short = FALSE, digits = max(3L, getOption("digits") - 3L), ... )## S3 method for class 'summary.um' print( x, stats = TRUE, short = FALSE, digits = max(3L, getOption("digits") - 3L), ... )
x |
A |
stats |
Logical. If TRUE, prints diagnostic statistics. |
short |
Logical. If TRUE, prints abbreviated output. |
digits |
Number of significant digits. |
... |
Additional arguments. |
Print method for transfer function objects
Print ucarima models
Print univariate models
Print univariate models
## S3 method for class 'tf' print(x, ...) ## S3 method for class 'ucarima' print(x, ...) ## S3 method for class 'predict.um' print(x, rows = NULL, ...) ## S3 method for class 'um' print(x, arima = FALSE, ...)## S3 method for class 'tf' print(x, ...) ## S3 method for class 'ucarima' print(x, ...) ## S3 method for class 'predict.um' print(x, rows = NULL, ...) ## S3 method for class 'um' print(x, arima = FALSE, ...)
x |
An object of class um. |
... |
Additional arguments. |
rows |
integer. Number of rows printed. |
arima |
logical. If TRUE, lag ARIMA polynomials are printed. |
Print method for objects of class tfm.
## S3 method for class 'tfm' print(x, ...)## S3 method for class 'tfm' print(x, ...)
x |
A |
... |
Additional arguments passed to |
Prints a summary of the transfer function model by calling
summary(x) with short = TRUE.
Print method for unobserved components
## S3 method for class 'uc' print(x, ...)## S3 method for class 'uc' print(x, ...)
x |
an object of class |
... |
currently unused. |
Invisibly returns NULL.
Prints a non-normalized polynomial as a lagpol object, preserving the
original coefficients.
printLagpol(pol, digits = 2, width = getOption("width"))printLagpol(pol, digits = 2, width = getOption("width"))
pol |
Numeric vector with the coefficients of a non-normalized polynomial. The first element can be any numeric value, not necessarily 1. |
digits |
Integer. Number of significant digits to display. Default is 2. |
width |
Integer. Maximum number of characters per line. Default is the console width. |
Invisibly returns the input vector.
lagpol objects.Prints a list of lagpol objects.
printLagpolList(llp, digits = 2, width = getOption("width"))printLagpolList(llp, digits = 2, width = getOption("width"))
llp |
A list of |
digits |
Integer. Number of significant digits to display. Default is 2. |
width |
Integer. Maximum number of characters per line. Default is the console width. |
Invisibly returns the list of lagpol objects.
psi computes the psi-weights of an AR(I)MA model.
psi.weights(um, ...) ## S3 method for class 'um' psi.weights(um, lag.max = 10, var.psi = FALSE, ...)psi.weights(um, ...) ## S3 method for class 'um' psi.weights(um, lag.max = 10, var.psi = FALSE, ...)
um |
an object of class |
... |
additional arguments. |
lag.max |
Largest MA(Inf) coefficient required. |
var.psi |
logical. If TRUE the I polynomials is also inverted. If FALSE it is ignored. |
A numeric vector.
um1 <- um(i = "(1 - B)(1 - B^12)", ma = "(1 - 0.8B)(1 - 0.8B^12)") psi.weights(um1) psi.weights(um1, var.psi = TRUE)um1 <- um(i = "(1 - B)(1 - B^12)", ma = "(1 - 0.8B)(1 - 0.8B^12)") psi.weights(um1) psi.weights(um1, var.psi = TRUE)
residuals.ssm generates the residuals of a fitted ssm
object.
## S3 method for class 'ssm' residuals(object, method = c("exact", "cond"), ...)## S3 method for class 'ssm' residuals(object, method = c("exact", "cond"), ...)
object |
an object of class |
method |
character. Either "exact" or "conditional" residuals. |
... |
additional arguments. |
These residuals are calculated by first converting the
ssm object to a um object and then using the
residuals.um function.
A ts object containing the residuals of the SSM.
# Local level model b <- 1 C <- as.matrix(1) ssm1 <- ssm(Nile, b, C, S = diag(c(irr = 15127.7, lvl = 1453.2))) u <-residuals(ssm1)# Local level model b <- 1 C <- as.matrix(1) ssm1 <- ssm(Nile, b, C, S = diag(c(irr = 15127.7, lvl = 1453.2))) u <-residuals(ssm1)
Computes exact or conditional residuals from a fitted transfer function model.
## S3 method for class 'tfm' residuals( object, y = NULL, method = c("exact", "cond"), envir = parent.frame(), ... )## S3 method for class 'tfm' residuals( object, y = NULL, method = c("exact", "cond"), envir = parent.frame(), ... )
object |
A fitted |
y |
Optional |
method |
Character: "exact" estimates presample values to compute residuals; "cond" fixes presample values at zero. |
envir |
Environment for evaluation. NULL uses calling environment. |
... |
Currently unused. |
A ts object containing model residuals with the same
time series attributes as the output series.
residuals.ucarima generates the residuals of a fitted ucarima
object.
## S3 method for class 'ucarima' residuals(object, method = c("exact", "cond"), ...)## S3 method for class 'ucarima' residuals(object, method = c("exact", "cond"), ...)
object |
an object of class |
method |
character. Either "exact" or "conditional" residuals. |
... |
additional arguments. |
These residuals are calculated by first converting the
ucarima object to a um object and then using the
residuals.um function.
A ts object containing the residuals of the SSM.
residuals computes the exact or conditional residuals.
## S3 method for class 'um' residuals(object, z = NULL, method = c("exact", "cond"), envir = NULL, ...)## S3 method for class 'um' residuals(object, z = NULL, method = c("exact", "cond"), envir = NULL, ...)
object |
an object of class |
z |
an object of class |
method |
exact/conditional residuals. |
envir |
environment in which the function arguments are evaluated. If NULL the calling environment of this function will be used. |
... |
additional arguments. |
An object of class um.
z <- AirPassengers airl <- um(z, i = list(1, c(1, 12)), ma = list(1, c(1, 12)), bc = TRUE) r <- residuals(airl) summary(r)z <- AirPassengers airl <- um(z, i = list(1, c(1, 12)), ma = list(1, c(1, 12)), bc = TRUE) r <- residuals(airl) summary(r)
roots computes the roots of lag polynomials from polynomial objects and
time series models that contain lag polynomials as components.
roots(x, ...) ## Default S3 method: roots(x, ...) ## S3 method for class 'lagpol' roots(x, table = TRUE, tol = 1e-05, ...) ## S3 method for class 'tf' roots(x, opr = c("arma", "ar", "ma"), ...) ## S3 method for class 'um' roots(x, opr = c("arma", "ar", "ma", "i", "arima"), ...)roots(x, ...) ## Default S3 method: roots(x, ...) ## S3 method for class 'lagpol' roots(x, table = TRUE, tol = 1e-05, ...) ## S3 method for class 'tf' roots(x, opr = c("arma", "ar", "ma"), ...) ## S3 method for class 'um' roots(x, opr = c("arma", "ar", "ma", "i", "arima"), ...)
x |
A model object containing lag polynomials ("um", "tfm") or a lag polynomial object ("lagpol"). |
... |
Additional arguments passed to methods. |
table |
Logical. If TRUE returns detailed table, if FALSE complex vector. |
tol |
Tolerance for identifying distinct roots. |
opr |
character. Operators for which roots are computed. Options: "arma", "arma", "ar", "ma", "i" or "arima". |
Returns a summary table with the roots of each lagpol.
roots(c(1, 1.2, -0.8)) um1 <- um(ar = "(1 - 0.8B)(1 - 0.8B^12)") roots(um1)roots(c(1, 1.2, -0.8)) um1 <- um(ar = "(1 - 0.8B)(1 - 0.8B^12)") roots(um1)
roots2lagpol creates a lag polynomial from its roots.
roots2lagpol(x, lp = TRUE, ...)roots2lagpol(x, lp = TRUE, ...)
x |
a vector of real and/or complex roots. |
lp |
logical. If TRUE, a object of class |
... |
additional arguments. |
A lag polynomial or a numeric vector.
roots2lagpol(polyroot(c(1, -1))) roots2lagpol(polyroot(c(1, -1, 1)))roots2lagpol(polyroot(c(1, -1))) roots2lagpol(polyroot(c(1, -1, 1)))
156 monthly observations from January 1967 to December 1979.
rsalesrsales
An object of class ts of length 156.
Chen, C. and Liu, L. (1993) Joint Estimation of Model Parameters and Outlier Effects in Time Series, Journal of the American Statistical Association, Vol. 88, No. 421, pp. 284-297
Computes rolling sum over one year for monthly/quarterly data.
S(x, extend = TRUE)S(x, extend = TRUE)
x |
A |
extend |
If TRUE, pads result with NAs to match original length. Default is TRUE. |
Time series of annual sums with same frequency as input.
'sdummies()' creates a full set of seasonal dummies (reference-coded).
sdummies(Y, ref = 1, constant = FALSE, n.ahead = 0)sdummies(Y, ref = 1, constant = FALSE, n.ahead = 0)
Y |
A seasonal 'ts' object. |
ref |
Reference season (1..frequency). |
constant |
Logical. If 'TRUE', include an intercept column. |
n.ahead |
Integer. Extra observations to extend the sample. |
A 'ts' matrix with seasonal dummies (and intercept if requested).
D <- sdummies(AirPassengers, ref = 1, constant = TRUE, n.ahead = 24)D <- sdummies(AirPassengers, ref = 1, constant = TRUE, n.ahead = 24)
seasadj removes the seasonal component of time series.
seasadj(mdl, ...) ## S3 method for class 'um' seasadj( mdl, z = NULL, method = c("ucarima", "ucarima0", "ssm", "ssm0", "mixed", "forecast", "backcast"), envir = parent.frame(), ... )seasadj(mdl, ...) ## S3 method for class 'um' seasadj( mdl, z = NULL, method = c("ucarima", "ucarima0", "ssm", "ssm0", "mixed", "forecast", "backcast"), envir = parent.frame(), ... )
mdl |
An object of class |
... |
Additional arguments passed to internal methods. |
z |
an object of class |
method |
Character string specifying the decomposition method. Options are:
|
envir |
environment in which the function arguments are evaluated. If NULL the calling environment of this function will be used. |
seasadj returns a seasonal adjusted time series.
Y <- AirPassengers um1 <- um(Y, bc = TRUE, i = list(1, c(1,12)), ma = list(1, c(1,12))) Y <- seasadj(um1) ide(Y)Y <- AirPassengers um1 <- um(Y, bc = TRUE, i = list(1, c(1,12)), ma = list(1, c(1,12))) Y <- seasadj(um1) ide(Y)
226 observations.
seriesCseriesC
An object of class numeric of length 226.
Box, G.E., Jenkins, G.M., Reinsel, G.C. and Ljung, G.M. (2015) Time Series Analysis: Forecasting and Control. John Wiley & Sons, Hoboken.
Sampling interval 9 seconds; observations for 296 pairs of data points.
seriesJseriesJ
A object of class data.frame with 296 rows and 2 columns:
0.60-0.04 (input gas rate in cubir feet per minute.)
% CO2 in outlet gas.
Box, G.E., Jenkins, G.M., Reinsel, G.C. and Ljung, G.M. (2015) Time Series Analysis: Forecasting and Control. John Wiley & Sons, Hoboken.
Adds new inputs to transfer function or univariate models.
## S3 method for class 'tfm' setinputs( mdl, xreg = NULL, inputs = NULL, y = NULL, envir = parent.frame(), ... ) setinputs(mdl, ...) ## S3 method for class 'um' setinputs(mdl, xreg = NULL, inputs = NULL, y = NULL, envir = NULL, ...)## S3 method for class 'tfm' setinputs( mdl, xreg = NULL, inputs = NULL, y = NULL, envir = parent.frame(), ... ) setinputs(mdl, ...) ## S3 method for class 'um' setinputs(mdl, xreg = NULL, inputs = NULL, y = NULL, envir = NULL, ...)
mdl |
A |
xreg |
Optional matrix of exogenous regressors. |
inputs |
Optional list of |
y |
Optional |
envir |
Environment for evaluation. Default is calling environment. |
... |
Additional arguments passed to model constructor. |
For tfm objects: If the model already has inputs of the same type,
new ones are appended (combined). The model is re-fitted by default unless
fit = FALSE.
A tfm object.
signal extracts the signal of a TF model.
signal(mdl, ...) ## S3 method for class 'tfm' signal( mdl, y = NULL, diff = FALSE, type = c("xreg", "inputs"), envir = parent.frame(), ... )signal(mdl, ...) ## S3 method for class 'tfm' signal( mdl, y = NULL, diff = FALSE, type = c("xreg", "inputs"), envir = parent.frame(), ... )
mdl |
an object of the class |
... |
additional arguments. |
y |
output of the TF model if it is different to that of the |
diff |
logical. If TRUE, the signal is differenced with the "i" operator of the univariate model of the noise. |
type |
Character vector specifying signal components to extract: "xreg" for exogenous regressors only,"inputs" for transfer function inputs only. If both provided (default), includes all components. |
envir |
Environment in which the function arguments are evaluated. By default, the calling environment is used. |
A "ts" object.
Generates random time series from ARIMA (um) or transfer function (tfm) models.
## S3 method for class 'tfm' sim( mdl, n = 100, z0 = NULL, n0 = 0, a = NULL, seed = NULL, envir = parent.frame(), ... ) sim(mdl, ...) ## S3 method for class 'um' sim( mdl, n = 100, z0 = NULL, n0 = 0, a = NULL, seed = NULL, envir = parent.frame(), ... )## S3 method for class 'tfm' sim( mdl, n = 100, z0 = NULL, n0 = 0, a = NULL, seed = NULL, envir = parent.frame(), ... ) sim(mdl, ...) ## S3 method for class 'um' sim( mdl, n = 100, z0 = NULL, n0 = 0, a = NULL, seed = NULL, envir = parent.frame(), ... )
mdl |
|
n |
Number of observations to simulate. |
z0 |
Initial conditions for nonstationary series. Default is |
n0 |
Number of initial observations to discard as burn-in. Default is |
a |
Optional vector of innovations with length |
seed |
Random seed for reproducibility. |
envir |
Environment for argument evaluation. Default is |
... |
Additional arguments. |
A ts object with the simulated time series.
# AR(1) model mdl1 <- um(ar = "1 - 0.8B", sig2 = 1) z1 <- sim(mdl1, n = 100, seed = 123) # ARIMA(0,1,1) with burn-in mdl2 <- um(i = 1, ma = "1 - 0.5B", sig2 = 1) z2 <- sim(mdl2, n = 100, n0 = 50, seed = 456)# AR(1) model mdl1 <- um(ar = "1 - 0.8B", sig2 = 1) z1 <- sim(mdl1, n = 100, seed = 123) # ARIMA(0,1,1) with burn-in mdl2 <- um(i = 1, ma = "1 - 0.5B", sig2 = 1) z2 <- sim(mdl2, n = 100, n0 = 50, seed = 456)
'sincos()' creates a full set of seasonal trigonometric regressors (cos/sin harmonics) for a seasonal frequency.
sincos(Y, n.ahead = 0, constant = FALSE)sincos(Y, n.ahead = 0, constant = FALSE)
Y |
A seasonal 'ts' object. |
n.ahead |
Integer. Extra observations to extend the sample. |
constant |
Logical. If 'TRUE', include an intercept column. |
A 'ts' matrix with trigonometric variables (and intercept if requested).
X <- sincos(AirPassengers, constant = TRUE)X <- sincos(AirPassengers, constant = TRUE)
spec computes the spectrum of an ARMA model.
spec(um, ...) ## S3 method for class 'um' spec(um, nabla = FALSE, n.freq = 501, ...)spec(um, ...) ## S3 method for class 'um' spec(um, nabla = FALSE, n.freq = 501, ...)
um |
an object of class |
... |
additional parameters. |
nabla |
logical. If TRUE, the pseudospectrum for a non stationary ARIMA model is calculated. By default, the spectrum is computed for the stationary ARMA model. |
n.freq |
number of frequencies. |
A matrix with the frequencies and the power spectral densities.
The I polynomial is ignored.
um1 <- um(i = "(1 - B)(1 - B^12)", ma = "(1 - 0.8B)(1 - 0.8B^12)") s <- spec(um1, lag.max = 13)um1 <- um(i = "(1 - B)(1 - B^12)", ma = "(1 - 0.8B)(1 - 0.8B^12)") s <- spec(um1, lag.max = 13)
ssm creates an S3 object representing a time-invariant state space
model:
ssm(z, b, C, S, xreg = NULL, bc = FALSE, cform = TRUE, tol = 1e-05)ssm(z, b, C, S, xreg = NULL, bc = FALSE, cform = TRUE, tol = 1e-05)
z |
an object of class |
b |
vector of coefficients (m-dimensional). |
C |
matrix of coefficients (m x m). |
S |
covariance matrix of the error vector [u(t), v(t)], (m+1 x m+1). |
xreg |
design matrix of regressors. |
bc |
logical. If TRUE logs are taken. |
cform |
logical. If TRUE state equation is given in contemporaneous form, otherwise it is written in lagged form. |
tol |
tolerance to check if a value is zero or one. |
z(t) = b'x(t-j) + u(t) (observation equation), x(t) = Cx(t-1) + v(t) (state equation), j = 0 for contemporaneous form or j = 1 for lagged form. Note: the lagged form (j=1) is equivalent to the future form x(t+1) = Cx(t) + v(t+1).
An object of class ssm containing:
z |
the input time series |
b |
observation coefficients |
C |
state transition matrix |
S |
error covariance matrix |
xreg |
regressor matrix (if provided) |
a |
regression coefficients for xreg (if computed) |
z.name |
name of the input series |
bc |
Box-Cox transformation indicator |
m |
number of state variables |
cform |
form indicator (contemporaneous vs lagged) |
is.adm |
admissibility flag |
Durbin, J. and Koopman, S.J. (2012) Time Series Analysis by State Space Methods, 2nd ed., Oxford University Press, Oxford.
Harvey, A.C. (1989) Forecasting, Structural Time Series Models and the Kalman Filter. Cambridge University Press, Cambridge.
# Local level model b <- 1 C <- as.matrix(1) ssm1 <- ssm(Nile, b, C, S = diag(c(irr = 1, lvl = 0.5)) ) ssm1# Local level model b <- 1 C <- as.matrix(1) ssm1 <- ssm(Nile, b, C, S = diag(c(irr = 1, lvl = 0.5)) ) ssm1
Centers and scales a time series to zero mean and unit variance.
std(x)std(x)
x |
A |
Standardized time series with same class as input.
summary.ssm generates a detailed summary of the results of the
estimation of a ssm object.
## S3 method for class 'ssm' summary(object, ...)## S3 method for class 'ssm' summary(object, ...)
object |
An object of class |
... |
additional arguments. |
An object of class summary.ssm.
Produces summary statistics for a fitted transfer function model including parameter estimates, standard errors, and diagnostic tests.
## S3 method for class 'tfm' summary( object, y = NULL, method = c("exact", "cond"), digits = max(3L, getOption("digits") - 3L), envir = parent.frame(), ... )## S3 method for class 'tfm' summary( object, y = NULL, method = c("exact", "cond"), digits = max(3L, getOption("digits") - 3L), envir = parent.frame(), ... )
object |
A fitted |
y |
Optional |
method |
Character: "exact" or "cond" for residual calculation. |
digits |
Number of significant digits for printing. |
envir |
Environment for evaluation. NULL uses calling environment. |
... |
Additional arguments:
|
Computes parameter estimates with standard errors (from Jacobian), z-statistics, p-values, AIC, BIC, log-likelihood, Ljung-Box tests (at lags p+q+1 and n/4+p+q), and Bartlett heteroscedasticity test.
Object of class summary.tfm containing: call, coefficient
table, variance-covariance matrix, residuals, diagnostic statistics,
information criteria, and time series attributes.
## Not run: data(seriesJ) Y <- seriesJ$Y - mean(seriesJ$Y) X <- seriesJ$X - mean(seriesJ$X) umx <- um(X, ar = 3) umy <- fit(umx, Y) tfx <- tfest(Y, X, delay = 3, p = 2, q = 2, um.x = umx, um.y = umy) tfmy <- tfm(Y, inputs = tfx, noise = um(ar = 2)) sm <- summary(tfmy) print(sm) ## End(Not run)## Not run: data(seriesJ) Y <- seriesJ$Y - mean(seriesJ$Y) X <- seriesJ$X - mean(seriesJ$X) umx <- um(X, ar = 3) umy <- fit(umx, Y) tfx <- tfest(Y, X, delay = 3, p = 2, q = 2, um.x = umx, um.y = umy) tfmy <- tfm(Y, inputs = tfx, noise = um(ar = 2)) sm <- summary(tfmy) print(sm) ## End(Not run)
summary prints a summary of the estimation and diagnosis.
## S3 method for class 'um' summary( object, z = NULL, method = c("exact", "cond"), digits = max(3L, getOption("digits") - 3L), envir = NULL, ... )## S3 method for class 'um' summary( object, z = NULL, method = c("exact", "cond"), digits = max(3L, getOption("digits") - 3L), envir = NULL, ... )
object |
an object of class |
z |
an object of class |
method |
exact/conditional maximum likelihood. |
digits |
number of significant digits to use when printing. |
envir |
environment in which the function arguments are evaluated. If NULL the calling environment of this function will be used. |
... |
additional arguments. |
A list with the summary of the estimation and diagonosis.
z <- AirPassengers airl <- um(z, i = list(1, c(1,12)), ma = list(1, c(1,12)), bc = TRUE) summary(airl)z <- AirPassengers airl <- um(z, i = list(1, c(1,12)), ma = list(1, c(1,12)), bc = TRUE) summary(airl)
tf creates a rational transfer function for an input, V(B) = w0(1 -
w_1B - ... - w_qB^q)/(1-d_1B - ... - d_pB^p)B^dX_t. Note that in this
specification the constant term of the MA polynomial is factored out so that
both polynomials in the numerator and denominator are normalized and can be
specified with the lagpol function in the same way as the operators of
univariate models.
tf( x = NULL, delay = 0, w0 = 0.01, ar = NULL, ma = NULL, um = NULL, n.back = NULL, par.prefix = "", envir = parent.frame() )tf( x = NULL, delay = 0, w0 = 0.01, ar = NULL, ma = NULL, um = NULL, n.back = NULL, par.prefix = "", envir = parent.frame() )
x |
Input time series. A ts object or numeric vector. If NULL, input
should be provided inside the |
delay |
Integer. Number of periods to delay the input (d in the transfer function). |
w0 |
Numeric. Constant term of the transfer function polynomial V(B). |
ar |
Character string or list. Specification of autoregressive polynomials in the denominator. |
ma |
Character string or list. Specification of moving average polynomials in the numerator. |
um |
Univariate model object. Model for the stochastic component of the input series. |
n.back |
Integer. Number of backcasts to compute for extending the input series backward. |
par.prefix |
Character. Prefix for parameter names in transfer function. |
envir |
Environment. Environment for evaluating function arguments. If NULL, uses the calling environment. |
An object of class "tf" containing the transfer function specification. Key components include:
Input time series data (possibly extended with backcasts).
Number of periods delay in the transfer function.
Constant gain parameter.
AR polynomial coefficients (denominator).
MA polynomial coefficients (numerator).
Orders of AR and MA polynomials respectively.
Named list of all model parameters.
Univariate model for the input series.
Box, G.E., Jenkins, G.M., Reinsel, G.C. and Ljung, G.M. (2015) Time Series Analysis: Forecasting and Control. John Wiley & Sons, Hoboken.
Wei, W.W.S. (2006) Time Series Analysis Univariate and Multivariate Methods. 2nd Edition, Addison Wesley, New York, 33-59.
um.
x <- rep(0, 100) x[50] <- 1 tfx <- tf(x, w0 = 0.8, ar = "(1 - 0.5B)(1 - 0.7B^12)")x <- rep(0, 100) x[50] <- 1 tfx <- tf(x, w0 = 0.8, ar = "(1 - 0.5B)(1 - 0.7B^12)")
tfest estimates the transfer function
that relates the input X_t to the output Y_t.
tfest( y, x, delay = 0, p = 1, q = 2, um.y = NULL, um.x = NULL, n.back = NULL, par.prefix = "", envir = envir <- parent.frame() )tfest( y, x, delay = 0, p = 1, q = 2, um.y = NULL, um.x = NULL, n.back = NULL, par.prefix = "", envir = envir <- parent.frame() )
y |
Output series, a ts object or numeric vector. |
x |
Input series, a ts object or numeric vector. |
delay |
Integer. Number of periods delay (default 0). |
p |
Integer. Order of the AR polynomial (default 1). |
q |
Integer. Order of the MA polynomial (default 2). |
um.y |
Univariate model for output series, um object or NULL. |
um.x |
Univariate model for input series, um object or NULL. |
n.back |
Integer. Number of backcasts to compute. |
par.prefix |
Character. Prefix for parameter names. |
envir |
Environment for evaluating arguments. If NULL, uses calling environment. |
Uses prewhitening to estimate initial parameter values.
An object of class tf containing preestimated transfer
function parameters.
data(seriesJ) Y <- seriesJ$Y - mean(seriesJ$Y) X <- seriesJ$X - mean(seriesJ$X) umx <- um(X, ar = 3) umy <- fit(umx, Y) tfx <- tfest(Y, X, delay = 3, p = 2, q = 2, um.x = umx, um.y = umy)data(seriesJ) Y <- seriesJ$Y - mean(seriesJ$Y) X <- seriesJ$X - mean(seriesJ$X) umx <- um(X, ar = 3) umy <- fit(umx, Y) tfx <- tfest(Y, X, delay = 3, p = 2, q = 2, um.x = umx, um.y = umy)
Creates and optionally fits a multiple-input transfer function model. A transfer function model relates an output time series to one or more input series (transfer functions), exogenous regressors, and a noise model.
tfm( output = NULL, xreg = NULL, inputs = NULL, noise, fit = TRUE, new.name = TRUE, envir = parent.frame(), ... )tfm( output = NULL, xreg = NULL, inputs = NULL, noise, fit = TRUE, new.name = TRUE, envir = parent.frame(), ... )
output |
A numeric vector or |
xreg |
A numeric matrix or |
inputs |
A list of transfer function objects of class |
noise |
An object of class |
fit |
Logical. If |
new.name |
Logical. Internal use. If |
envir |
Environment in which the function arguments are evaluated.
If |
... |
Additional arguments passed to |
All series must have the same frequency. Input series must span at least
the same period as output. The function applies differencing and Box-Cox
transformation as specified in noise.
Object of class tfm with components: output, xreg, inputs,
noise, param, kx, k, optim, method, and call.
Box, G. E., Jenkins, G. M., Reinsel, G. C., & Ljung, G. M. (2015). Time Series Analysis: Forecasting and Control (5th ed.). Wiley.
## Not run: data(seriesJ) Y <- seriesJ$Y - mean(seriesJ$Y) X <- seriesJ$X - mean(seriesJ$X) umx <- um(X, ar = 3) umy <- fit(umx, Y) tfx <- tfest(Y, X, delay = 3, p = 2, q = 2, um.x = umx, um.y = umy) tfmy <- tfm(Y, inputs = tfx, noise = um(ar = 2)) ## End(Not run)## Not run: data(seriesJ) Y <- seriesJ$Y - mean(seriesJ$Y) X <- seriesJ$X - mean(seriesJ$X) umx <- um(X, ar = 3) umy <- fit(umx, Y) tfx <- tfest(Y, X, delay = 3, p = 2, q = 2, um.x = umx, um.y = umy) tfmy <- tfm(Y, inputs = tfx, noise = um(ar = 2)) ## End(Not run)
Unscramble MA polynomial
theta(um) ## S3 method for class 'um' theta(um)theta(um) ## S3 method for class 'um' theta(um)
um |
an object of class |
A numeric vector c(1, a1, ..., ad)
This function returns the member variable um$theta.
um1 <- um(ma = "(1 - 0.8B)(1 - 0.5B)") theta(um1)um1 <- um(ma = "(1 - 0.8B)(1 - 0.5B)") theta(um1)
tsdiag.tfm is a wrap of the stats::tsdiag function.
## S3 method for class 'tfm' tsdiag(object, gof.lag = 10, ...)## S3 method for class 'tfm' tsdiag(object, gof.lag = 10, ...)
object |
a fitted |
gof.lag |
the maximum number of lags for a Portmanteau goodness-of-fit test |
... |
additional arguments. |
stats::tsdiag.
tsdiag.um is a wrap of the stats::tsdiag function.
## S3 method for class 'um' tsdiag(object, gof.lag = 10, ...)## S3 method for class 'um' tsdiag(object, gof.lag = 10, ...)
object |
a fitted |
gof.lag |
the maximum number of lags for a Portmanteau goodness-of-fit test |
... |
additional arguments. |
stats::tsdiag.
Retrieves the value of a time series at a specific date.
tsvalue(x, date)tsvalue(x, date)
x |
A |
date |
Numeric vector: c(year) for annual data or c(year, period) for seasonal data. |
Numeric value at the specified date.
uc creates an S3 object representing a predefined UC (trend, seasonal,
cycle, autoregressive and irregular component).
uc( type, s2 = NULL, s = 12, form = c("trig", "dummy"), per = 5, phi = 0.9, counter = 1 )uc( type, s2 = NULL, s = 12, form = c("trig", "dummy"), per = 5, phi = 0.9, counter = 1 )
type |
character. The type of component: trend, seasonal, cycle, AR or irregular. |
s2 |
vector with the variances of the errors driving the UC. |
s |
integer. Seasonal period for seasonal components. |
form |
character. The form of the seasonal component (trigonometric or dummy seasonality). |
per |
numeric. The period of the cycle component. |
phi |
numeric. The damping factor of the cycle component. |
counter |
integer. Counter for numbering phi cycle parameters. |
An object of class uc.
Durbin, J. and Koopman, S.J. (2012) Time Series Analysis by State Space Methods, 2nd ed., Oxford University Press, Oxford.
Harvey, A.C. (1989) Forecasting, Structural Time Series Models and the Kalman Filter. Cambridge University Press, Cambridge.
# Trend component trend <- uc("trend", s2 = c(s2_lvl = 0.5, s2_slp = 0.025)) # Seasonal component seas <- uc("seasonal", s2 = c(s2_seas = 0.5), s = 12, form = "trig") # Cycle component cycle1 <- uc("cycle", s2 = c(s2_c1 = 0.5), per = 5, phi = 0.8) cycle2 <- uc("cycle", s2 = c(s2_c2 = 0.5), per = 10, phi = 0.8, counter = 2)# Trend component trend <- uc("trend", s2 = c(s2_lvl = 0.5, s2_slp = 0.025)) # Seasonal component seas <- uc("seasonal", s2 = c(s2_seas = 0.5), s = 12, form = "trig") # Cycle component cycle1 <- uc("cycle", s2 = c(s2_c1 = 0.5), per = 5, phi = 0.8) cycle2 <- uc("cycle", s2 = c(s2_c2 = 0.5), per = 10, phi = 0.8, counter = 2)
uc0 constructs unobservable components by specifying their state-space
representation matrices. This is the helper function used internally by
uc to create predefined components like trends, seasonals, and
cycles.
uc0(name, param, b, C = NULL, S = NULL)uc0(name, param, b, C = NULL, S = NULL)
name |
character, name of the UC. |
param |
a vector or list with the parameters of the UC. |
b |
vector of the UC in the observation equation. |
C |
matrix of the UC in the transition matrix. |
S |
covariance matrix of the error vector driving the UC. |
An S3 object of class uc.
Matrices b, C and S can include symbolic expressions in terms of the
parameters of the model. These parameters are defined in the param
argument with their corresponding names. See the ssm function
for more information about b, C and S.
Durbin, J. and Koopman, S.J. (2012) Time Series Analysis by State Space Methods, 2nd ed., Oxford University Press, Oxford.
Harvey, A.C. (1989) Forecasting, Structural Time Series Models and the Kalman Filter. Cambridge University Press, Cambridge.
# Local linear trend component param <- c(s2_lvl = 0.05, s2_slp = 0.025) b <- c(1, 0) C <- matrix(c(1, 1, 0, 1), 2, 2, byrow = TRUE) S <- matrix(c("s2_lvl", "0", "0", "s2_slp"), 2, 2) trend <- uc0("trend", param, b, C, S) # Cycle component param <- c(phi = 0.8, per = 5, s2c = 0.01) b <- c(1, 0) C <- matrix(c("phi*cos(2*pi/per)", "phi*sin(2*pi/per)", "-phi*sin(2*pi/per)", "phi*cos(2*pi/per)"), 2, 2, byrow = TRUE) S <- matrix(c("s2c*(1 - phi^2)", "0", "0", "s2c*(1 - phi^2)")) cycle <- uc0("cycle", param, b, C, S)# Local linear trend component param <- c(s2_lvl = 0.05, s2_slp = 0.025) b <- c(1, 0) C <- matrix(c(1, 1, 0, 1), 2, 2, byrow = TRUE) S <- matrix(c("s2_lvl", "0", "0", "s2_slp"), 2, 2) trend <- uc0("trend", param, b, C, S) # Cycle component param <- c(phi = 0.8, per = 5, s2c = 0.01) b <- c(1, 0) C <- matrix(c("phi*cos(2*pi/per)", "phi*sin(2*pi/per)", "-phi*sin(2*pi/per)", "phi*cos(2*pi/per)"), 2, 2, byrow = TRUE) S <- matrix(c("s2c*(1 - phi^2)", "0", "0", "s2c*(1 - phi^2)")) cycle <- uc0("cycle", param, b, C, S)
ucarima creates an S3 object that combines two or more ARIMA models
(objects of class um).
ucarima( z = NULL, bc = FALSE, ucm = NULL, ar = NULL, xreg = NULL, fit = TRUE, envir = parent.frame(), ... )ucarima( z = NULL, bc = FALSE, ucm = NULL, ar = NULL, xreg = NULL, fit = TRUE, envir = parent.frame(), ... )
z |
an object of class |
bc |
logical. If TRUE logs are taken. |
ucm |
a list of |
ar |
list of stationary AR lag polynomials ( |
xreg |
matrix of explanatory variables. |
fit |
logical. If TRUE, model is fitted. |
envir |
environment. |
... |
additional arguments. |
An object of class ucarima.
Harvey, A.C. (1989) Forecasting, Structural Time Series Models and the Kalman Filter. Cambridge University Press, Cambridge.
trend <- um(i = "(1 - B)", sig2 = c(s2t = 1)) seas <- um(i = "(1+B)", sig2 = c(s2s = 0.05)) irreg <- um(sig2 = c(s2i = 0.75)) uca1 <- ucarima(ucm = list(trend = trend, seas = seas, irreg = irreg)) uca1 # Trigonometric seasonality uca2 <- ucarima(AirPassengers, bc = TRUE) uca2 # Dummy seasonality uca3 <- ucarima(AirPassengers, bc = TRUE, ucm = "ht") uca3trend <- um(i = "(1 - B)", sig2 = c(s2t = 1)) seas <- um(i = "(1+B)", sig2 = c(s2s = 0.05)) irreg <- um(sig2 = c(s2i = 0.75)) uca1 <- ucarima(ucm = list(trend = trend, seas = seas, irreg = irreg)) uca1 # Trigonometric seasonality uca2 <- ucarima(AirPassengers, bc = TRUE) uca2 # Dummy seasonality uca3 <- ucarima(AirPassengers, bc = TRUE, ucm = "ht") uca3
ucm creates an S3 object representing an UC model:
ucm( z, bc = FALSE, uc = NULL, xreg = NULL, cform = TRUE, fit = TRUE, s = 12, ... )ucm( z, bc = FALSE, uc = NULL, xreg = NULL, cform = TRUE, fit = TRUE, s = 12, ... )
z |
an object of class |
bc |
logical. If TRUE, logs are taken. |
uc |
list of objects of class |
xreg |
optional design matrix of regressors. |
cform |
logical. If TRUE, observation equation is given in contemporaneous form (j = 0); otherwise it is written in lagged form (j = 1). |
fit |
logical. If TRUE, model is fitted. |
s |
integer, seasonal period. Optional argument to create a UC model without providing a time series. |
... |
additional parameters for the |
z(t) = b'*x(t) + T(t - j) + S(t - j) + C(t - j) + AR(t - j) + I(t),
where z(t) is a time series; x(t) is a set of regressors; T(t - j), S(t - j),
C(t - j), AR(t - j) and I(t) are the trend, seasonal, cycle, autoregressive
and irregular unobserved components; and i indicates whether the model is
written in lagged form (j = 1) or contemporaneous form (j = 0).
See uc and ssm for more details.
An object of class ucm and class ssm.
Durbin, J. and Koopman, S.J. (2012) Time Series Analysis by State Space Methods, 2nd ed., Oxford University Press, Oxford.
Harvey, A.C. (1989) Forecasting, Structural Time Series Models and the Kalman Filter. Cambridge University Press, Cambridge.
# Local level model ucm1 <- ucm(Nile, uc = "llm") ucm1# Local level model ucm1 <- ucm(Nile, uc = "llm") ucm1
um creates an S3 object representing a univariate ARIMA model, which
can contain multiple AR, I and MA polynomials, as well as parameter
restrictions.
um( z = NULL, ar = NULL, i = NULL, ma = NULL, mu = NULL, sig2 = 1, bc = FALSE, fit = TRUE, envir = parent.frame(), warn = TRUE, ... )um( z = NULL, ar = NULL, i = NULL, ma = NULL, mu = NULL, sig2 = 1, bc = FALSE, fit = TRUE, envir = parent.frame(), warn = TRUE, ... )
z |
an object of class |
ar |
list of stationary AR lag polynomials. |
i |
list of nonstationary AR (I) polynomials. |
ma |
list of MA polynomials. |
mu |
mean of the stationary time series. |
sig2 |
variance of the error. |
bc |
logical. If TRUE logs are taken. |
fit |
logical. If TRUE, model is fitted. |
envir |
the environment in which to look for the time series z when it is passed as a character string. |
warn |
logical. If TRUE, a warning is displayed for non-admissible models. |
... |
additional arguments. |
An object of class um.
Box, G.E.P., Jenkins, G.M., Reinsel, G.C. and Ljung, G.M. (2015) Time Series Analysis: Forecasting and Control. John Wiley & Sons, Hoboken.
ar1 <- um(ar = "(1 - 0.8B)") ar2 <- um(ar = "(1 - 1.4B + 0.8B^2)") ma1 <- um(ma = "(1 - 0.8B)") ma2 <- um(ma = "(1 - 1.4B + 0.8B^2)") arma11 <- um(ar = "(1 - 1.4B + 0.8B^2)", ma = "(1 - 0.8B)")ar1 <- um(ar = "(1 - 0.8B)") ar2 <- um(ar = "(1 - 1.4B + 0.8B^2)") ma1 <- um(ma = "(1 - 0.8B)") ma2 <- um(ma = "(1 - 1.4B + 0.8B^2)") arma11 <- um(ar = "(1 - 1.4B + 0.8B^2)", ma = "(1 - 0.8B)")
unitcircle plots the inverse roots of a lag polynomial together the
unit circle.
unitcircle(lp, ...) ## Default S3 method: unitcircle(lp, ...) ## S3 method for class 'lagpol' unitcircle(lp, s = 12, ...)unitcircle(lp, ...) ## Default S3 method: unitcircle(lp, ...) ## S3 method for class 'lagpol' unitcircle(lp, s = 12, ...)
lp |
an object of class |
... |
additional arguments. |
s |
integer, seasonal period. |
unitcircle returns a NULL value.
unitcircle(as.lagpol(c(1, rep(0, 11), -1)))unitcircle(as.lagpol(c(1, rep(0, 11), -1)))
varsel omits non-significant inputs from a transfer function model.
varsel(tfm, ...) ## S3 method for class 'tfm' varsel(tfm, y = NULL, p.value = 0.1, envir = parent.frame(), ...)varsel(tfm, ...) ## S3 method for class 'tfm' varsel(tfm, y = NULL, p.value = 0.1, envir = parent.frame(), ...)
tfm |
a |
... |
other arguments. |
y |
a "ts" object. |
p.value |
probability value to decide whether or not to omit an input. |
envir |
environment in which the function arguments are evaluated. By default, the calling environment of this function will be used. |
A tfm object or a "um" if no input is significant at that level.
wkfilter extracts a signal for a time series described by an ARIMA
model given the ARIMA model for the signal.
## S3 method for class 'as_ucarima' wkfilter(object, z = NULL, tol = 1e-05, envir = parent.frame(), ...) wkfilter(object, ...) ## S3 method for class 'um' wkfilter( object, um.uc, z = NULL, output = c("series", "filter"), tol = 1e-05, envir = parent.frame(), ... )## S3 method for class 'as_ucarima' wkfilter(object, z = NULL, tol = 1e-05, envir = parent.frame(), ...) wkfilter(object, ...) ## S3 method for class 'um' wkfilter( object, um.uc, z = NULL, output = c("series", "filter"), tol = 1e-05, envir = parent.frame(), ... )
object |
an object of class |
z |
an optional |
tol |
numeric tolerance used in polynomial divisions. Default is
|
envir |
environment to get |
... |
additional arguments. |
um.uc |
ARIMA models for the observed time series and the unobserved component (signal). |
output |
character, output of the function: '"series"' (default) returns the filtered time series, or '"filter"' returns the filter coefficients. |
An object of class ts containing the estimated signal.
um1 <- airline(AirPassengers, bc = TRUE) uca1 <- as.ucarima(um1, i = "(1-B)2") trend <- wkfilter(um1, uca1$ucm$signal1) seas <- wkfilter(um1, uca1$ucm$signal2)um1 <- airline(AirPassengers, bc = TRUE) uca1 <- as.ucarima(um1, i = "(1-B)2") trend <- wkfilter(um1, uca1$ucm$signal1) seas <- wkfilter(um1, uca1$ucm$signal2)
Transforming a palindromic polymonial into a Wold polynomial/ Computing the Cramer-Wold factorization
wold.pol(x, type = c("wold", "palindromic", "cramer-wold"), tol = 1e-05)wold.pol(x, type = c("wold", "palindromic", "cramer-wold"), tol = 1e-05)
x |
numeric vector, coefficients of a palindromic or a Wold polynomial. |
type |
character indicating the type of polynomial: (1) Wold polynomial, (2) Palindromic polynomial and (3) Cramer-Wold factor. |
tol |
tolerance to check if an autocovariance is zero. |
wold.pol can be used with three purposes:
(1) to transform a self-reciprocal or palindromic polynomial a_0 + a_1(B+F) + a_2(B^2+F^2) + ... + a_p(B^p+F^p) into a Wold polynomial b_0 + b_1(B+F) + b_2(B+F)^2 + ... + b_p(B+F)^p;
(2) to revert the previous transformation to obtain the palindromic polynominal from a Wold polynomial and
(3) to compute the Cramer-Wold factorization: b(B+F) = c(B)c(F).
Numeric vector.
wold.pol(c(6, -4, 1))wold.pol(c(6, -4, 1))
Monthly data from January 1951 to October 1966.
WtelephoneWtelephone
A object of class data.frame with 215 rows and 2 columns:
Monthly outward station movements.
Montly inward station movements.
https://drive.google.com/file/d/1LP8aMIQewMrxgOlrg9rN3eWHhZuUsY8K/view?usp=sharing
Thompson, H. E. and Tiao, G. C. (1971) "Analysis of Telephone Data: A Case Study of Forecasting Seasonal Time Series," Bell Journal of Economics, The RAND Corporation, vol. 2(2), pages 515-541, Autumn.