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

Release v0.1.1 to CRAN #284

Merged
merged 22 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
^data-raw$
^CITATION\.cff$
^_pkgdown\.yml$
^CRAN-SUBMISSION$
22 changes: 22 additions & 0 deletions .github/settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
repository:
# https://probot.github.io/apps/settings/
allow_merge_commit: false
allow_rebase_merge: true
allow_squash_merge: true
default_branch: main
delete_branch_on_merge: true
# has_discussions: false
has_issues: true
# has_projects: false
# has_wiki: false
# private: false
branches:
- name: main
# https://docs.github.com/en/rest/reference/repos#update-branch-protection
protection:
required_pull_request_reviews:
required_approving_review_count: 0 # (1-6; optionally 0)
dismiss_stale_reviews: true
require_code_owner_reviews: false
required_status_checks:
strict: true
1 change: 1 addition & 0 deletions .github/workflows/lint-changed-files.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
any::gh
any::lintr
any::purrr
any::cyclocomp
epiverse-trace/etdev
needs: check

Expand Down
1 change: 1 addition & 0 deletions .lintr
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
linters: all_linters(
packages = c("lintr", "etdev"),
pipe_consistency_linter(pipe = "%>%"),
object_name_linter = NULL,
implicit_integer_linter = NULL,
extraction_operator_linter = NULL,
Expand Down
3 changes: 3 additions & 0 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Version: 0.1.1
Date: 2024-10-09 11:55:04 UTC
SHA: cefe3fcfbce1b012b86cae03cf55b3ec90fff852
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Package: epichains
Title: Simulating and Analysing Transmission Chain Statistics Using
Branching Process Models
Version: 0.1.0.9000
Version: 0.1.1
Authors@R: c(
person("James M.", "Azam", , "[email protected]", role = c("aut", "cre", "cph"),
comment = c(ORCID = "0000-0001-5782-7330")),
person("Sebastian", "Funk", , "[email protected]", role = "aut",
person("Sebastian", "Funk", , "[email protected]", role = c("aut", "cph"),
comment = c(ORCID = "0000-0002-2842-3406")),
person("Flavio", "Finger", , "[email protected]", role = "aut",
comment = c(ORCID = "0000-0002-8613-5170")),
Expand Down Expand Up @@ -54,4 +54,4 @@ Encoding: UTF-8
Language: en-GB
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2.9000
6 changes: 4 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# epichains (development version)
# epichains 0.1.1

This is the first CRAN release of `{epichains}`.

## Package

Expand All @@ -8,7 +10,7 @@

We are excited to announce the first minor release of `{epichains}`.

`{epichains}` re-implements [{bpmodels}](https://github.com/epiverse-trace/bpmodels), focusing on a unified simulation framework using branching processes to simulate transmission chains data. The framework incorporates susceptible depletion and pre-existing immunity and provides dedicated data structures for handling and analysing transmission chains in both tabular and vector formats. The goal is to provide seamless interoperability with other packages within the Epiverse-TRACE Initiative and the broader epidemiological tool ecosystem.
`{epichains}` re-implements [{bpmodels}](https://github.com/epiforecasts/bpmodels/), focusing on a unified simulation framework using branching processes to simulate transmission chains data. The framework incorporates susceptible depletion and pre-existing immunity and provides dedicated data structures for handling and analysing transmission chains in both tabular and vector formats. The goal is to provide seamless interoperability with other packages within the Epiverse-TRACE Initiative and the broader epidemiological tool ecosystem.

## New Features

Expand Down
40 changes: 29 additions & 11 deletions R/borel.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@
#' @param mu A non-negative number for the poisson mean.
#' @param log Logical; if TRUE, probabilities p are given as log(p).
#' @return A numeric vector of the borel probability density.
#' @author Sebastian Funk
#' @author Sebastian Funk James M. Azam
#' @export
#' @examples
#' set.seed(32)
#' dborel(1:5, 1)
dborel <- function(x, mu, log = FALSE) {
checkmate::assert_numeric(
x, lower = 1, upper = Inf
x,
lower = 1,
upper = Inf
)
checkmate::assert_number(
mu, lower = 0, finite = TRUE, na.ok = FALSE
mu,
lower = 0,
finite = TRUE,
na.ok = FALSE
)

ld <- -mu * x + (x - 1) * log(mu * x) - lgamma(x + 1)
Expand All @@ -34,17 +39,23 @@ dborel <- function(x, mu, log = FALSE) {
#' `mu >= 1`, the simulation could proceed unendingly. This parameter is used
#' to prevent this.
#' @return A numeric vector of random numbers.
#' @author Sebastian Funk
#' @author Sebastian Funk James M. Azam
#' @export
#' @examples
#' set.seed(32)
#' rborel(5, 1)
rborel <- function(n, mu, censor_at = Inf) {
checkmate::assert_number(
n, lower = 1, finite = TRUE, na.ok = FALSE
n,
lower = 1,
finite = TRUE,
na.ok = FALSE
)
checkmate::assert_number(
mu, lower = 0, finite = TRUE, na.ok = FALSE
mu,
lower = 0,
finite = TRUE,
na.ok = FALSE
)
# Run simulations
out <- simulate_chain_stats(
Expand All @@ -69,7 +80,7 @@ rborel <- function(n, mu, censor_at = Inf) {
#' 0 and 1.
#' @param mu Mean; A positive number.
#' @return Numeric vector of random numbers
#' @author Sebastian Funk
#' @author Sebastian Funk James M. Azam
#' @export
#' @examples
#' set.seed(32)
Expand All @@ -81,16 +92,22 @@ rgborel <- function(n, size, prob, mu, censor_at = Inf) {
# its "correct implementation" for documentation/clarity purposes, as well as
# for simulations.
checkmate::assert_number(
size, finite = TRUE, lower = 0
size,
finite = TRUE,
lower = 0
)
if (!missing(prob)) {
checkmate::assert_number(
prob, lower = 0, upper = 1
prob,
lower = 0,
upper = 1
)
}
if (!missing(mu)) {
checkmate::assert_number(
mu, finite = TRUE, lower = 0
mu,
finite = TRUE,
lower = 0
)
}
if (!missing(prob)) {
Expand All @@ -101,6 +118,7 @@ rgborel <- function(n, size, prob, mu, censor_at = Inf) {
x <- rgamma(n, shape = size, rate = size / mu)
# then, sample from borel
return(vapply(
x, rborel, n = 1, censor_at = censor_at, FUN.VALUE = numeric(1)
x, rborel,
n = 1, censor_at = censor_at, FUN.VALUE = numeric(1)
))
}
8 changes: 4 additions & 4 deletions R/checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@
# check that stat_threshold is an integer or Inf.
checkmate::assert(
checkmate::anyInfinite(stat_threshold),
checkmate::check_integerish(
stat_threshold,
lower = 1
checkmate::check_integerish(
stat_threshold,
lower = 1
),
combine = "or"
)
Expand Down Expand Up @@ -102,7 +102,7 @@
if (!is.null(generation_time)) {
.check_generation_time_valid(generation_time)
} else if (tf_specified) {
stop("If `tf` is specified, `generation_time` must be specified too.")
stop("If `tf` is specified, `generation_time` must be specified too.")
}
checkmate::assert_number(
tf,
Expand Down
88 changes: 44 additions & 44 deletions R/epichains.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
#' @author James M. Azam
#' @keywords internal
.new_epichains <- function(sim_df,
n_chains,
statistic,
offspring_dist,
stat_threshold,
track_pop) {
n_chains,
statistic,
offspring_dist,
stat_threshold,
track_pop) {
# Assemble the elements of the object
obj <- sim_df
class(obj) <- c("epichains", class(obj))
Expand Down Expand Up @@ -55,11 +55,11 @@
#' @author James M. Azam
#' @keywords internal
.epichains <- function(sim_df,
n_chains,
offspring_dist,
track_pop,
statistic = c("size", "length"),
stat_threshold = Inf) {
n_chains,
offspring_dist,
track_pop,
statistic = c("size", "length"),
stat_threshold = Inf) {
# Check that inputs are well specified
checkmate::assert_data_frame(sim_df, min.cols = 3, min.rows = n_chains)
checkmate::assert_integerish(
Expand Down Expand Up @@ -112,10 +112,10 @@
#' @author James M. Azam
#' @keywords internal
.new_epichains_summary <- function(chains_summary,
n_chains,
statistic,
offspring_dist,
stat_threshold) {
n_chains,
statistic,
offspring_dist,
stat_threshold) {
# Assemble the elements of the object
obj <- chains_summary
class(obj) <- c("epichains_summary", class(chains_summary))
Expand All @@ -141,10 +141,10 @@
#' @author James M. Azam
#' @keywords internal
.epichains_summary <- function(chains_summary,
n_chains,
offspring_dist,
statistic = c("size", "length"),
stat_threshold = Inf) {
n_chains,
offspring_dist,
statistic = c("size", "length"),
stat_threshold = Inf) {
# chain_summary can sometimes contain infinite values, so check
# that finite elements are integerish.
checkmate::check_integerish(
Expand Down Expand Up @@ -194,12 +194,12 @@
#' # population up to chain size 10.
#' set.seed(32)
#' chains_pois_offspring <- simulate_chains(
#' n_chains = 10,
#' statistic = "size",
#' offspring_dist = rpois,
#' stat_threshold = 10,
#' generation_time = function(n) rep(3, n),
#' lambda = 2
#' n_chains = 10,
#' statistic = "size",
#' offspring_dist = rpois,
#' stat_threshold = 10,
#' generation_time = function(n) rep(3, n),
#' lambda = 2
#' )
#' chains_pois_offspring # Print the object
print.epichains <- function(x, ...) {
Expand All @@ -226,11 +226,11 @@ print.epichains <- function(x, ...) {
#' # population up to chain size 10.
#' set.seed(32)
#' chain_summary_print_eg <- simulate_chain_stats(
#' n_chains = 10,
#' statistic = "size",
#' offspring_dist = rpois,
#' stat_threshold = 10,
#' lambda = 2
#' n_chains = 10,
#' statistic = "size",
#' offspring_dist = rpois,
#' stat_threshold = 10,
#' lambda = 2
#' )
#' chain_summary_print_eg # Print the object
print.epichains_summary <- function(x, ...) {
Expand Down Expand Up @@ -322,19 +322,19 @@ format.epichains_summary <- function(x, ...) {
"Max: %s",
ifelse(
is.infinite(
statistics[["max_stat"]]),
paste0(">=", attr(x, "stat_threshold")
statistics[["max_stat"]]
),
paste0(">=", attr(x, "stat_threshold")),
statistics[["max_stat"]]
)
),
sprintf(
"Min: %s",
ifelse(
is.infinite(
statistics[["min_stat"]]),
paste0(">=", attr(x, "stat_threshold")
statistics[["min_stat"]]
),
paste0(">=", attr(x, "stat_threshold")),
statistics[["min_stat"]]
)
)
Expand Down Expand Up @@ -455,11 +455,11 @@ summary.epichains <- function(object, ...) {
#' # population up to chain size 10.
#' set.seed(32)
#' chain_stats <- simulate_chain_stats(
#' n_chains = 10,
#' statistic = "size",
#' offspring_dist = rpois,
#' stat_threshold = 10,
#' lambda = 2
#' n_chains = 10,
#' statistic = "size",
#' offspring_dist = rpois,
#' stat_threshold = 10,
#' lambda = 2
#' )
#' summary(chain_stats)
summary.epichains_summary <- function(object, ...) {
Expand Down Expand Up @@ -526,7 +526,7 @@ summary.epichains_summary <- function(object, ...) {
stopifnot(
"object does not contain the correct columns" =
c("chain", "infector", "infectee", "generation") %in%
colnames(x),
colnames(x),
"column `chain` must be a numeric" =
is.numeric(x$chain),
"column `infector` must be a numeric" =
Expand Down Expand Up @@ -643,11 +643,11 @@ tail.epichains <- function(x, ...) {
#' cases_per_gen <- aggregate(chains, by = "generation")
#' head(cases_per_gen)
aggregate.epichains <- function(x,
by = c(
"time",
"generation"
),
...) {
by = c(
"time",
"generation"
),
...) {
.validate_epichains(x)
checkmate::assert_string(by)
# Get grouping variable
Expand Down
Loading
Loading