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

Full package review for epichains v0.1.0 release #122

Merged
merged 23 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
33405ae
Apply suggestions from code review
jamesmbaazam Dec 12, 2023
95d3a65
Automatic readme update
actions-user Dec 12, 2023
dc59cfb
Apply suggestions: Reword ... arg description
jamesmbaazam Dec 13, 2023
721468d
Clarify phrase about how generation_time can be specified
jamesmbaazam Dec 15, 2023
33c2344
Remove sprintf call from stop() message
jamesmbaazam Dec 15, 2023
08fc5fa
Remove redundant check
jamesmbaazam Dec 15, 2023
c2889c3
Generate documentation
jamesmbaazam Dec 15, 2023
0070ebe
Rename count variable and convert result to tibble
jamesmbaazam Dec 15, 2023
6aa9d4a
Remove unneccesary lambda from lapply
jamesmbaazam Dec 15, 2023
f0ba812
Label count column in raw data as cases.
jamesmbaazam Dec 15, 2023
468312c
Revert use of setdiff
jamesmbaazam Dec 15, 2023
0041c98
Generate docs
jamesmbaazam Dec 15, 2023
1640a77
Fix spelling and update wordlist. Fixes #144.
jamesmbaazam Dec 15, 2023
b3a35a4
Linting
jamesmbaazam Dec 15, 2023
22ad47a
Fix test
jamesmbaazam Dec 15, 2023
b80c1cf
Update snapshots
jamesmbaazam Dec 15, 2023
8264254
Remove unnecessary badges to fix #164
jamesmbaazam Dec 15, 2023
794a145
Delete CITATION file to fix #129
jamesmbaazam Dec 15, 2023
985c3f3
Use dev version
jamesmbaazam Dec 15, 2023
a2f1813
Clean up NEWS
jamesmbaazam Dec 15, 2023
0d2733b
Move truncdist to Imports to fix #138
jamesmbaazam Dec 15, 2023
caa78d6
Remove unnecessary packages from Suggests and Remotes to close #126 a…
jamesmbaazam Dec 15, 2023
a3b8022
Automatic readme update
actions-user Dec 15, 2023
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
11 changes: 3 additions & 8 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: epichains
Title: Simulating and Analysing Transmission Chain Statistics Using Branching Process
Models
Version: 0.1.0
Version: 0.0.0.9999
Authors@R: c(
person("James M.", "Azam", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "https://orcid.org/0000-0001-5782-7330")),
Expand All @@ -26,24 +26,19 @@ Depends:
Imports:
checkmate,
stats,
truncdist,
utils
Suggests:
bookdown,
covr,
dplyr,
epiparameter,
ggplot2,
knitr,
lubridate,
rmarkdown,
spelling,
testthat,
truncdist,
usethis
testthat
VignetteBuilder:
knitr
Remotes:
github::epiverse-trace/epiparameter
Config/Needs/website:epiverse-trace/epiversetheme
Config/testthat/edition: 3
Encoding: UTF-8
Expand Down
57 changes: 20 additions & 37 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,31 @@
# epichains 0.1.9999
# epichains 0.0.9999

## Documentation
* A vignette outlining how to simulate interventions has been added
* `epichains` is a re-implementation of `bpmodels` with a focus on providing
a dedicated class of data structures for easy manipulation and interoperability
with other new tools in the Epiverse and existing ecosystem.

# epichains 0.1.0
## Documentation

## Package name change
* A vignette outlining how to simulate interventions has been added.

* `epichains` is a re-implementation of `bpmodels` with a focus on providing
a dedicated class of data structures for easy manipulation and interoperability
with other new tools in the pipeline.
## Functions

### Functions

* `simulate_tree()`: simulate transmission trees from a given number of chains.
* `simulate_tree()`: simulate transmission trees from a given number of initial
cases.
* `simulate_tree_from_pop()`: simulate transmission trees from a given
population size and initial immunity.
population size and initial immunity.
* `simulate_summary()`: simulate a vector of observed transmission chains
sizes/lengths from a given number of chains.
sizes/lengths from a given number of chains.
* `likelihood()`: estimate the likelihood/loglikelihood of observing
chains of given sizes/lengths.

### Classes

* An `epichains` class, which inherits from `data.frame` with attributes for
tracking:
- `chains`: number of chains simulated
- `chain_type`:
- `chains_tree`, if returned from `simulate_tree()` or
`simulate_tree_from_pop()`
- `chains_summary`, if returned from `simulate_summary()`.
- `track_pop`: whether the susceptible population is tracked or not.
* An `epichains_aggregate_df` class, which inherits from `data.frame` with
attributes for tracking:
- `chain_type`: as defined above, and
- `aggregated_over`: the variable(s) over which aggregation was done: "time",
"generation" or "both". Useful for easy plotting with the `plot` method (see
methods section below).

### Methods

* `print()`
* `summary()`
* `aggregate()`
chains of given sizes/lengths.

## Methods

* Use `print()` and `summary()` to obtain more insightful results compared to
previously in {bpmodels}.
* Use `aggregate()` to aggregate results from `simulate_tree()` and
`simulate_tree_from_pop()` into cases by "generation" and "time" (if time is
simulated)

# bpmodels 0.2.1

Expand Down
1 change: 0 additions & 1 deletion R/borel.r
jamesmbaazam marked this conversation as resolved.
Show resolved Hide resolved
jamesmbaazam marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ dborel <- function(x, mu, log = FALSE) {
mu, lower = 0, finite = TRUE, na.ok = FALSE
)

if (x < 1) stop("'x' must be greater than 0")
ld <- -mu * x + (x - 1) * log(mu * x) - lgamma(x + 1)
if (!log) ld <- exp(ld)
return(ld)
Expand Down
10 changes: 4 additions & 6 deletions R/checks.R
jamesmbaazam marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
#' @keywords internal
check_offspring_valid <- function(offspring_dist) {
if (!checkmate::test_string(offspring_dist)) {
stop(sprintf(
"%s %s",
stop(
"'offspring_dist' must be specified as a character string.",
"Did you forget to enclose it in quotes?"
))
)
}
}

Expand All @@ -37,11 +36,10 @@ check_offspring_func_valid <- function(roffspring_name) {
#' @keywords internal
check_generation_time_valid <- function(generation_time) {
if (!checkmate::test_function(generation_time, nargs = 1)) {
stop(sprintf(
"%s %s",
stop(
"The `generation_time` argument must be a function",
"(see details in ?simulate_tree)."
))
)
}
x <- generation_time(10)
if (!checkmate::test_numeric(x, len = 10)) {
Expand Down
12 changes: 6 additions & 6 deletions R/epichains.R
jamesmbaazam marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ print.epichains_tree <- function(x, ...) {
#' Print an `<epichains_summary>` object
#'
#' @param x An `<epichains_summary>` object.
#' @param ... Other parameters passed to `print()`.
#' @param ... ignored.
#' @return Invisibly returns an `<epichains_summary>`. Called for
#' side-effects.
#' @author James M. Azam
Expand All @@ -193,7 +193,7 @@ print.epichains_summary <- function(x, ...) {
#' Format method for `<epichains_tree>` class
#'
#' @param x An `<epichains_tree>` object
#' @param ... further arguments passed to or from other methods
#' @param ... ignored
#' @return Invisibly returns an `<epichains_tree>`.
#' Called for printing side-effects.
#' @author James M. Azam
Expand Down Expand Up @@ -246,7 +246,7 @@ format.epichains_tree <- function(x, ...) {
#' Format method for `<epichains_summary>` class
#'
#' @param x An `<epichains_summary>` object
#' @param ... further arguments passed to or from other methods
#' @param ... ignored
#' @return Invisibly returns an `<epichains_summary>`. Called for printing
#' side-effects.
#' @author James M. Azam
Expand Down Expand Up @@ -289,7 +289,7 @@ format.epichains_summary <- function(x, ...) {
#' Summary method for `<epichains_tree>` class
#'
#' @param object An `<epichains_tree>` object
#' @param ... further arguments passed to or from other methods
#' @param ... ignored
#'
#' @return List of summaries
#' @author James M. Azam
Expand Down Expand Up @@ -323,7 +323,7 @@ summary.epichains_tree <- function(object, ...) {
#' Summary method for `<epichains_summary>` class
#'
#' @param object An `<epichains_summary>` object
#' @param ... further arguments passed to or from other methods
#' @param ... ignored
#'
#' @return List of summaries
#' @author James M. Azam
Expand Down Expand Up @@ -458,7 +458,7 @@ tail.epichains_tree <- function(x, ...) {
#' @param x An `<epichains_tree>` object.
#' @param by The variable to aggregate by. Options include
#' "time" and "generation".
#' @param ... Other arguments passed to aggregate.
#' @param ... ignored.
#' @importFrom stats aggregate
#' @return A `<data.frame>` object of cases by `by`.
#' @author James M. Azam
Expand Down
7 changes: 4 additions & 3 deletions R/likelihood.R
jamesmbaazam marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,17 @@ likelihood <- function(chains, statistic = c("size", "length"), offspring_dist,
if (!missing(exclude)) {
likelihoods <- likelihoods - log(-expm1(sum(likelihoods[exclude])))
likelihoods[exclude] <- -Inf

stat_rep_list <- lapply(stat_rep_list, function(y) {
y[!(y %in% exclude)]
})
}
)
}

## assign likelihoods
chains_likelihood <- lapply(stat_rep_list, function(sx) {
likelihoods[sx[!(sx %in% exclude)]]
})
}
)

## if individual == FALSE, return the joint log-likelihood
## (sum of the log-likelihoods)
Expand Down
19 changes: 6 additions & 13 deletions R/simulate.r
jamesmbaazam marked this conversation as resolved.
Show resolved Hide resolved
jamesmbaazam marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@
#'
#' ## Specifying `generation_time`
#'
#' `generation_time` must be specified as a named or
#' [anonymous/inline/unnamed function](https://en.wikipedia.org/wiki/Anonymous_function#R)
#' with one argument.
#' `generation_time` must be specified as a function with one argument.
#'
#' For example, assuming we want to specify the generation time
#' as a random log-normally distributed variable with
Expand Down Expand Up @@ -118,6 +116,8 @@ simulate_tree <- function(ntrees, statistic = c("size", "length"),

if (!missing(generation_time)) {
check_generation_time_valid(generation_time)
} else if (!missing(tf)) {
stop("If `tf` is specified, `generation_time` must be specified too.")
}
checkmate::assert_numeric(
t0, lower = 0, finite = TRUE
Expand All @@ -129,12 +129,6 @@ simulate_tree <- function(ntrees, statistic = c("size", "length"),
# Gather offspring distribution parameters
pars <- list(...)

if (!missing(generation_time)) {
check_generation_time_valid(generation_time)
} else if (!missing(tf)) {
stop("If `tf` is specified, `generation_time` must be specified too.")
}

# Initialisations
stat_track <- rep(1, ntrees) # track length or size (depending on `statistic`)
n_offspring <- rep(1, ntrees) # current number of offspring
Expand Down Expand Up @@ -453,14 +447,13 @@ simulate_tree_from_pop <- function(pop,
}
} else if (offspring_dist == "nbinom") {
if (is.null(pars$size)) {
stop(sprintf("%s", "'size' must be specified."))
stop("'size' must be specified.")
} else if (pars$size <= 1) { ## dispersion coefficient
stop(sprintf(
"%s %s %s",
stop(
"Offspring distribution 'nbinom' requires",
"argument 'size' > 1.",
"Use 'pois' if there is no overdispersion."
))
)
}
## get distribution params from mean and dispersion
offspring_func <- function(n, susc) {
Expand Down
8 changes: 3 additions & 5 deletions README.Rmd
jamesmbaazam marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ knitr::opts_chunk$set(
# _{{ packagename }}_: Methods for simulating and analysing the size and length of transmission chains from branching process models <img src="man/figures/logo.svg" align="right" height="130" />

<!-- badges: start -->
![GitHub R package version](https://img.shields.io/github/r-package/v/epiverse-trace/epichains)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![R-CMD-check](https://github.com/epiverse-trace/epichains/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/epiverse-trace/epichains/actions/workflows/R-CMD-check.yaml)
[![codecov](https://codecov.io/github/epiverse-trace/epichains/branch/main/graphs/badge.svg)](https://codecov.io/github/epiverse-trace/epichains)
![GitHub contributors](https://img.shields.io/github/contributors/epiverse-trace/epichains)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Lifecycle:
experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
<!-- badges: end -->
Expand All @@ -41,9 +39,9 @@ models are often used in infectious disease epidemiology, where the chains repre
transmission, and the offspring distribution represents the distribution of
secondary infections caused by an infected individual.

_{{ packagename }}_ re-implements [bpmodels]("https://github.com/epiverse-trace/bpmodels/")
_{{ packagename }}_ re-implements [bpmodels](https://github.com/epiverse-trace/bpmodels/)
by providing bespoke functions and data structures that allow easy
manipulation and interoperability with other Epiverse-TRACE packages, for example, [superspreading]("https://github.com/epiverse-trace/superspreading/") and [epiparameter]("https://github.com/epiverse-trace/epiparameter/"), and potentially some existing packages for handling transmission chains, for example, [epicontacts](https://github.com/reconhub/epicontacts).
manipulation and interoperability with other Epiverse-TRACE packages, for example, [superspreading](https://github.com/epiverse-trace/superspreading/) and [epiparameter](https://github.com/epiverse-trace/epiparameter/), and potentially some existing packages for handling transmission chains, for example, [epicontacts](https://github.com/reconhub/epicontacts).

_{{ packagename }}_ is developed at the [Centre for the Mathematical Modelling of Infectious Diseases](https://www.lshtm.ac.uk/research/centres/centre-mathematical-modelling-infectious-diseases) at the London School of Hygiene and Tropical Medicine as part of the [Epiverse Initiative](https://data.org/initiatives/epiverse/).

Expand Down
43 changes: 21 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@

<!-- badges: start -->

![GitHub R package
version](https://img.shields.io/github/r-package/v/epiverse-trace/epichains)
[![R-CMD-check](https://github.com/epiverse-trace/epichains/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/epiverse-trace/epichains/actions/workflows/R-CMD-check.yaml)
[![codecov](https://codecov.io/github/epiverse-trace/epichains/branch/main/graphs/badge.svg)](https://codecov.io/github/epiverse-trace/epichains)
![GitHub
contributors](https://img.shields.io/github/contributors/epiverse-trace/epichains)
[![License:
MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![R-CMD-check](https://github.com/epiverse-trace/epichains/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/epiverse-trace/epichains/actions/workflows/R-CMD-check.yaml)
[![codecov](https://codecov.io/github/epiverse-trace/epichains/branch/main/graphs/badge.svg)](https://codecov.io/github/epiverse-trace/epichains)
[![Lifecycle:
experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
<!-- badges: end -->
Expand All @@ -29,15 +25,13 @@ distribution represents the distribution of secondary infections caused
by an infected individual.

*epichains* re-implements
[bpmodels](%22https://github.com/epiverse-trace/bpmodels/%22) by
providing bespoke functions and data structures that allow easy
manipulation and interoperability with other Epiverse-TRACE packages,
for example,
[superspreading](%22https://github.com/epiverse-trace/superspreading/%22)
and
[epiparameter](%22https://github.com/epiverse-trace/epiparameter/%22),
and potentially some existing packages for handling transmission chains,
for example, [epicontacts](https://github.com/reconhub/epicontacts).
[bpmodels](https://github.com/epiverse-trace/bpmodels/) by providing
bespoke functions and data structures that allow easy manipulation and
interoperability with other Epiverse-TRACE packages, for example,
[superspreading](https://github.com/epiverse-trace/superspreading/) and
[epiparameter](https://github.com/epiverse-trace/epiparameter/), and
potentially some existing packages for handling transmission chains, for
example, [epicontacts](https://github.com/reconhub/epicontacts).

*epichains* is developed at the [Centre for the Mathematical Modelling
of Infectious
Expand Down Expand Up @@ -133,18 +127,23 @@ By contributing to this project, you agree to abide by its terms.

``` r
citation("epichains")
#> To cite package epichains in publications use:
#> To cite package 'epichains' in publications use:
#>
#> Sebastian Funk, Flavio Finger, and James M. Azam (2023). epichains:
#> Analysing transmission chain statistics using branching process
#> models, website: https://github.com/epiverse-trace/epichains/
#> Azam J, Finger F, Funk S (2023). _epichains: Simulating and Analysing
#> Transmission Chain Statistics Using Branching Process Models_. R
#> package version 0.0.0.9999,
#> https://epiverse-trace.github.io/epichains/,
#> <https://github.com/epiverse-trace/epichains>.
#>
#> A BibTeX entry for LaTeX users is
#>
#> @Manual{,
#> title = {epichains: Analysing transmission chain statistics using branching process models},
#> author = {{Sebastian Funk} and {Flavio Finger} and {James M. Azam}},
#> title = {epichains: Simulating and Analysing Transmission Chain Statistics Using
#> Branching Process Models},
#> author = {James M. Azam and Flavio Finger and Sebastian Funk},
#> year = {2023},
#> url = {https://github.com/epiverse-trace/epichains/},
#> note = {R package version 0.0.0.9999,
#> https://epiverse-trace.github.io/epichains/},
#> url = {https://github.com/epiverse-trace/epichains},
#> }
```
4 changes: 1 addition & 3 deletions data-raw/covid19_sa.R
jamesmbaazam marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ covid19_sa <- covid19_sa %>%
select(date) %>%
mutate(date = lubridate::dmy(date)) %>%
filter(date <= min(date) + lubridate::days(15)) %>%
group_by(date) %>%
summarise(cases = n()) %>%
ungroup()
count(date, name = "cases")

use_data(covid19_sa, overwrite = TRUE)
16 changes: 0 additions & 16 deletions inst/CITATION

This file was deleted.

Loading