Error(s) in re-building vignettes:
  ...
--- re-building ‘opera-vignette.Rmd’ using rmarkdown
** Processing: /home/hornik/tmp/R.check/r-devel-gcc/Work/PKGS/opera.Rcheck/vign_test/opera/vignettes/opera-vignette_files/figure-html/Load-1.png
576x384 pixels, 8 bits/pixel, 256 colors in palette
Reducing image to 8 bits/pixel, grayscale
Input IDAT size = 19464 bytes
Input file size = 20346 bytes

Trying:
  zc = 9  zm = 8  zs = 0  f = 0		IDAT size = 18426
  zc = 9  zm = 8  zs = 1  f = 0		IDAT size = 18337
  zc = 1  zm = 8  zs = 2  f = 0
  zc = 9  zm = 8  zs = 3  f = 0
  zc = 9  zm = 8  zs = 0  f = 5		IDAT size = 15447
  zc = 9  zm = 8  zs = 1  f = 5		IDAT size = 15343
  zc = 1  zm = 8  zs = 2  f = 5
  zc = 9  zm = 8  zs = 3  f = 5
                               
Selecting parameters:
  zc = 9  zm = 8  zs = 1  f = 5		IDAT size = 15343

Output IDAT size = 15343 bytes (4121 bytes decrease)
Output file size = 15421 bytes (4925 bytes = 24.21% decrease)

** Processing: /home/hornik/tmp/R.check/r-devel-gcc/Work/PKGS/opera.Rcheck/vign_test/opera/vignettes/opera-vignette_files/figure-html/Temp-1.png
576x384 pixels, 8 bits/pixel, 254 colors in palette
Reducing image to 8 bits/pixel, grayscale
Input IDAT size = 7902 bytes
Input file size = 8754 bytes

Trying:
  zc = 9  zm = 8  zs = 0  f = 0		IDAT size = 7140
  zc = 9  zm = 8  zs = 1  f = 0		IDAT size = 7112
  zc = 1  zm = 8  zs = 2  f = 0
  zc = 9  zm = 8  zs = 3  f = 0
  zc = 9  zm = 8  zs = 0  f = 5
  zc = 9  zm = 8  zs = 1  f = 5
  zc = 1  zm = 8  zs = 2  f = 5
  zc = 9  zm = 8  zs = 3  f = 5
                               
Selecting parameters:
  zc = 9  zm = 8  zs = 1  f = 0		IDAT size = 7112

Output IDAT size = 7112 bytes (790 bytes decrease)
Output file size = 7190 bytes (1564 bytes = 17.87% decrease)

** Processing: /home/hornik/tmp/R.check/r-devel-gcc/Work/PKGS/opera.Rcheck/vign_test/opera/vignettes/opera-vignette_files/figure-html/NumWeek-1.png
576x384 pixels, 8 bits/pixel, 255 colors in palette
Reducing image to 8 bits/pixel, grayscale
Input IDAT size = 7753 bytes
Input file size = 8608 bytes

Trying:
  zc = 9  zm = 8  zs = 0  f = 0		IDAT size = 6848
  zc = 9  zm = 8  zs = 1  f = 0		IDAT size = 6822
  zc = 1  zm = 8  zs = 2  f = 0
  zc = 9  zm = 8  zs = 3  f = 0
  zc = 9  zm = 8  zs = 0  f = 5
  zc = 9  zm = 8  zs = 1  f = 5
  zc = 1  zm = 8  zs = 2  f = 5
  zc = 9  zm = 8  zs = 3  f = 5
                               
Selecting parameters:
  zc = 9  zm = 8  zs = 1  f = 0		IDAT size = 6822

Output IDAT size = 6822 bytes (931 bytes decrease)
Output file size = 6900 bytes (1708 bytes = 19.84% decrease)



`opera` is a R package that provides several algorithms to perform robust online prediction of time series with the help of expert advice. In this vignette, we provide an example of how to use the package. 

## Setting: when is the package `opera` useful?
Consider a sequence of real bounded observations $y_1,\dots,y_n$ to be predicted step by step. Suppose that you have at your disposal a finite set of methods $k =1,\dots,K$ (henceforth referred to as experts) that provide you before each time step $t=1,\dots,n$ predictions $x_{k,t}$ of the next observation $y_t$. You can form your prediction $\widehat y_t$ by using only the knowledge of the past observations $y_1,\dots,y_{t-1}$ and past and current expert forecasts $x_{k,1},\dots,x_{k,t}$ for $k=1,\dots,K$. The package <a href=#>opera</a> implements several algorithms of the online learning literature that form predictions $\widehat y_t$ by combining the expert forecasts according to their past performance. That is,

<p align='center'></p>

<p align='center'><p align="center">
<img src="../man/figures/formula.png" width="20%" style="display: block; margin: auto;" />
</p></p>

These algorithms come with finite time worst-case guarantees. The monograph of [Cesa-Bianchi and Lugisi (2006)][Cesa-BianchiLugosi2006] gives a complete introduction to the setting of prediction of arbitrary sequences with the help of expert advice.


### What are the most important functions?

The package `opera` provides three important functions: `mixture` to build the algorithm object, `predict` to make a prediction by using the algorithm, and `oracle` to evaluate the performance of the experts and compare the performance of the combining algorithm.

## Installation
opera is now available on CRAN, so you can install it with:
<p align='center'>

``` r
install.packages("opera")
```

</p>
You can also install the development version of opera with the package devtools:
<p align='center'>

``` r
install.packages("devtools")
devtools::install_github("dralliag/opera")
```

</p>
You may be asked to install additional necessary packages. You can install the package vignette by setting the option: build_vignettes = TRUE.

## Example: predict the weekly electricity consumption.

Here, we provide a concrete example on how to use the package.
To do so, we consider an electricity forecasting data set that
includes weekly observations of the French electric load together
with several covariates: the temperature, calendar information,
and industrial production indexes. The data set is provided by 
the French [National Institute of Statistics and Economic Studies (Insee)][Insee].

<p align='center'>

``` r
library(opera)
set.seed(1)
```

</p>

### The data set

First, we load the data and we cut it into two subsets: a training set used to build the experts (base forecasting methods) and a testing set (here the last two years) used to evaluate the performance and to run the combining algorithms. 



<p align='center'>

``` r
data(electric_load)
attach(electric_load)
idx_data_test <- 620:nrow(electric_load)
data_train <- electric_load[-idx_data_test, ] 
data_test <- electric_load[idx_data_test, ]  
```

</p>

The data is displayed in the following figures.

<p align='center'>

``` r
plot(Load, type = "l", main = "The electric Load")
```

</p>
<p align='center'><img src="/home/hornik/tmp/R.check/r-devel-gcc/Work/PKGS/opera.Rcheck/vign_test/opera/vignettes/opera-vignette_files/figure-html/Load-1.png" width="50%" /></p>

<p align='center'>

``` r
plot(Temp, Load, pch = 16, cex = 0.5, main = "Temperature vs Load")
```

</p>
<p align='center'><img src="/home/hornik/tmp/R.check/r-devel-gcc/Work/PKGS/opera.Rcheck/vign_test/opera/vignettes/opera-vignette_files/figure-html/Temp-1.png" width="50%" /></p>

<p align='center'>

``` r
plot(NumWeek, Load, pch = 16, cex = 0.5, main = "Annual seasonality")
```

</p>
<p align='center'><img src="/home/hornik/tmp/R.check/r-devel-gcc/Work/PKGS/opera.Rcheck/vign_test/opera/vignettes/opera-vignette_files/figure-html/NumWeek-1.png" width="50%" /></p>

### First: build the expert forecasts

Here, we build three base forecasting methods to be combined later. 

* A generalized additive model using the `mgcv` package:
  
<p align='center'>

``` r
library(mgcv)
gam.fit <- gam(Load ~ s(IPI) + s(Temp) + s(Time, k=3) + 
                 s(Load1) + as.factor(NumWeek), data = data_train)
gam.forecast <- predict(gam.fit, newdata = data_test)
```

</p>

*  A medium term generalized additive model followed by an autoregressive short-term correction.
<p align='center'>

``` r
# medium term model
medium.fit <- gam(Load ~ s(Time,k=3) + s(NumWeek) + s(Temp) + s(IPI), data = data_train)
electric_load$Medium <- c(predict(medium.fit), predict(medium.fit, newdata = data_test))
electric_load$Residuals <- electric_load$Load - electric_load$Medium

# autoregressive correction
ar.forecast <- numeric(length(idx_data_test))
for (i in seq(idx_data_test)) {
  ar.fit <- ar(electric_load$Residuals[1:(idx_data_test[i] - 1)])
  ar.forecast[i] <- as.numeric(predict(ar.fit)$pred) + electric_load$Medium[idx_data_test[i]]
}
```

</p>

* A gradient boosting model using `caret` package

















































Quitting from lines 118-121 [gbm] (./../inst/rmd/example.Rmd)

Quitting from lines 48-48 [unnamed-chunk-2] (opera-vignette.Rmd)
Error: processing vignette 'opera-vignette.Rmd' failed with diagnostics:
there is no package called 'caret'
--- failed re-building ‘opera-vignette.Rmd’

--- re-building ‘regional_forecasting.Rmd’ using rmarkdown
** Processing: /home/hornik/tmp/R.check/r-devel-gcc/Work/PKGS/opera.Rcheck/vign_test/opera/vignettes/regional_forecasting_files/figure-html/unnamed-chunk-2-1.png
681x528 pixels, 3x8 bits/pixel, RGB
Input IDAT size = 159410 bytes
Input file size = 159716 bytes

Trying:
  zc = 9  zm = 8  zs = 0  f = 0
  zc = 9  zm = 8  zs = 1  f = 0
  zc = 1  zm = 8  zs = 2  f = 0
  zc = 9  zm = 8  zs = 3  f = 0
  zc = 9  zm = 8  zs = 0  f = 5		IDAT size = 156679
  zc = 9  zm = 8  zs = 1  f = 5		IDAT size = 155706
  zc = 1  zm = 8  zs = 2  f = 5
  zc = 9  zm = 8  zs = 3  f = 5
                               
Selecting parameters:
  zc = 9  zm = 8  zs = 1  f = 5		IDAT size = 155706

Output IDAT size = 155706 bytes (3704 bytes decrease)
Output file size = 155784 bytes (3932 bytes = 2.46% decrease)

** Processing: /home/hornik/tmp/R.check/r-devel-gcc/Work/PKGS/opera.Rcheck/vign_test/opera/vignettes/regional_forecasting_files/figure-html/unnamed-chunk-3-1.png
681x528 pixels, 3x8 bits/pixel, RGB
Input IDAT size = 57270 bytes
Input file size = 57420 bytes

Trying:
  zc = 9  zm = 8  zs = 0  f = 0
  zc = 9  zm = 8  zs = 1  f = 0
  zc = 1  zm = 8  zs = 2  f = 0
  zc = 9  zm = 8  zs = 3  f = 0
  zc = 9  zm = 8  zs = 0  f = 5		IDAT size = 52261
  zc = 9  zm = 8  zs = 1  f = 5
  zc = 1  zm = 8  zs = 2  f = 5
  zc = 9  zm = 8  zs = 3  f = 5
                               
Selecting parameters:
  zc = 9  zm = 8  zs = 0  f = 5		IDAT size = 52261

Output IDAT size = 52261 bytes (5009 bytes decrease)
Output file size = 52339 bytes (5081 bytes = 8.85% decrease)

Warning in doTryCatch(return(expr), name, parentenv, handler) :
  argument 1 does not name a graphical parameter
** Processing: /home/hornik/tmp/R.check/r-devel-gcc/Work/PKGS/opera.Rcheck/vign_test/opera/vignettes/regional_forecasting_files/figure-html/unnamed-chunk-8-1.png
681x528 pixels, 3x8 bits/pixel, RGB
Input IDAT size = 85056 bytes
Input file size = 85254 bytes

Trying:
  zc = 9  zm = 8  zs = 0  f = 0		IDAT size = 68440
  zc = 9  zm = 8  zs = 1  f = 0
  zc = 1  zm = 8  zs = 2  f = 0
  zc = 9  zm = 8  zs = 3  f = 0
  zc = 9  zm = 8  zs = 0  f = 5
  zc = 9  zm = 8  zs = 1  f = 5
  zc = 1  zm = 8  zs = 2  f = 5
  zc = 9  zm = 8  zs = 3  f = 5
                               
Selecting parameters:
  zc = 9  zm = 8  zs = 0  f = 0		IDAT size = 68440

Output IDAT size = 68440 bytes (16616 bytes decrease)
Output file size = 68518 bytes (16736 bytes = 19.63% decrease)

** Processing: /home/hornik/tmp/R.check/r-devel-gcc/Work/PKGS/opera.Rcheck/vign_test/opera/vignettes/regional_forecasting_files/figure-html/unnamed-chunk-9-1.png
681x528 pixels, 8 bits/pixel, 256 colors in palette
Reducing image to 8 bits/pixel, grayscale
Input IDAT size = 7585 bytes
Input file size = 8443 bytes

Trying:
  zc = 9  zm = 8  zs = 0  f = 0		IDAT size = 6470
  zc = 9  zm = 8  zs = 1  f = 0
  zc = 1  zm = 8  zs = 2  f = 0
  zc = 9  zm = 8  zs = 3  f = 0
  zc = 9  zm = 8  zs = 0  f = 5
  zc = 9  zm = 8  zs = 1  f = 5
  zc = 1  zm = 8  zs = 2  f = 5
  zc = 9  zm = 8  zs = 3  f = 5
                               
Selecting parameters:
  zc = 9  zm = 8  zs = 0  f = 0		IDAT size = 6470

Output IDAT size = 6470 bytes (1115 bytes decrease)
Output file size = 6548 bytes (1895 bytes = 22.44% decrease)

--- finished re-building ‘regional_forecasting.Rmd’

SUMMARY: processing the following file failed:
  ‘opera-vignette.Rmd’

Error: Vignette re-building failed.
Execution halted