Title: | Implementation of Unobserved Components Model (UCM) in R |
---|---|
Description: | Unobserved Components Models (introduced in Harvey, A. (1989), Forecasting, structural time series models and the Kalman filter, Cambridge New York: Cambridge University Press) decomposes a time series into components such as trend, seasonal, cycle, and the regression effects due to predictor series which captures the salient features of the series to predict its behavior. |
Authors: | Kaushik Roy Chowdhury |
Maintainer: | Kaushik Roy Chowdhury <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.6.2 |
Built: | 2025-03-08 02:13:46 UTC |
Source: | https://github.com/kaushikrch/rucm |
Function predict.ucm
predicts the future observations of
an Unobserved Components Model. The ucm
function returns an object
model
of class SSModel
which is then further used in
predict.SSModel
.
## S3 method for class 'ucm' predict(object, n.ahead, newdata, ...)
## S3 method for class 'ucm' predict(object, n.ahead, newdata, ...)
object |
an object of class |
n.ahead |
number of points for which forecasts are to generated. |
newdata |
A compatible dataframe to be added in the end of the old object for which the predictions are required. If omitted, predictions are either for the past data points, or if argument n.ahead is given, n.ahead time steps ahead. |
... |
ignored. |
A matrix or list of matrices containing the predictions.
modelNile <- ucm(Nile~0, data = Nile, slope = TRUE) predict(modelNile$model, n.ahead = 12)
modelNile <- ucm(Nile~0, data = Nile, slope = TRUE) predict(modelNile$model, n.ahead = 12)
Print ucm Object
## S3 method for class 'ucm' print(x, ...)
## S3 method for class 'ucm' print(x, ...)
x |
ucm object |
... |
Ignored. |
Package rucm contains functions to model and predict a time series using Unobserved Components Model (UCM) (Harvey (1989)) which decomposes the series into its salient components of trend, seasons, cycles, and regression effects due to predictors.
Unobserved Components Models (UCMs) are special cases of more general and powerful tool in time series called State Space Models having an observation equation, which relates the dependent series to an unobserved state vector, and a state equation describing the evolution of the state vector over time. For a detailed discussion on State Space Models refer Harvey (1989) or Helske (2014).
Harvey A. (1989). Forecasting, structural time series models and the Kalman filter. Cambridge New York: Cambridge University Press
Helske J (2014). KFAS: Kalman filter and Smoothers for Exponential Family State Space Models. R package version 1.0.4-1, URL http://CRAN.R-project.org/package=KFAS.
SAS Institute Inc (2010). SAS/ETS 9.22 User's Guide. SAS Institute Inc., Cary, NC. URL http://support.sas.com/documentation/cdl/en/etsug/60372/PDF/default/etsug.pdf.
Selukar R (2011). "State Space Modeling Using SAS". Journal of Statistical Software, 41(12), 1-13. URL http://www.jstatsoft.org/v41/i12/.
Petris G, Petrone S (2011). "State Space Models in R". Journal of Statistical Software, 41(4), 1-25. URL http://www.jstatsoft.org/v41/i04/.
modelNile <- ucm(Nile~0, data = Nile, irregular = TRUE, level = TRUE, slope = TRUE) modelNile #Print the model #Return smoothed level values modelNile$s.level #Fixing the level variance to an absolute value modelNile.fix <- ucm(Nile~0, data = Nile, irregular = TRUE, level = TRUE, level.var = 500, slope = TRUE) #Predicting future values of the time series predict(modelNile.fix, n.ahead = 12)
modelNile <- ucm(Nile~0, data = Nile, irregular = TRUE, level = TRUE, slope = TRUE) modelNile #Print the model #Return smoothed level values modelNile$s.level #Fixing the level variance to an absolute value modelNile.fix <- ucm(Nile~0, data = Nile, irregular = TRUE, level = TRUE, level.var = 500, slope = TRUE) #Predicting future values of the time series predict(modelNile.fix, n.ahead = 12)
Function ucm
decomposes a time series into components such as trend, seasonal, cycle, and the regression effects due to predictor series using Unobserved Components Model (UCM).
ucm(formula, data, irregular = TRUE, irregular.var = NA, level = TRUE, level.var = NA, slope = FALSE, slope.var = NA, season = FALSE, season.length = NA, season.var = NA, cycle = FALSE, cycle.period = NA, cycle.var = NA, tol = .Machine$double.eps^0.5)
ucm(formula, data, irregular = TRUE, irregular.var = NA, level = TRUE, level.var = NA, slope = FALSE, slope.var = NA, season = FALSE, season.length = NA, season.var = NA, cycle = FALSE, cycle.period = NA, cycle.var = NA, tol = .Machine$double.eps^0.5)
formula |
an object of class |
data |
a required data frame or list containing variables in the model. |
irregular |
logical; if irregular component is to be included in the model. Defaults to |
irregular.var |
value to fix variance of irregular component. |
level |
logical; if level is to be included in the model. Defaults to |
level.var |
value to fix variance of level component. |
slope |
logical; if slope is to be included in the model along with level. Defaults to |
slope.var |
value to fix variance of the slope component. |
season |
logical; if seasonal component is to be included in the model. Defaults to |
season.length |
value of length of seasonal component. Required when |
season.var |
value to fix variance of seasonal component. |
cycle |
logical; if cyclical component is to be included in the model. Defaults to |
cycle.period |
length of cyclical component. Required when |
cycle.var |
value to fix variance of cyclical component. |
tol |
Used by |
Formula of the model can be of the forma as in lm
with response variable on rhs and predictor variables or 0 (if no predictor variables) on the rhs.
object of class ucm
, which is a list with the following components:
est |
Estimates of predictor variables, if present. |
irr.var |
Estimated variance of irregular component, if present. |
est.var.level |
Estimated variance of the level component, if present. |
est.var.slope |
Estimated variance of slope of the level, if present. |
est.var.season |
Estimated variance of the seasonal component, if present. |
est.var.cycle |
Estimated variance of the cyclical component, if present. |
s.level |
An object of the same class as of dependent variable containing the time varying level values, if level is present. |
s.lope |
An object of the same class as of dependent variable containing the time varying slope values, if slope is present. |
s.season |
An object of the same class as of dependent variable containing the time varying seasonal values, if season is present. |
s.cycle |
An object of the same class as of dependent variable containing the time varying cyclical values, if cycle is present. |
vs.level |
A vector containing time varying estimated variance of level, if level is present. |
vs.slope |
A vector containing time varying estimated variance of slope, if slope is present. |
vs.season |
A vector containing time varying estimated variance of seasonal component, if season is present. |
vs.cycle |
A vector containing time varying estimated variance of cyclical component, if cycle is present. |
call |
Original call of the function. |
model |
KFAS
, SSModel
for a detailed discussion on State Space Models.
modelNile <- ucm(Nile~0, data = Nile, slope = TRUE) modelNile modelNile$s.level
modelNile <- ucm(Nile~0, data = Nile, slope = TRUE) modelNile modelNile$s.level