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

Ensure non-zero negative binomial offspring parameters #150

Merged
merged 6 commits into from
Aug 22, 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
56 changes: 35 additions & 21 deletions CITATION.cff
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# -----------------------------------------------------------
# CITATION file created with {cffr} R package, v0.5.0
# --------------------------------------------
# CITATION file created with {cffr} R package
# See also: https://docs.ropensci.org/cffr/
# -----------------------------------------------------------
# --------------------------------------------

cff-version: 1.2.0
message: 'To cite package "bpmodels" in publications use:'
type: software
license: MIT
title: 'bpmodels: Simulating and Analysing Transmission Chain Statistics using Branching
Process Models'
version: 0.3.1
version: 0.3.2
abstract: Provides methods to simulate and analyse the size and length of branching
processes with an arbitrary offspring distribution. These can be used, for example,
to analyse the distribution of chain sizes or length of infectious disease outbreaks,
as discussed in Farrington et al. (2003) <doi:10.1093/biostatistics/4.2.279>.
as discussed in Farrington et al. (2003) <https://doi.org/10.1093/biostatistics/4.2.279>.
authors:
- family-names: Azam
given-names: James M.
Expand All @@ -37,8 +37,8 @@ preferred-citation:
- name: James M. Azam
year: '2023'
url: https://github.com/epiverse-trace/bpmodels/
repository-code: https://github.com/epiverse-trace/bpmodels
url: https://epiverse-trace.github.io/bpmodels/
repository-code: https://github.com/epiforecasts/bpmodels
url: https://epiforecasts.io/bpmodels/
contact:
- family-names: Azam
given-names: James M.
Expand All @@ -63,11 +63,10 @@ references:
url: https://www.R-project.org/
authors:
- name: R Core Team
location:
name: Vienna, Austria
year: '2023'
institution:
name: R Foundation for Statistical Computing
address: Vienna, Austria
year: '2024'
version: '>= 3.6.0'
- type: software
title: bookdown
Expand All @@ -80,7 +79,8 @@ references:
given-names: Yihui
email: xie@yihui.name
orcid: https://orcid.org/0000-0003-0645-5666
year: '2023'
year: '2024'
doi: 10.32614/CRAN.package.bookdown
- type: software
title: dplyr
abstract: 'dplyr: A Grammar of Data Manipulation'
Expand All @@ -104,7 +104,8 @@ references:
given-names: Davis
email: davis@posit.co
orcid: https://orcid.org/0000-0003-4777-038X
year: '2023'
year: '2024'
doi: 10.32614/CRAN.package.dplyr
- type: software
title: ggplot2
abstract: 'ggplot2: Create Elegant Data Visualisations Using the Grammar of Graphics'
Expand Down Expand Up @@ -139,7 +140,12 @@ references:
- family-names: Dunnington
given-names: Dewey
orcid: https://orcid.org/0000-0002-9415-4582
year: '2023'
- family-names: Brand
given-names: Teun
name-particle: van den
orcid: https://orcid.org/0000-0002-9335-7468
year: '2024'
doi: 10.32614/CRAN.package.ggplot2
- type: software
title: knitr
abstract: 'knitr: A General-Purpose Package for Dynamic Report Generation in R'
Expand All @@ -151,7 +157,8 @@ references:
given-names: Yihui
email: xie@yihui.name
orcid: https://orcid.org/0000-0003-0645-5666
year: '2023'
year: '2024'
doi: 10.32614/CRAN.package.knitr
- type: software
title: lubridate
abstract: 'lubridate: Make Dealing with Dates a Little Easier'
Expand All @@ -166,7 +173,8 @@ references:
given-names: Garrett
- family-names: Wickham
given-names: Hadley
year: '2023'
year: '2024'
doi: 10.32614/CRAN.package.lubridate
- type: software
title: rmarkdown
abstract: 'rmarkdown: Dynamic Documents for R'
Expand Down Expand Up @@ -209,12 +217,13 @@ references:
given-names: Richard
email: rich@posit.co
orcid: https://orcid.org/0000-0003-3925-190X
year: '2023'
year: '2024'
doi: 10.32614/CRAN.package.rmarkdown
- type: software
title: spelling
abstract: 'spelling: Tools for Spell Checking in R'
notes: Suggests
url: https://docs.ropensci.org/spelling/
url: https://ropensci.r-universe.dev/spelling
repository: https://CRAN.R-project.org/package=spelling
authors:
- family-names: Ooms
Expand All @@ -224,7 +233,8 @@ references:
- family-names: Hester
given-names: Jim
email: james.hester@rstudio.com
year: '2023'
year: '2024'
doi: 10.32614/CRAN.package.spelling
- type: software
title: testthat
abstract: 'testthat: Unit Testing for R'
Expand All @@ -235,7 +245,8 @@ references:
- family-names: Wickham
given-names: Hadley
email: hadley@posit.co
year: '2023'
year: '2024'
doi: 10.32614/CRAN.package.testthat
- type: software
title: truncdist
abstract: 'truncdist: Truncated Random Variables'
Expand All @@ -248,7 +259,8 @@ references:
- family-names: Nadarajah
given-names: Saralees
email: saralees.nadarajah@manchester.ac.uk
year: '2023'
year: '2024'
doi: 10.32614/CRAN.package.truncdist
- type: software
title: checkmate
abstract: 'checkmate: Fast and Versatile Argument Checks'
Expand All @@ -260,4 +272,6 @@ references:
given-names: Michel
email: michellang@gmail.com
orcid: https://orcid.org/0000-0001-9754-0393
year: '2023'
year: '2024'
doi: 10.32614/CRAN.package.checkmate

2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: bpmodels
Title: Simulating and Analysing Transmission Chain Statistics using Branching Process
Models
Version: 0.3.1
Version: 0.3.2
Authors@R: c(
person("James M.", "Azam", , "james.azam@lshtm.ac.uk", role = c("aut", "cre"),
comment = c(ORCID = "https://orcid.org/0000-0001-5782-7330")),
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# bpmodels 0.3.2

## Model

* `chain_sim()` now ensures that the parameters of the negative binomial offspring are not both zero else returns an informative error.

# bpmodels 0.3.1

## Unit tests and input validation
Expand Down
7 changes: 7 additions & 0 deletions R/simulate.r
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ chain_sim <- function(n, offspring, stat = c("size", "length"), infinite = Inf,
if (!(exists(roffspring_name)) || !is.function(get(roffspring_name))) {
stop("Function ", roffspring_name, " does not exist.")
}
# If both parameters of the negative binomial are zero, you get NaNs
if (roffspring_name == "rnbinom" && all(c(...) == 0)) {
stop(
"The negative binomial parameters must have at least one ",
"non-zero parameter."
)
}

if (!missing(serial)) {
if (!is.function(serial)) {
Expand Down
13 changes: 13 additions & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Borel
CMD
COVID
Eq
Lifecycle
Marivate
ORCID
Poisson
Expand All @@ -9,16 +11,25 @@ README's
Vukosi
Zhian
codecov
cutoff
dfrac
doi
ecdf
epichains
frac
gborel
geq
immunes
infectee
infectees
infector
infectors
json
kS
linelist
ln
mathbf
mathrm
nbinom
nolint
pois
Expand All @@ -27,4 +38,6 @@ quickstart
sim
superspreading
susceptibles
th
unnormalised
var
10 changes: 10 additions & 0 deletions tests/testthat/tests-sim.r
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ test_that("Errors are thrown", {
),
"If `tf` is specified, `serial` must be specified too."
)
expect_error(
chain_sim(
n = 10,
offspring = "nbinom",
stat = "size",
mu = 0,
size = 0
),
"must have at least one non-zero parameter"
)
})

test_that("Chains can be simulated", {
Expand Down