Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge to update branch #72

Merged
merged 71 commits into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
6012843
created test directory and dependency (Suggests) to testthat
Apr 13, 2020
288135e
Start unit tests for group3 functions defined by Nath
andreamrau Apr 14, 2020
ec8f3db
created a test file for "evaluate_model"
Apr 15, 2020
7ed4787
forecast_cases() unit test draft
Apr 18, 2020
cd83999
fixed a typo in tests of "forecast_cases"
Apr 21, 2020
8f99d29
tests(evaluate model): improved verbose
Apr 21, 2020
b008998
added a test file for 'compare_models'
Apr 21, 2020
08e1245
added a test file for 'compare_timeseries'
Apr 21, 2020
6cdf346
added a test file for 'summarise_scores'
Apr 21, 2020
92ceb06
Add forecast_rt tests
andreamrau Apr 22, 2020
7a1d5c6
added the tests for the group 1 functions
achateigner Apr 22, 2020
2d0dd7e
Add iterative_rt_forecast tests
andreamrau Apr 22, 2020
b6b6583
corrected the as_tibble bug
achateigner Apr 22, 2020
60a9757
added a test file for 'plot_forecast'
Apr 22, 2020
087025a
added a test for 'plot_forecast_evaluation'
Apr 22, 2020
43dabb8
Add score_forecast tests
andreamrau Apr 22, 2020
524b2dd
Add score_case_forecast tests
andreamrau Apr 23, 2020
32a92a4
Unit tests group 2
maressyl Apr 26, 2020
f607575
fixed a bug in test_plot_forecast
Apr 27, 2020
a13bbba
changed a file name to avoid possible problems with brackets
Apr 27, 2020
b752f73
split testGroup1 into separated files + translated comments in English
Apr 27, 2020
2425fae
commented lines that possibly make the tests fail depending on random…
Apr 27, 2020
62ecdbd
move (almost) all comments in tests to github issues
Apr 27, 2020
5d10adc
Fix bugs in test_score_forecast and test_score_case_forecast
andreamrau Apr 27, 2020
fa71811
added codecov support
Apr 28, 2020
7c46479
Aurelien: changed the way I tested the results, as long as I cannot f…
Apr 29, 2020
97f9dfb
added first hack at brms wrapper
medewitt Apr 30, 2020
56c0c61
added github actions
medewitt Apr 30, 2020
dc236e1
minor additions in tests (testing number of rows in outputs)
Apr 30, 2020
cd44d99
removed codecov check
Apr 30, 2020
4ba5c7a
fixed missing globals and missing brms arguments in example
medewitt Apr 30, 2020
457067d
pesky mac
medewitt Apr 30, 2020
363e47e
Update check-full.yaml
medewitt Apr 30, 2020
cb3601e
update R versions
medewitt Apr 30, 2020
637b224
updated docs to allow links to packages described in function descrip…
medewitt May 2, 2020
c79e495
fixed links in some of the documentation. additionally moved brms and…
medewitt May 2, 2020
9bc4c4c
don't run brms example
medewitt May 2, 2020
70c434e
remove import of brms functions to pass checks
medewitt May 2, 2020
9e30ec0
I think I have all the dependency stuff figured out with move to sugg…
medewitt May 2, 2020
143bafd
fixed missing link in documentation. seems to pass all checks locally
medewitt May 2, 2020
44a506b
Merge pull request #45 from tuxette/testthat
seabbs May 4, 2020
dd10d5a
removed codecov check
Apr 30, 2020
ea104e8
Merge branch 'testthat'
May 5, 2020
871140a
added contributors in DESCRIPTION
May 5, 2020
6d0ed94
Merge pull request #48 from tuxette/master
seabbs May 14, 2020
4381eed
Merge branch 'master' into master
seabbs May 14, 2020
83ef4b0
Merge pull request #46 from medewitt/master
seabbs May 14, 2020
6fe477d
Update DESCRIPTION
seabbs May 14, 2020
7d37614
Update DESCRIPTION
seabbs May 14, 2020
84b8ac3
Merge pull request #1 from epiforecasts/master
medewitt May 14, 2020
92bb7a1
first part of the infrastrture. Need the gh-pages orphan branch
May 14, 2020
c2aadb4
added my credentials as contributor
May 14, 2020
405c3dd
Update DESCRIPTION
seabbs May 15, 2020
f0b3962
move bsts to suggests
seabbs May 15, 2020
44292ba
move all fable to suggests
seabbs May 15, 2020
87f4e34
tests passing
seabbs May 15, 2020
8d62021
first pass at forecastHybrid
seabbs May 15, 2020
dde67e4
Merge pull request #61 from medewitt/add-md
seabbs May 15, 2020
bdd0a14
Merge pull request #62 from medewitt/add-gha
seabbs May 15, 2020
aa03f6c
simple sampler for forecastHybrid
seabbs May 15, 2020
576ba3c
update readme
seabbs May 15, 2020
3daa362
Update forecastHybrid_model.R
seabbs May 15, 2020
3b1f135
Merge pull request #63 from epiforecasts/add_forecastHybrid
seabbs May 15, 2020
05983ae
Merge pull request #65 from epiforecasts/update_readme
seabbs May 15, 2020
04da868
changed to work with the mean calculated by forecastHybrid instead of…
nikosbosse May 15, 2020
d998d51
Merge pull request #66 from epiforecasts/change_mean_forecastHybrid
seabbs May 15, 2020
e3cdb3e
first attempt at blocking hybrid from usign multplec oers
seabbs May 15, 2020
0b72e13
Updated check_suggest to allow for custom dev messages for packages n…
nikosbosse May 15, 2020
e1234f4
Merge pull request #67 from epiforecasts/update_check_suggest
seabbs May 15, 2020
c478eb5
added new ensemble method
seabbs May 15, 2020
5e8d2ec
Merge pull request #69 from epiforecasts/stop_parallel_hybrid
seabbs May 15, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@
^.cache$
^inst/pkg-structure$
^_pkgdown.yml$
^\.github$
^_pkgdown\.yml$
^pkgdown$
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
85 changes: 85 additions & 0 deletions .github/workflows/check-full.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
on:
push:
branches:
- master
pull_request:
branches:
- master

name: R-CMD-check

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: macOS-latest, r: 'devel'}
- {os: macOS-latest, r: '4.0'}
- {os: windows-latest, r: '4.0'}
- {os: ubuntu-16.04, r: '4.0', rspm: "https://demo.rstudiopm.com/all/__linux__/xenial/latest"}
- {os: ubuntu-16.04, r: '3.6', rspm: "https://demo.rstudiopm.com/all/__linux__/xenial/latest"}
- {os: ubuntu-16.04, r: '3.5', rspm: "https://demo.rstudiopm.com/all/__linux__/xenial/latest"}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: ${{ matrix.config.rspm }}

steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-r@master
with:
r-version: ${{ matrix.config.r }}

- uses: r-lib/actions/setup-pandoc@master

- name: Query dependencies
run: |
install.packages('remotes')
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
shell: Rscript {0}

- name: Cache R packages
if: runner.os != 'Windows'
uses: actions/cache@v1
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-r-${{ matrix.config.r }}-1-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ runner.os }}-r-${{ matrix.config.r }}-1-

- name: Install system dependencies
if: runner.os == 'Linux'
env:
RHUB_PLATFORM: linux-x86_64-ubuntu-gcc
run: |
sudo add-apt-repository -y "ppa:marutter/rrutter3.5"
sudo add-apt-repository -y "ppa:marutter/c2d4u3.5"
sudo apt update
sudo apt install r-cran-rstan
Rscript -e "remotes::install_github('r-hub/sysreqs')"
sysreqs=$(Rscript -e "cat(sysreqs::sysreq_commands('DESCRIPTION'))")
sudo -s eval "$sysreqs"

- name: Install dependencies
run: |
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("rcmdcheck")
shell: Rscript {0}

- name: Check
env:
_R_CHECK_CRAN_INCOMING_: false
run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check")
shell: Rscript {0}

- name: Upload check results
if: failure()
uses: actions/upload-artifact@master
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check
44 changes: 44 additions & 0 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
on:
push:
branches: master

name: pkgdown

jobs:
pkgdown:
runs-on: macOS-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-r@master

- uses: r-lib/actions/setup-pandoc@master

- name: Query dependencies
run: |
install.packages('remotes')
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
shell: Rscript {0}

- name: Cache R packages
uses: actions/cache@v1
with:
path: ${{ env.R_LIBS_USER }}
key: macOS-r-4.0-1-${{ hashFiles('.github/depends.Rds') }}
restore-keys: macOS-r-4.0-1-

- name: Install dependencies
run: |
install.packages("remotes")
remotes::install_deps(dependencies = TRUE)
remotes::install_dev("pkgdown")
shell: Rscript {0}

- name: Install package
run: R CMD INSTALL .

- name: Deploy package
run: pkgdown::deploy_to_branch(new_process = FALSE)
shell: Rscript {0}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
.RData
.Rproj.user
inst/doc
.DS_Store
docs
41 changes: 31 additions & 10 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ Authors@R: c(
role = c("aut", "cre"),
email = "[email protected]",
comment = c(ORCID = "0000-0001-8057-8037")),
person("Joel", "Hellewell",
email = "[email protected]",
role = c("aut"),
comment = c(ORCID = "0000-0003-2683-0849")),
person(given = "Nikos",
family = "Bosse",
role = c("aut"),
email = "[email protected]"),
person("Joel", "Hellewell",
email = "[email protected]",
role = c("aut"),
comment = c(ORCID = "0000-0003-2683-0849")),
person("Katharine", "Sherratt",
email = "[email protected]",
role = c("aut")),
Expand All @@ -24,24 +24,38 @@ Authors@R: c(
person("Robin", "Thompson",
email = "[email protected]",
role = c("aut")),
person("Aurelien", "Chateigner",
email = "[email protected]",
role = c("aut")),
person("Sylvain", "Mareschal",
email = "[email protected]",
role = c("aut")),
person("Andrea", "Rau",
email = "[email protected]",
role = c("aut")),
person("Nathalie", "Vialaneix",
email = "[email protected]",
role = c("aut")),
person(given = "Michael",
family = "DeWitt",
role = c("aut"),
email = "[email protected]",
comment = c(ORCID = "0000-0001-8940-1967")),
person("Sebastian", "Funk",
email = "[email protected]",
role = c("aut")))
Description: To forecast the time-varying reproduction number and using this to forecast reported case counts. Includes
Description: To forecast the time-varying reproduction number and use this to forecast reported case counts. Includes
tools to evaluate a range of models across samples and time series using proper scoring rules.
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.0.2
RoxygenNote: 7.1.0
Depends:
R (>= 3.3.0)
Imports:
scoringutils,
scoringRules,
bsts,
fabletools,
tsibble,
purrr,
furrr,
magrittr,
Expand All @@ -60,7 +74,14 @@ Remotes:
Suggests:
knitr,
rmarkdown,
fabletools,
tsibble,
forecastHybrid,
fable,
bsts,
feasts,
future.apply
future.apply,
brms,
tidybayes,
testthat
VignetteBuilder: knitr
15 changes: 10 additions & 5 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Generated by roxygen2: do not edit by hand

export("%>%")
export(brms_model)
export(bsts_model)
export(compare_models)
export(compare_timeseries)
export(draw_from_si_prob)
export(evaluate_model)
export(fable_model)
export(forecastHybrid_model)
export(forecast_cases)
export(forecast_rt)
export(iterative_case_forecast)
Expand All @@ -23,10 +25,10 @@ export(summarise_forecast)
export(summarise_scores)
importFrom(HDInterval,hdi)
importFrom(R.utils,withTimeout)
importFrom(bsts,bsts)
importFrom(bsts,predict.bsts)
importFrom(cowplot,theme_cowplot)
importFrom(data.table,`:=`)
importFrom(dplyr,arrange)
importFrom(dplyr,bind_cols)
importFrom(dplyr,bind_rows)
importFrom(dplyr,filter)
importFrom(dplyr,group_by)
Expand All @@ -40,8 +42,6 @@ importFrom(dplyr,select_if)
importFrom(dplyr,slice)
importFrom(dplyr,summarise)
importFrom(dplyr,ungroup)
importFrom(fabletools,forecast)
importFrom(fabletools,model)
importFrom(furrr,future_map)
importFrom(furrr,future_pmap)
importFrom(ggplot2,aes)
Expand All @@ -67,9 +67,14 @@ importFrom(scoringutils,bias)
importFrom(scoringutils,interval_score)
importFrom(scoringutils,pit)
importFrom(scoringutils,sharpness)
importFrom(stats,median)
importFrom(stats,quantile)
importFrom(stats,rpois)
importFrom(stats,rt)
importFrom(stats,sd)
importFrom(stats,setNames)
importFrom(tibble,tibble)
importFrom(tidyr,expand_grid)
importFrom(tidyr,gather)
importFrom(tidyr,spread)
importFrom(tidyr,unnest)
importFrom(tsibble,tsibble)
76 changes: 76 additions & 0 deletions R/brms_model.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#' brms model wrapper
#'
#' Allows users to specify a model using the [brms::bf()] wrapper from `brms`
#' Note that `brms` and `tidybayes` must both be installed for this
#' model wrapper to be functional.
#'
#' @param y Numeric vector of time points to forecast
#' @param samples Numeric, number of samples to take.
#' @param model A `brms` model wrapped in the [brms::bf()] function
#' @param horizon Numeric, the time horizon over which to predict.
#' @param n_cores Numeric, the number of cores to use, default of 1
#' @param n_chains Numeric, the number of chains to use, default of 4
#' @param n_iter Numeric, the number of iterations in the sampler to use,
#' default of 4000
#' @param ... additional arguments passed to `brms` (e.g. priors or family)
#' @return A dataframe of predictions (with columns representing the time horizon and rows representing samples).
#' @export
#' @importFrom data.table `:=`
#' @examples \dontrun{
#'
#' ## Used on its own
#' ## Note: More iterations and chains should be used
#' library(brms)
#'brms_model(y = EpiSoon::example_obs_rts[1:10, ]$rt,
#' model = brms::bf(y ~ gp(time)),
#' samples = 10, horizon = 7, n_iter = 40, n_chains = 1, refresh =0)
#'
#' ## Used for forecasting
#' ## Note that the timeout parameter has been increased to allow
#' ## for the time for the code to be compiled
#' ## Note: More iterations and chains should be used
#'
#' forecast_rt(EpiSoon::example_obs_rts[1:10, ],
#' model = function(...){
#' brms_model(model = brms::bf(y ~ gp(time)), n_iter = 40, n_chains = 1, ...)},
#' horizon = 7, samples = 10, timeout = 300)
#'}

brms_model <- function(y = NULL, samples = NULL,
horizon = NULL, model = NULL, n_cores = 1,
n_chains = 4, n_iter = 2000, ...) {

check_suggests("brms")
check_suggests("tidybayes")
check_suggests("tsibble")

## Make input numeric into correct tsibble format
timeseries <- tsibble::tsibble(y = y, time = 1:length(y), index = time)

## Fit the model
fit <- brms::brm(formula = model, data = timeseries,
chains = n_chains, iter = n_iter,
cores = n_cores, ...)

# Create Prediction Data Frame
dat_new <- data.frame(time = (length(y)+1):(length(y)+horizon))

prediction <- tidybayes::add_fitted_draws(newdata = dat_new,
model = fit, n = samples)

prediction <- dplyr::mutate(prediction, row_id = dplyr::row_number())

prediction <- dplyr::ungroup(prediction)

prediction <- data.table::as.data.table(prediction)

prediction <- data.table::dcast(prediction, row_id~time, value.var = ".value")

prediction <- prediction[,row_id:=NULL]

## Extract samples and tidy format
samples <- as.data.frame(prediction)

return(samples)

}
14 changes: 7 additions & 7 deletions R/bsts_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
#' @param horizon Numeric, the time horizon over which to predict.
#' @return A dataframe of predictions (with columns representing the time horizon and rows representing samples).
#' @export
#' @importFrom bsts bsts predict.bsts
#' @examples
#' @examples \dontrun{
#'
#' library(bsts)
#'
#' ## Used on its own
#' bsts_model(y = EpiSoon::example_obs_rts[1:10, ]$rt,
Expand All @@ -21,10 +22,14 @@
#' function(ss, y){
#' bsts::AddAr(ss, y = y, lags = 3)}, ...)},
#' horizon = 7, samples = 10)
#'}
bsts_model <- function(y = NULL, samples = NULL,
horizon = NULL, model = NULL) {


check_suggests("bsts")


model <- model(list(), y)

## Fit the model
Expand All @@ -44,9 +49,4 @@ bsts_model <- function(y = NULL, samples = NULL,

return(samples)






}
Loading