The function uses an automatically produced moving average smoother as base
for predicting and returning the next n consecutive values of the provided
univariate time series using an also automatically fitted model
(ets
/stlf
or arima
). It also
evaluates the fitness and prediction accuracy of the produced model.
fittestMAS(
timeseries,
timeseries.test = NULL,
h = NULL,
order = NULL,
minorder = 1,
maxorder = min(36, length(ts(na.action(timeseries)))/2),
model = c("ets", "arima"),
level = 0.95,
na.action = stats::na.omit,
rank.by = c("MSE", "NMSE", "MAPE", "sMAPE", "MaxError", "AIC", "AICc", "BIC",
"logLik", "errors", "fitness"),
...
)
A vector or univariate time series.
A vector or univariate time series containing a
continuation for timeseries
with actual values. It is used as a
testing set and base for calculation of prediction error measures. Ignored
if NULL
.
Number of consecutive values of the time series to be predicted. If
h
is NULL
, the number of consecutive values to be predicted is
assumed to be equal to the length of timeseries.test
. Required when
timeseries.test
is NULL
.
A numeric integer value corresponding to the order of moving
average smoother to be produced. If NULL
, the order of the moving
average smoother returned by the function is automatically selected within
the interval minorder:maxorder
. See 'Details'.
A numeric integer value corresponding to the minimum order
of candidate moving average smoothers to be produced and evaluated. Ignored
if order
is provided. See 'Details'.
A numeric integer value corresponding to the maximal order
of candidate moving average smoothers to be produced and evaluated. Ignored
if order
is provided. See 'Details'.
Character string. Indicates which model is to be used for fitting and prediction of the moving average smoothed series.
Confidence level for prediction intervals. See the
forecast
function of the forecast
package.
A function for treating missing values in timeseries
and timeseries.test
. The default function is na.omit
,
which omits any missing values found in timeseries
or
timeseries.test
.
Character string. Criteria used for ranking candidate models generated. See 'Details'.
Additional arguments passed to the modeling functions.
A list with components:
A list containing information about the best evaluated model.
The order of moving average smoother provided or automatically selected.
The simple moving
average smoother of order order
of the provided time series.
Numeric value of the computed AICc criterion of the best evaluated model.
Numeric value of the computed AIC criterion of the best evaluated model.
Numeric value of the computed BIC criterion of the best evaluated model.
Numeric value of the computed log-likelihood of the best evaluated model.
A list
with the components mean
, lower
and upper
, containing
the predictions of the best evaluated model and the lower and upper limits
for prediction intervals, respectively. All components are time series. See
the forecast
function in the forecast
package.
Numeric value of the resulting MSE error of prediction.
Require timeseries.test
.
Numeric value of the resulting
NMSE error of prediction. Require timeseries.test
.
Numeric value of the resulting MAPE error of prediction. Require
timeseries.test
.
Numeric value of the resulting sMAPE
error of prediction. Require timeseries.test
.
Numeric value of the maximal error of prediction. Require
timeseries.test
.
Data.frame with the fitness or
prediction accuracy criteria computed for all candidate models ranked by
rank.by
. It has the attribute "ranked.models"
, which is a list
of objects containing all the candidate models, also ranked by
rank.by
.
Ranking criteria used for ranking candidate
models and producing rank.val
.
The function produces a moving average smoother of timeseries
with
order order
and uses it as base for model fitting and prediction. If
model="arima"
, an arima model is used and automatically fitted using
the auto.arima
function. If model="ets"
, the
function fits an [forecast]ets
model (if timeseries
is
non-seasonal or the seasonal period is 12 or less) or
stlf
model (if the seasonal period is 13 or more).
For producing the prediction of the next h
consecutive values of the
provided univariate time series, the function mas.rev
is used.
If order
is NULL
, it is automatically selected. For that, a
set with candidate models constructed for moving average smoothers of orders
from minorder
to maxorder
is generated. The default value of
maxorder
is set based on code from the sma
function of
smooth
package. The value option of order
which generate the
best ranked candidate 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.
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.
# NOT RUN {
data(CATS)
# }
# NOT RUN {
fMAS <- fittestMAS(CATS[,1],h=20,model="arima")
#automatically selected order of moving average
mas.order <- fMAS$order
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab