diff --git a/DESCRIPTION b/DESCRIPTION index 0803232..c12b0ee 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: fiphde Title: Forecasting Influenza in Support of Public Health Decision Making -Version: 2.0.1 +Version: 2.0.2 Authors@R: c(person(given = "VP", family = "Nagraj", diff --git a/NEWS.md b/NEWS.md index 782bbb3..ec1bc16 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,11 @@ +# fiphde 2.0.2 + +## New features + +### NNETAR in ensemble + +As of this release, if the NNETAR model is specified in the `ts_fit_forecast()` function (i.e., "nnetar" is not `NULL` in the model list) then the model will be included in the ensemble. In previous releases, if the NNETAR method was used the results would be included in the returned forecast and fit objects but would not be ensembled with the other components. Note that currently *all* of the possible models (ARIMA, ETS, and NNETAR) must be specified to use the NNETAR in the ensemble. + # fiphde 2.0.1 ## Bug fixes diff --git a/R/fiphde-package.R b/R/fiphde-package.R index 8e7e14e..41f3c99 100644 --- a/R/fiphde-package.R +++ b/R/fiphde-package.R @@ -132,5 +132,6 @@ if(getRversion() >= "2.15.1") utils::globalVariables(c(".", "reference_date", "target_name", "target_prob", + "nnetar", ".")) diff --git a/R/forecast.R b/R/forecast.R index 9975b7e..f10018b 100644 --- a/R/forecast.R +++ b/R/forecast.R @@ -122,10 +122,13 @@ ts_fit_forecast <- function(prepped_tsibble, # e.g. if an ARIMA model doesn't fit for one location but the ETS does, you still want the ETS model for that location. tsfit <- purrr::reduce(tsfit, dplyr::inner_join, by="location") - # Ensemble the ARIMA and ETS models - # Hard-coded for now - can always ensemble other models if/when we add them. - # fixme: this could be more flexible - if (ensemble & !is.null(models$arima) & !is.null(models$ets)) { + # Ensemble the models + # TODO: make this more flexible and not hard-coded in the future? + if (ensemble & !is.null(models$arima) & !is.null(models$ets) & !is.null(models$nnetar)) { + tsfit <- + tsfit %>% + dplyr::mutate(ensemble=(arima+ets+nnetar)/3) + } else if (ensemble & !is.null(models$arima) & !is.null(models$ets)) { tsfit <- tsfit %>% dplyr::mutate(ensemble=(arima+ets)/2)