Description Usage Arguments Details Value Author(s) References Examples

The function does rolling origin for any forecasting function

1 2 |

`data` |
Data vector or ts object passed to the function. |

`h` |
The forecasting horizon. |

`origins` |
The number of rolling origins. |

`call` |
The call that is passed to the function. The call must be in quotes.
Example: |

`value` |
The variable or set of variables returned by the |

`ci` |
The parameter defines if the in-sample window size should be constant.
If |

`co` |
The parameter defines whether the holdout sample window size should
be constant. If |

`silent` |
If |

`parallel` |
If |

`...` |
This is temporary and is needed in order to capture "silent" parameter if it is provided. |

This function produces rolling origin forecasts using the `data`

and a
`call`

passed as parameters. The function can do all of that either in
serial or in parallel, but it needs `foreach`

and either `doMC`

(Linux only), `doParallel`

or `doSNOW`

packages installed in order
to do the latter.

This is a dangerous function, so be careful with the call that you pass to it, and make sure that it is well formulated before the execution.

For more details and more examples of usage, please see vignette for the function.
In order to do that, just run the command: `vignette("ro","greybox")`

Function returns the following variables:

`actuals`

- the data provided to the function.`holdout`

- the matrix of actual values corresponding to the produced forecasts from each origin.`value`

- the matrices / array / lists with the produced data from each origin. Name of each object corresponds to the names in the parameter`value`

.

Yves Sagaert

Ivan Svetunkov, [email protected]

Tashman, (2000) Out-of-sample tests of forecasting accuracy: an analysis and review International Journal of Forecasting, 16, pp. 437-450. https://doi.org/10.1016/S0169-2070(00)00065-0.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | ```
x <- rnorm(100,0,1)
ourCall <- "predict(arima(x=data,order=c(0,1,1)),n.ahead=h)"
# The default call and values
ourValue <- "pred"
ourRO <- ro(x, h=5, origins=5, ourCall, ourValue)
# We can now plot the results of this evaluation:
plot(ourRO)
# You can also use dolar sign
ourValue <- "$pred"
# And you can have constant in-sample size
ro(x, h=5, origins=5, ourCall, ourValue, ci=TRUE)
# You can ask for several values
ourValue <- c("pred","se")
# And you can have constant holdout size
ro(x, h=5, origins=20, ourCall, ourValue, ci=TRUE, co=TRUE)
#### The following code will give exactly the same result as above,
#### but computed in parallel using all but 1 core of CPU:
## Not run: ro(x, h=5, origins=20, ourCall, ourValue, ci=TRUE, co=TRUE, parallel=TRUE)
#### If you want to use functions from forecast package, please note that you need to
#### set the values that need to be returned explicitly. There are two options for this.
# Example 1:
## Not run: ourCall <- "forecast(ets(data), h=h, level=95)"
ourValue <- c("mean", "lower", "upper")
ro(x,h=5,origins=5,ourCall,ourValue)
## End(Not run)
# Example 2:
## Not run: ourCall <- "forecast(ets(data), h=h, level=c(80,95))"
ourValue <- c("mean", "lower[,1]", "upper[,1]", "lower[,2]", "upper[,2]")
ro(x,h=5,origins=5,ourCall,ourValue)
## End(Not run)
#### A more complicated example using the for loop and
#### several time series
x <- matrix(rnorm(120*3,0,1), 120, 3)
## Form an array for the forecasts we will produce
## We will have 4 origins with 6-steps ahead forecasts
ourForecasts <- array(NA,c(6,4,3))
## Define models that need to be used for each series
ourModels <- list(c(0,1,1), c(0,0,1), c(0,1,0))
## This call uses specific models for each time series
ourCall <- "predict(arima(data, order=ourModels[[i]]), n.ahead=h)"
ourValue <- "pred"
## Start the loop. The important thing here is to use the same variable 'i' as in ourCall.
for(i in 1:3){
ourdata <- x[,i]
ourForecasts[,,i] <- ro(data=ourdata,h=6,origins=4,call=ourCall,
value=ourValue,co=TRUE,silent=TRUE)$pred
}
## ourForecasts array now contains rolling origin forecasts from specific
## models.
##### An example with exogenous variables
x <- rnorm(100,0,1)
xreg <- rnorm(100,0,1)
## 'counti' is used to define in-sample size of xreg,
## 'counto' - the size of the holdout sample of xreg
ourCall <- "predict(arima(x=data, order=c(0,1,1), xreg=xreg[counti]),
n.ahead=h, newxreg=xreg[counto])"
ourValue <- "pred"
ro(x,h=5,origins=5,ourCall,ourValue)
## 'countf' is used to take xreg of the size corresponding to the whole
## sample on each iteration
## This is useful when working with functions from smooth package.
## The following call will return the forecasts from es() function of smooth.
## Not run: ourCall <- "es(data=data, h=h, xreg=xreg[countf])"
ourValue <- "forecast"
ro(x,h=5,origins=5,ourCall,ourValue)
## End(Not run)
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.