-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added extra.R to ensure document() builds ok
- Loading branch information
Showing
16 changed files
with
420 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
^pkgdown$ | ||
^\.github$ | ||
^vignettes/articles$ | ||
^README\.Rmd$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples | ||
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help | ||
on: | ||
push: | ||
branches: [main, master] | ||
pull_request: | ||
branches: [main, master] | ||
|
||
name: test-coverage.yaml | ||
|
||
permissions: read-all | ||
|
||
jobs: | ||
test-coverage: | ||
runs-on: ubuntu-latest | ||
env: | ||
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: r-lib/actions/setup-r@v2 | ||
with: | ||
use-public-rspm: true | ||
|
||
- uses: r-lib/actions/setup-r-dependencies@v2 | ||
with: | ||
extra-packages: any::covr, any::xml2 | ||
needs: coverage | ||
|
||
- name: Test coverage | ||
run: | | ||
cov <- covr::package_coverage( | ||
quiet = FALSE, | ||
clean = FALSE, | ||
exclusions <- "src/stanExports_epifilter_covariates.h|src/stanExports_epifilter.h" | ||
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package") | ||
) | ||
covr::to_cobertura(cov) | ||
shell: Rscript {0} | ||
|
||
- uses: codecov/codecov-action@v4 | ||
with: | ||
fail_ci_if_error: ${{ github.event_name != 'pull_request' && true || false }} | ||
file: ./cobertura.xml | ||
plugin: noop | ||
disable_search: true | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
|
||
- name: Show testthat output | ||
if: always() | ||
run: | | ||
## -------------------------------------------------------------------- | ||
find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true | ||
shell: bash | ||
|
||
- name: Upload test results | ||
if: failure() | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: coverage-test-failures | ||
path: ${{ runner.temp }}/package |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(fit_epifilter) | ||
export(fit_epifilter_covariates) | ||
export(simulate_renewal_epidemic) | ||
exportPattern("^[[:alpha:]]+") | ||
import(Rcpp) | ||
import(methods) | ||
importFrom(rstan,sampling) | ||
useDynLib(epidp, .registration = TRUE) | ||
useDynLib(epidp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#' @useDynLib epidp | ||
#' @import Rcpp | ||
#' @import methods | ||
#' @importFrom rstan sampling | ||
#' @exportPattern "^[[:alpha:]]+" | ||
NULL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
--- | ||
output: github_document | ||
--- | ||
|
||
<!-- README.md is generated from README.Rmd. Please edit that file --> | ||
|
||
```{r, include = FALSE} | ||
knitr::opts_chunk$set( | ||
collapse = TRUE, | ||
comment = "#>", | ||
fig.path = "man/figures/README-", | ||
out.width = "100%" | ||
) | ||
``` | ||
|
||
# epidp | ||
|
||
<!-- badges: start --> | ||
[![codecov](https://codecov.io/github/ben18785/epidp/graph/badge.svg?token=STG0INT235)](https://codecov.io/github/ben18785/epidp) | ||
<!-- badges: end --> | ||
|
||
The goal of `epidp` is to allow covariate information to inform estimates of the time-varying reproduction number, $R_t$. | ||
|
||
## Installation | ||
|
||
You can install the development version of epidp from [GitHub](https://github.com/) with: | ||
|
||
``` r | ||
# install.packages("devtools") | ||
devtools::install_github("ben18785/epidp") | ||
``` | ||
|
||
## Example | ||
### Step function in $R_t$ | ||
We first generate case data assuming a step function for $R_t$. | ||
```{r} | ||
library(epidp) | ||
library(ggplot2) | ||
library(dplyr) | ||
library(magrittr) | ||
library(purrr) | ||
library(tidyr) | ||
rt_fun = function(t){ | ||
if(t <= 60) | ||
R = 2 | ||
else if (t <= 90) | ||
R = 0.5 | ||
else | ||
R = 1 | ||
R | ||
} | ||
# simulation parameters | ||
nt <- 200 | ||
mean_si <- 6.5 | ||
sd_si <- 4.03 | ||
i_0 <- 10 | ||
# data frame of outputs | ||
epidemic_df <- simulate_renewal_epidemic(rt_fun, nt, mean_si, sd_si, i_0) | ||
# plot | ||
transform_factor <- 300 | ||
epidemic_df %>% | ||
select(-c(w_dist, lambda_t)) %>% | ||
mutate(R_t = R_t * transform_factor) %>% | ||
pivot_longer(c(i_t, R_t)) %>% | ||
ggplot(aes(x = t, y = value, colour = name)) + | ||
geom_line() + | ||
scale_y_continuous( | ||
name = "Incidence (i_t)", | ||
sec.axis = sec_axis(~ . / transform_factor, name = "Reproduction Number (R_t)") | ||
) + | ||
labs(x = "Time") + | ||
theme_minimal() + | ||
scale_color_brewer("Series", palette = "Dark2") | ||
``` | ||
|
||
We now use a Stan version of EpiFilter to estimate the maximum a posteriori estimates | ||
of $R_t$ and overlay these on top of the actual values. Note, these estimates do | ||
not have uncertainty associated with them but the benefit of this is that estimation | ||
is instantaneous. The estimates are close to the actual $R_t$ values after an initial | ||
period when case counts are low. | ||
```{r} | ||
# fit model | ||
fit <- fit_epifilter( | ||
N=length(epidemic_df$i_t), | ||
C=epidemic_df$i_t, | ||
w=epidemic_df$w_dist, | ||
is_sampling=FALSE, | ||
as_vector=FALSE | ||
) | ||
# plot | ||
R <- fit$par$R | ||
epidemic_df %>% | ||
mutate(estimated=R) %>% | ||
rename(true=R_t) %>% | ||
select(t, estimated, true) %>% | ||
pivot_longer(c(estimated, true)) %>% | ||
ggplot(aes(x=t, y=value)) + | ||
geom_line(aes(colour=name)) + | ||
scale_color_brewer("R_t", palette = "Dark2") + | ||
ylab("R_t") + | ||
xlab("Time") + | ||
theme_minimal() | ||
``` | ||
|
||
## Contributing guidelines | ||
We welcome contributions from collaborators. Before doing so, we ask that you read | ||
our [contributing guidelines](contributing-guidelines.md) section. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.