An open API service indexing awesome lists of open source software.

https://github.com/andybega/ebmahelper

Regular S3 model fitting function and methods for EBMAforecast
https://github.com/andybega/ebmahelper

ebma ebma-forecast ensemble r stacking

Last synced: 5 months ago
JSON representation

Regular S3 model fitting function and methods for EBMAforecast

Awesome Lists containing this project

README

          

---
output:
md_document:
variant: markdown_github
---

```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```

# EBMAhelper

[![Travis build status](https://travis-ci.org/andybega/EBMAhelper.svg?branch=master)](https://travis-ci.org/andybega/EBMAhelper)
[![CRAN status](https://www.r-pkg.org/badges/version/EBMAhelper)](https://cran.r-project.org/package=EBMAhelper)
[![Coverage status](https://codecov.io/gh/andybega/EBMAhelper/branch/master/graph/badge.svg)](https://codecov.io/github/andybega/EBMAhelper?branch=master)

EBMAhelper is a wrapper around EBMAforecast ([CRAN](https://cran.r-project.org/web/packages/EBMAforecast/index.html), [GitHub](https://github.com/jmontgomery/EBMAforecast)) that provides some convenience functions more akin to R's conventional model-related functions:

- `ebma()` to create and fit an EBMA ensemble model; wraps `EBMAforecast::makeForecastData` and `EBMAforecast::calibrateEnsemble`
- `predict` method for the class "ebma" object returned by `ebma()`

and a standalone `predict()` (TODO) method to aggregate new forecasts.

## Installation

```{r installation, eval = FALSE}
library("devtools")

install_github("andybega/EBMAhelper")
```

## Example

A EBMA ensemble can be fitted like this:

```{r example}
suppressMessages({
library("EBMAforecast")
library("EBMAhelper")
})

data("presidentialForecast")

head(presidentialForecast)
str(presidentialForecast)

fitted_ensemble <- ebma(y = presidentialForecast[ ,7],
x = presidentialForecast[ ,c(1:6)],
model_type = "normal")
summary(fitted_ensemble)
```

To do the same with `EBMAforecast` is slightly more verbose and does not follow R's model fitting conventions. The following code is adapted from the package demo:

```{r}
data("presidentialForecast")

full.forecasts <- presidentialForecast[, c(1:6)]
full.observed <- presidentialForecast[, 7]

this.ForecastData <- makeForecastData(
.predCalibration=full.forecasts[1:12,],
.outcomeCalibration=full.observed[1:12],
.predTest=full.forecasts[13:15,],
.outcomeTest=full.observed[13:15],
.modelNames=c("Campbell", "Lewis-Beck","EWT2C2","Fair","Hibbs","Abramowitz"))
thisEnsemble <- calibrateEnsemble(this.ForecastData, model="normal",
useModelParams=FALSE, tol = 0.000000001,
const = 0)
summary(thisEnsemble)
```