Crandore Hub

carts

Simulation-Based Assessment of Covariate Adjustment in Randomized Trials

Monte Carlo simulation framework for different randomized clinical trial designs with a special emphasis on estimators based on covariate adjustment. The package implements regression-based covariate adjustment (Rosenblum & van der Laan (2010) <doi:10.2202/1557-4679.1138>) and a one-step estimator (Van Lancker et al (2024) <doi:10.48550/arXiv.2404.11150>) for trials with continuous, binary and count outcomes. The estimation of the minimum sample-size required to reach a specified statistical power for a given estimator uses bisection to find an initial rough estimate, followed by stochastic approximation (Robbins-Monro (1951) <doi:10.1214/aoms/1177729586>) to improve the estimate, and finally, a grid search to refine the estimate in the neighborhood of the current best solution.

README

---
output: github_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
<!-- README.md is generated from inst/README.Rmd. Please edit that file -->

<!-- badges: start -->
[![complete-checks](https://github.com/NovoNordisk-OpenSource/carts/actions/workflows/r-cmd-check.yaml/badge.svg)](https://github.com/NovoNordisk-OpenSource/carts/actions/workflows/r-cmd-check.yaml)
[![vignettes](https://github.com/NovoNordisk-OpenSource/carts/actions/workflows/vignettes.yaml/badge.svg)](https://github.com/NovoNordisk-OpenSource/carts/actions/workflows/vignettes.yaml)
[![slowtests](https://github.com/NovoNordisk-OpenSource/carts/actions/workflows/slow-tests.yaml/badge.svg)](https://github.com/NovoNordisk-OpenSource/carts/actions/workflows/slow-tests.yaml)
<!-- badges: end -->

# carts package <img src="man/figures/logo.png" align="right" height="250" style="float:right; height:250px;" alt="carts website" />

The `carts` R package is a simulation tool for exploring various estimators
within a clinical trial context under differing assumptions. The package
provides a user-friendly interface for defining a clinical trial object with
different choices for its design, patient and endpoint distributions, and
treatment effect estimators. Once a clinical trial object is specified, the
package provides the functionality for estimating the power with Monte Carlo
simulations.

## Example

Here we emulate a simple parallel trial design with both observed and unobserved
covariates. The treatment effect is estimated using an estimator based on the
efficient influence function (EIF) where we adjust for the observed covariate x.

The necessary sample-size to achieve 90% power for a one-sided superiority test
is estimated using a variation of a bisection and a Robbins-Monro stochastic
approximation algorithm with parallelized computations
```{r carts1, cache=TRUE, output=FALSE}
library("carts")
library("data.table")
future::plan(future::multicore)
## progressr::handlers(global = TRUE)
## progressr::handlers(progressr::handler_cli)

## Covariates at baseline
x0 <- function(n, pa = 0.5, gamma.var = 0.7, ...) {
  data.table(
    a = rbinom(n, 1, pa), ## Treatment
    x = rnorm(n), ## Obs.
    z = log(rgamma(n, shape = 1 / gamma.var, rate = 1 / gamma.var)) ## Unobs.
  )
}
## Outcome model
outcome <- function(data, b = c(log(2.5), log(0.38)), ...) {
  X <- model.matrix(~ 1 + a, data)
  rate <- exp(X %*% b + with(data, x + z))
  data.table(y = rpois(length(rate), rate))
}

qmodel  <- targeted::learner_glm(y ~ a * x, family = poisson)
m <- Trial$new(
  covariates = x0,
  outcome = outcome,
  estimators = list(adj = est_adj(qmodel))
  )

## Sample-size estimation via Stochastic Approximation
e <- m$estimate_samplesize(R = 1000)
print(e)
```

## Installation

The package can be installed on all unix systems from the command line via `make
install`. Already installed R packages that are dependencies of `carts` will
not be upgrade with `make install`. Instead, use the `make upgrade` rule to
upgrade all dependencies, followed by the installation of the package.


## Project organization

We use the `dev` branch for development and the `main` branch for stable
releases. All releases follow [semantic versioning](https://semver.org/), are [tagged](https://github.com/NovoNordisk-OpenSource/carts/tags) and notable changes are reported in the [NEWS.md](https://github.com/NovoNordisk-OpenSource/carts/blob/main/NEWS.md) file.

## I Have a Question / I Want to Report a Bug

If you want to ask questions, require help or clarification, or report a bug, we recommend to either contact a maintainer directly or the following:

- Open an [Issue](https://github.com/NovoNordisk-OpenSource/carts/issues).
- Provide as much context as you can about what you're running into.
- Provide project and platform versions, depending on what seems relevant.

We will then take care of the issue as soon as possible.

## Maintainers
> Benedikt Sommer (benediktsommer92@gmail.com)\
> Klaus Kähler Holst (klaus@holst.it)

Versions across snapshots

VersionRepositoryFileSize
0.1.0 rolling linux/jammy R-4.5 carts_0.1.0.tar.gz 794.8 KiB
0.1.0 rolling linux/noble R-4.5 carts_0.1.0.tar.gz 796.3 KiB
0.1.0 rolling source/ R- carts_0.1.0.tar.gz 1.5 MiB
0.1.0 latest linux/jammy R-4.5 carts_0.1.0.tar.gz 794.8 KiB
0.1.0 latest linux/noble R-4.5 carts_0.1.0.tar.gz 796.3 KiB
0.1.0 latest source/ R- carts_0.1.0.tar.gz 1.5 MiB
0.1.0 2026-04-26 source/ R- carts_0.1.0.tar.gz 1.5 MiB
0.1.0 2026-04-23 source/ R- carts_0.1.0.tar.gz 1.5 MiB
0.1.0 2026-04-09 windows/windows R-4.5 carts_0.1.0.zip 1.0 MiB

Dependencies (latest)

Depends

Imports

LinkingTo

Suggests