Skip to content
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
4 changes: 3 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
^pkgdown$
^README\.Rmd$
^LICENSE\.md$
^LICENSE\.note$
^vignettes/web_only
^vignettes/denim_benchmark.Rmd
^vignettes/denim_vs_deSolve.Rmd
Expand All @@ -20,4 +21,5 @@
^extra_benchmark$
^manuscript_plots$
^\.vscode$
^logo\.svg$
^logo\.svg$
^CODE_OF_CONDUCT\.md$
126 changes: 126 additions & 0 deletions .github/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Contributor Covenant Code of Conduct

## Our Pledge

We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, caste, color, religion, or sexual
identity and orientation.

We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.

## Our Standards

Examples of behavior that contributes to a positive environment for our
community include:

* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the overall
community

Examples of unacceptable behavior include:

* The use of sexualized language or imagery, and sexual attention or advances of
any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email address,
without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Enforcement Responsibilities

Community leaders are responsible for clarifying and enforcing our standards of
acceptable behavior and will take appropriate and fair corrective action in
response to any behavior that they deem inappropriate, threatening, offensive,
or harmful.

Community leaders have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, and will communicate reasons for moderation
decisions when appropriate.

## Scope

This Code of Conduct applies within all community spaces, and also applies when
an individual is officially representing the community in public spaces.
Examples of representing our community include using an official e-mail address,
posting via an official social media account, or acting as an appointed
representative at an online or offline event.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at anhptq@oucru.org.
All complaints will be reviewed and investigated promptly and fairly.

All community leaders are obligated to respect the privacy and security of the
reporter of any incident.

## Enforcement Guidelines

Community leaders will follow these Community Impact Guidelines in determining
the consequences for any action they deem in violation of this Code of Conduct:

### 1. Correction

**Community Impact**: Use of inappropriate language or other behavior deemed
unprofessional or unwelcome in the community.

**Consequence**: A private, written warning from community leaders, providing
clarity around the nature of the violation and an explanation of why the
behavior was inappropriate. A public apology may be requested.

### 2. Warning

**Community Impact**: A violation through a single incident or series of
actions.

**Consequence**: A warning with consequences for continued behavior. No
interaction with the people involved, including unsolicited interaction with
those enforcing the Code of Conduct, for a specified period of time. This
includes avoiding interactions in community spaces as well as external channels
like social media. Violating these terms may lead to a temporary or permanent
ban.

### 3. Temporary Ban

**Community Impact**: A serious violation of community standards, including
sustained inappropriate behavior.

**Consequence**: A temporary ban from any sort of interaction or public
communication with the community for a specified period of time. No public or
private interaction with the people involved, including unsolicited interaction
with those enforcing the Code of Conduct, is allowed during this period.
Violating these terms may lead to a permanent ban.

### 4. Permanent Ban

**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.

**Consequence**: A permanent ban from any sort of public interaction within the
community.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.1, available at
<https://www.contributor-covenant.org/version/2/1/code_of_conduct.html>.

Community Impact Guidelines were inspired by
[Mozilla's code of conduct enforcement ladder][https://github.com/mozilla/inclusion].

For answers to common questions about this code of conduct, see the FAQ at
<https://www.contributor-covenant.org/faq>. Translations are available at <https://www.contributor-covenant.org/translations>.

[homepage]: https://www.contributor-covenant.org
60 changes: 60 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
editor_options:
markdown:
wrap: sentence
---

# Contributing to denim

This outlines how to propose a change to the package denim.
For a detailed discussion on contributing to this and other tidyverse packages, please see the [development contributing guide](https://rstd.io/tidy-contrib) and our [code review principles](https://code-review.tidyverse.org/).

## Fixing typos

You can fix typos, spelling mistakes, or grammatical errors in the documentation directly using the GitHub web interface, as long as the changes are made in the *source* file, meaning:

- YES: you edit a [roxygen2 comments](https://roxygen2.r-lib.org/articles/roxygen2.html) in a `.R` file below `R/`.

- NO: you edit an `.Rd` file below `man/`.

You can find the `.R` file that generates the `.Rd` by reading the comment in the first line.

## Bigger changes

If you want to make a bigger change, it's a good idea to first file an issue and make sure someone from the team agrees that it's needed.

If you've found a bug, please file an issue that illustrates the bug with a reproducible example, preferrably using [reprex](https://www.tidyverse.org/help/#reprex) (this will also help you write a unit test, if needed).
See our guide on [how to create a great issue](https://code-review.tidyverse.org/issues/) for more advice.

### Pull request process

- Fork the package and clone onto your computer.
If you haven't done this before, we recommend using `usethis::create_from_github("thinhong/denim", fork = TRUE)`.

- Install all development dependencies with `devtools::install_dev_deps()`, and then make sure the package passes R CMD check by running `devtools::check()`.
If R CMD check doesn't pass cleanly, it's a good idea to ask for help before continuing.

- Create a Git branch for your pull request (PR).
We recommend using `usethis::pr_init("brief-description-of-change")`.

- Make your changes, keep in mind that

- We use [roxygen2](#0), for documentation.

- We use [testthat](#0) for unit testings.
Contributions with test cases included are easier to accept.

- New code should follow the tidyverse [style guide](https://style.tidyverse.org).
You can use the [styler](https://CRAN.R-project.org/package=styler) package to apply these styles, but please don't restyle code that has nothing to do with your PR.

- Commit to git, and then create a PR by running `usethis::pr_push()`, and following the prompts in your browser.
The title of your PR should briefly describe the change.
The body of your PR should contain `Fixes #issue-number`.

- For user-facing changes, add a bullet to the top of `NEWS.md` (i.e. just below the first header).
Follow the style described in <https://style.tidyverse.org/news.html>.

## Code of Conduct

Please note that the `denim` project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md).
By contributing to this project you agree to abide by its terms.
4 changes: 2 additions & 2 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Version: 1.2.2
Date: 2025-08-18 05:41:32 UTC
SHA: 0d64dc2b4afd1b166100d94463729a191a8ce96c
Date: 2025-08-21 04:31:08 UTC
SHA: efec9ea304554e3cb0dfd99a39401ae47a5115dd
12 changes: 8 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ Authors@R: c(
comment = c(ORCID = "0009-0000-2129-435X")),
person("Marc", "Choisy", , "mchoisy@oucru.org", role = "aut",
comment = c(ORCID = "0000-0002-5187-6390")),
person("Niels", "Lohman", ,role = "ctb"),
person("Bjoern", "Hoehrmann", ,email = "bjoern@hoehrmann.de", role = "ctb"),
person("Florian", "Loitsch", ,role = "ctb"),
person("Ingo", "Berg", ,role = "ctb")
person("Niels", "Lohman", ,role = c("ctb", "cph"),
comment="Author for the bundled JSON C++ library"),
person("Bjoern", "Hoehrmann", ,email = "bjoern@hoehrmann.de", role = c("ctb", "cph"),
comment="Contributor for the bundled JSON C++ library"),
person("Florian", "Loitsch", ,role = c("ctb", "cph"),
comment="Contributor for the bundled JSON C++ library"),
person("Ingo", "Berg", ,role = c("ctb", "cph"),
comment="Author for the bundled MuParser C++ library")
)
Description: R package to build and simulate deterministic compartmental models that can be non-Markovian. Length of stay in each compartment can be defined to follow a parametric distribution (d_exponential(), d_gamma(), d_weibull(), d_lognormal()) or a non-parametric distribution (nonparametric()). Other supported types of transition from one compartment to another includes fixed transition (constant()), multinomial (multinomial()), fixed transition probability (transprob()).
License: MIT + file LICENSE
Expand Down
5 changes: 5 additions & 0 deletions LICENSE.note
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
The denim package as a whole is distributed under MIT. The denim package includes other open source software components. The following is a list of these components:

* muParser: BSD
* JSON: MIT
* diffviewer: written by package authors
7 changes: 1 addition & 6 deletions src/Compartment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ void Compartment::setOutValues() {
outTotals.resize(outTransitions.size(), 0);
}

// TODO: set length for nested subCompartment
void Compartment::setLengthSubCompartment() {
size_t maxLength {0};
// TODO: if competitive risk -> same subCompartment chain
// if competitive risk -> same subCompartment chain
// ignore option to distribute initial values


Expand Down Expand Up @@ -257,8 +256,6 @@ void Compartment::updateSubCompByDist(size_t iter, size_t outIndex) {
for (size_t i = 0; i <= endIndex; ++i) {
// if competing risks, compute out population using tmpSubComp instead
double out = tmpSubComp[i] * (i >= transProbRef.size() ? 0 : transProbRef[i]);
// TODO: check formulation with 1 - exp(-rate) instead
// double out = tmpSubComp[i] * (i >= transProbRef.size() ? 0 : transProbRef[i]);
outTotals[outIndex] += out;
subCompartments[0][i] -= out;
}
Expand All @@ -268,8 +265,6 @@ void Compartment::updateSubCompByDist(size_t iter, size_t outIndex) {

for (size_t i = 0; i <= endIndex; ++i) {
double out = subCompartments[outIndex][i] * (i >= transProbRef.size() ? 0 : transProbRef[i]);
// TODO: check formulation with 1 - exp(-rate) instead
// double out = subCompartments[outIndex][i] * (1 - exp(-(i >= transProbRef.size() ? 0 : transProbRef[i])));
outTotals[outIndex] += out;
subCompartments[outIndex][i] -= out;
}
Expand Down
23 changes: 19 additions & 4 deletions src/test-denim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ context("Lognormal distribution") {
test_polymorphism = std::make_shared<TransitionLogNormal>(1, 0.25);

test_that("getTransitionProb") {
// Check the resulting transition prob
expect_true(distr.getTransitionProb(0) == Approx(3.167e-05).margin(1e-06));
expect_true(distr.getTransitionProb(1) == Approx(0.1098).margin(0.01));
expect_true(distr.getTransitionProb(2) == Approx(0.6106).margin(0.01));
expect_true(distr.getTransitionProb(3) == Approx(0.8236).margin(0.01));
}

test_that("maxDay") {
Expand All @@ -60,7 +64,11 @@ context("Gamma distribution") {
TransitionDiscreteGamma distr(1, 3);

test_that("getTransitionProb") {
expect_true(distr.getTransitionProb(4) == Approx(0.4764).margin(0.01));
expect_true(distr.getTransitionProb(0) == Approx(0.0803).margin(0.001));
expect_true(distr.getTransitionProb(1) == Approx(0.2642).margin(0.001));
expect_true(distr.getTransitionProb(2) == Approx(0.3746).margin(0.001));
expect_true(distr.getTransitionProb(3) == Approx(0.4373).margin(0.001));
expect_true(distr.getTransitionProb(4) == Approx(0.4764).margin(0.001));
}

test_that("getRate") {
Expand All @@ -76,7 +84,11 @@ context("Exponential distribution") {
TransitionDiscreteExponential distr(0.5);

test_that("getTransitionProb") {
// expect the same transprob for exponential distribution (i.e. constant hazard rate)
expect_true(distr.getTransitionProb(0) == Approx(0.3934).margin(0.01));
expect_true(distr.getTransitionProb(1) == Approx(0.3934).margin(0.01));
expect_true(distr.getTransitionProb(2) == Approx(0.3934).margin(0.01));
expect_true(distr.getTransitionProb(3) == Approx(0.3934).margin(0.01));
}

test_that("getRate") {
Expand All @@ -96,7 +108,10 @@ context("Weibull distribution") {
TransitionDiscreteWeibull distr(3, 5);

test_that("getTransitionProb") {
expect_true(distr.getTransitionProb(2) == Approx(0.5803).margin(0.01));
expect_true(distr.getTransitionProb(0) == Approx(0.0041).margin(0.001));
expect_true(distr.getTransitionProb(1) == Approx(0.1197).margin(0.001));
expect_true(distr.getTransitionProb(2) == Approx(0.5803).margin(0.001));
expect_true(distr.getTransitionProb(3) == Approx(0.9598).margin(0.001));
}

test_that("getScale") {
Expand Down Expand Up @@ -210,11 +225,11 @@ context("Testing distributions in model"){
expect_true(comp->getCompTotal()[1] == Approx(2).margin(0.001e-03));
break;
case 4:
// check value for compartment V
// check value for compartment D
expect_true(comp->getCompTotal()[1] == Approx(3.167e-06).margin(0.001e-06));
break;
case 5:
// check value for compartment V
// check value for compartment R
expect_true(comp->getCompTotal()[1] == Approx(0.04016).margin(0.001e-03));
break;
}
Expand Down
Binary file added supplements/cached_time_scaling.rds
Binary file not shown.
Loading