predict.greybox: Forecasting using greybox functions

View source: R/methods.R

predict.almR Documentation

Forecasting using greybox functions

Description

The functions allow producing forecasts based on the provided model and newdata.

Usage

## S3 method for class 'alm'
predict(object, newdata = NULL, interval = c("none",
  "confidence", "prediction"), level = 0.95, side = c("both", "upper",
  "lower"), occurrence = NULL, ...)

## S3 method for class 'greybox'
predict(object, newdata = NULL, interval = c("none",
  "confidence", "prediction"), level = 0.95, side = c("both", "upper",
  "lower"), ...)

## S3 method for class 'scale'
predict(object, newdata = NULL, interval = c("none",
  "confidence", "prediction"), level = 0.95, side = c("both", "upper",
  "lower"), ...)

## S3 method for class 'greybox'
forecast(object, newdata = NULL, h = NULL, ...)

## S3 method for class 'alm'
forecast(object, newdata = NULL, h = NULL, ...)

Arguments

object

Time series model for which forecasts are required.

newdata

The new data needed in order to produce forecasts.

interval

Type of intervals to construct: either "confidence" or "prediction". Can be abbreviated

level

Confidence level. Defines width of prediction interval.

side

What type of interval to produce: "both" - produces both lower and upper bounds of the interval, "upper" - upper only, "lower" - respectively lower only. In the "both" case the probability is split into two parts: ((1-level)/2, (1+level)/2). When "upper" is specified, then the intervals for (0, level) are constructed Finally, with "lower" the interval for (1-level, 1) is returned.

occurrence

If occurrence was provided, then a user can provide a vector of future values via this variable.

...

Other arguments passed to vcov function (see coef.alm for details).

h

The forecast horizon.

Details

predict produces predictions for the provided model and newdata. If newdata is not provided, then the data from the model is extracted and the fitted values are reproduced. This might be useful when confidence / prediction intervals are needed for the in-sample values.

forecast function produces forecasts for h steps ahead. There are four scenarios in this function:

  1. If the newdata is not provided, then it will produce forecasts of the explanatory variables to the horizon h (using es from smooth package or using Naive if smooth is not installed) and use them as newdata.

  2. If h and newdata are provided, then the number of rows to use will be regulated by h.

  3. If h is NULL, then it is set equal to the number of rows in newdata.

  4. If both h and newdata are not provided, then it will use the data from the model itself, reproducing the fitted values.

After forming the newdata the forecast function calls for predict, so you can provide parameters interval, level and side in the call for forecast.

Value

predict.greybox() returns object of class "predict.greybox", which contains:

  • model - the estimated model.

  • mean - the expected values.

  • fitted - fitted values of the model.

  • lower - lower bound of prediction / confidence intervals.

  • upper - upper bound of prediction / confidence intervals.

  • level - confidence level.

  • newdata - the data provided in the call to the function.

  • variances - conditional variance for the holdout sample. In case of interval="prediction" includes variance of the error.

predict.alm() is based on predict.greybox() and returns object of class "predict.alm", which in addition contains:

  • location - the location parameter of the distribution.

  • scale - the scale parameter of the distribution.

  • distribution - name of the fitted distribution.

forecast() functions return the same "predict.alm" and "predict.greybox" classes, with the same set of output variables.

Author(s)

Ivan Svetunkov, ivan@svetunkov.com

See Also

predict.lm

Examples


xreg <- cbind(rlaplace(100,10,3),rnorm(100,50,5))
xreg <- cbind(100+0.5*xreg[,1]-0.75*xreg[,2]+rlaplace(100,0,3),xreg,rnorm(100,300,10))
colnames(xreg) <- c("y","x1","x2","Noise")
inSample <- xreg[1:80,]
outSample <- xreg[-c(1:80),]

ourModel <- alm(y~x1+x2, inSample, distribution="dlaplace")

predict(ourModel,outSample)
predict(ourModel,outSample,interval="c")

plot(predict(ourModel,outSample,interval="p"))
plot(forecast(ourModel,h=10,interval="p"))


config-i1/greybox documentation built on Dec. 12, 2024, 1:42 p.m.