fittestMAS: Automatic prediction with moving average smoothing

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/fittestMAS.r

Description

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.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
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"),
  ...
)

Arguments

timeseries

A vector or univariate time series.

timeseries.test

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.

h

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.

order

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'.

minorder

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'.

maxorder

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'.

model

Character string. Indicates which model is to be used for fitting and prediction of the moving average smoothed series.

level

Confidence level for prediction intervals. See the forecast function of the forecast package.

na.action

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.

rank.by

Character string. Criteria used for ranking candidate models generated. See 'Details'.

...

Additional arguments passed to the modeling functions.

Details

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.

Value

A list with components:

model

A list containing information about the best evaluated model.

order

The order of moving average smoother provided or automatically selected.

ma

The simple moving average smoother of order order of the provided time series.

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 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.

MSE

Numeric value of the resulting MSE error of prediction. Require timeseries.test.

NMSE

Numeric value of the resulting NMSE error of prediction. Require timeseries.test.

MAPE

Numeric value of the resulting MAPE error of prediction. Require timeseries.test.

sMAPE

Numeric value of the resulting sMAPE error of prediction. Require timeseries.test.

MaxError

Numeric value of the maximal error of prediction. Require timeseries.test.

rank.val

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.

rank.by

Ranking criteria used for ranking candidate models and producing rank.val.

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

fittestEMD, fittestWavelet

Examples

1
2
3
4
5
6
data(CATS)

fMAS <- fittestMAS(CATS[,1],h=20,model="arima")

#automatically selected order of moving average
mas.order <- fMAS$order

RebeccaSalles/TSPred documentation built on April 6, 2021, 2:44 a.m.