The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.

cardx cardx website

R-CMD-check Codecov test coverage

The {cardx} package is an extension of the {cards} package, providing additional functions to create Analysis Results Data Objects (ARDs) using the R programming language. The {cardx} package exports ARD functions that uses utility functions from {cards} and statistical functions from additional packages (such as, {stats}, {mmrm}, {emmeans}, {car}, {survey}, etc.) to construct summary objects.

Summary objects can be used to:

Installation

Install cards from CRAN with:

install.packages("cardx")

You can install the development version of cards from GitHub with:

# install.packages("devtools")
devtools::install_github("insightsengineering/cardx")

Examples

Example ARD Creation

Example t-test:

library(cardx)

cards::ADSL |>
  # keep two treatment arms for the t-test calculation
  dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |>
  cardx::ard_stats_t_test(by = ARM, variable = AGE)
## {cards} data frame: 14 x 9

##    group1 variable   context   stat_name stat_label      stat
## 1     ARM      AGE stats_t_…    estimate  Mean Dif…     0.828
## 2     ARM      AGE stats_t_…   estimate1  Group 1 …    75.209
## 3     ARM      AGE stats_t_…   estimate2  Group 2 …    74.381
## 4     ARM      AGE stats_t_…   statistic  t Statis…     0.655
## 5     ARM      AGE stats_t_…     p.value    p-value     0.513
## 6     ARM      AGE stats_t_…   parameter  Degrees …   167.362
## 7     ARM      AGE stats_t_…    conf.low  CI Lower…    -1.668
## 8     ARM      AGE stats_t_…   conf.high  CI Upper…     3.324
## 9     ARM      AGE stats_t_…      method     method Welch Tw…
## 10    ARM      AGE stats_t_… alternative  alternat… two.sided
## 11    ARM      AGE stats_t_…          mu    H0 Mean         0
## 12    ARM      AGE stats_t_…      paired  Paired t…     FALSE
## 13    ARM      AGE stats_t_…   var.equal  Equal Va…     FALSE
## 14    ARM      AGE stats_t_…  conf.level  CI Confi…      0.95

## ℹ 3 more variables: fmt_fn, warning, error

Note that the returned ARD contains the analysis results in addition to the function parameters used to calculate the results allowing for reproducible future analyses and further customization.

Model Input

Some {cardx} functions accept regression model objects as input:

lm(AGE ~ ARM, data = cards::ADSL) |>
  ard_aod_wald_test()

Note that the Analysis Results Standard should begin with a data set rather than a model object. To accomplish this we include model construction helpers.

construct_model(
  data = cards::ADSL,
  formula = reformulate2("ARM", response = "AGE"),
  method = "lm"
) |>
  ard_aod_wald_test()
## {cards} data frame: 6 x 8

##      variable   context stat_name stat_label     stat fmt_fn
## 1 (Intercept) aod_wald…        df  Degrees …        1      1
## 2 (Intercept) aod_wald… statistic  Statistic 7126.713      1
## 3 (Intercept) aod_wald…   p.value    p-value        0      1
## 4         ARM aod_wald…        df  Degrees …        2      1
## 5         ARM aod_wald… statistic  Statistic    1.046      1
## 6         ARM aod_wald…   p.value    p-value    0.593      1

## ℹ 2 more variables: warning, error

Additional Resources

{cardx} + {renv}

The {cardx} package exports functions to create ARDs based on various statistical methods; methods that are primarily implemented in other packages. {cardx} does not take a hard dependency on these packages, meaning that these packages are not typically installed when {cardx} is installed from CRAN. As a result, {renv} will not record these packages in its lock.file unless there is a direct reference to the underlying statistical package in your code. For example, if you pass a regression model to ard_emmeans_mean_difference(), there is no direct reference to the {emmeans} package in your script and {renv} will not record the package.

One can circumvent this issue by including some kind of reference to the package in your code. Below are are couple of common ways to do so.

library(emmeans)

Attaching a package with library() is great for its simplicity, but you may not want to attach a package if it’s not necessary.

invisible(emmeans::emmeans)

You can invisibly print a function from the package. Printing a function does not have an effect on your environment (which is great), but it is somewhat more difficult to read. (This is my preferred method.)

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.