fittestArimaKF {TSPred} | R Documentation |
Automatic ARIMA fitting and prediction with Kalman filter
Description
The function predicts and returns the next n consecutive values of a univariate time series using the best evaluated ARIMA model automatically fitted with Kalman filter. It also evaluates the fitness of the produced model, using AICc, AIC, BIC and logLik criteria, and its prediction accuracy, using the MSE, NMSE, MAPE, sMAPE and maximal error accuracy measures.
Usage
fittestArimaKF(
timeseries,
timeseries.test = NULL,
h = NULL,
na.action = stats::na.omit,
level = 0.9,
filtered = TRUE,
initQ = NULL,
rank.by = c("MSE", "NMSE", "MAPE", "sMAPE", "MaxError", "AIC", "AICc", "BIC",
"logLik", "errors", "fitness"),
...
)
Arguments
timeseries |
A vector or univariate time series which contains the values used for fitting an ARIMA model with Kalman filter. |
timeseries.test |
A vector or univariate time series containing a
continuation for |
h |
Number of consecutive values of the time series to be predicted. If
|
na.action |
A function for treating missing values in |
level |
Confidence level for prediction intervals. See the
|
filtered |
If |
initQ |
Numeric argument regarding the initial value for the covariance
of disturbances parameter to be optimized over. The initial value to be
optimized is set to |
rank.by |
Character string. Criteria used for ranking candidate models
generated using different options of values for |
... |
Additional arguments passed to the |
Details
A best ARIMA model is automatically fitted by the auto.arima
function in the forecast
package. The coefficients of this model are
then used as initial parameters for optimization of a state space model
(SSModel
) using the Kalman filter and functions of the
KFAS
package (see SSMarima
and
artransform
).
If initQ
is NULL
, it is automatically set as either
log(var(timeseries))
or 0
. For that, a set of candidate ARIMA
state space models is generated by different initial parameterization of
initQ
during the model optimization process. The value option which
generates the best ranked candidate ARIMA model acoording to the criteria in
rank.by
is selected.
The ranking criteria in rank.by
may be set as a prediction error
measure (such as MSE
, NMSE
, MAPE
,
sMAPE
or MAXError
), or as a fitness criteria
(such as AIC
, AICc
, BIC
or
logLik
). In the former case, the candidate models are used for
time series prediction and the error measures are calculated by means of a
cross-validation process. In the latter case, the candidate models are
fitted and fitness criteria are calculated based on all observations in
timeseries
.
If rank.by
is set as "errors"
or "fitness"
, the
candidate models are ranked by all the mentioned prediction error measures
or fitness criteria, respectively. The wheight of the ranking criteria is
equally distributed. In this case, a rank.position.sum
criterion is
produced for ranking the candidate models. The rank.position.sum
criterion is calculated as the sum of the rank positions of a model (1 = 1st
position = better ranked model, 2 = 2nd position, etc.) on each calculated
ranking criteria.
Value
A list with components:
model |
An object of class "SSModel" containing the best evaluated ARIMA model fitted with Kalman Filter. |
initQ |
The initQ argument provided (or automatically selected) for optimization of the best evaluated ARIMA model fitted with Kalman Filter. |
AICc |
Numeric value of the computed AICc criterion of the best evaluated model. |
AIC |
Numeric value of the computed AIC criterion of the best evaluated model. |
BIC |
Numeric value of the computed BIC criterion of the best evaluated model. |
logLik |
Numeric value of the computed log-likelihood of the best evaluated model. |
pred |
A list
with the components |
MSE |
Numeric value of the resulting
MSE error of prediction. Require |
NMSE |
Numeric value of the resulting NMSE error of prediction. Require
|
MAPE |
Numeric value of the resulting MAPE
error of prediction. Require |
sMAPE |
Numeric
value of the resulting sMAPE error of prediction. Require
|
MaxError |
Numeric value of the maximal error
of prediction. Require |
rank.val |
Data.frame
with the fitness or prediction accuracy criteria computed for all candidate
ARIMA with Kalman filter models ranked by |
rank.by |
Ranking criteria used for ranking
candidate models and producing |
Author(s)
Rebecca Pontes Salles
References
R.J. Hyndman and G. Athanasopoulos, 2013, Forecasting: principles and practice. OTexts.
R.H. Shumway and D.S. Stoffer, 2010, Time Series Analysis and Its Applications: With R Examples. 3rd ed. 2011 edition ed. New York, Springer.
See Also
fittestArima
, fittestLM
,
marimapred
Examples
data(CATS,CATS.cont)
fArimaKF <- fittestArimaKF(CATS[,2],CATS.cont[,2])
#predicted values
pred <- fArimaKF$pred
#extracting Kalman filtered and smoothed time series from the best fitted model
fs <- KFAS::KFS(fArimaKF$model,filtering=c("state","mean"),smoothing=c("state","mean"))
f <- fitted(fs, filtered = TRUE) #Kalman filtered time series
s <- fitted(fs) #Kalman smoothed time series
#plotting the time series data
plot(c(CATS[,2],CATS.cont[,2]),type='o',lwd=2,xlim=c(960,1000),ylim=c(200,600),
xlab="Time",ylab="ARIMAKF")
#plotting the Kalman filtered time series
lines(f,col='red',lty=2,lwd=2)
#plotting the Kalman smoothed time series
lines(s,col='green',lty=2,lwd=2)
#plotting predicted values
lines(ts(pred$mean,start=981),lwd=2,col='blue')
#plotting prediction intervals
lines(ts(pred$upper,start=981),lwd=2,col='light blue')
lines(ts(pred$lower,start=981),lwd=2,col='light blue')