diff_ard_hierarchical: Rate Differences for Stacked Hierarchical ARDs

View source: R/diff_ard_hierarchical.R

diff_ard_hierarchicalR Documentation

Rate Differences for Stacked Hierarchical ARDs

Description

[Experimental]

Calculate the difference in event rates between two groups of a stacked hierarchical ARD created with ard_stack_hierarchical(). For every node in the hierarchy (e.g. each system organ class and each preferred term), the rate (p statistic) of a second group is subtracted from the rate of a first group and returned under a new statistic named "estimate".

The input ARD must contain the p statistic and at least one by variable. The by (grouping) dimension is collapsed in the result—only the estimate rows are returned.

Usage

diff_ard_hierarchical(x, levels = NULL)

Arguments

x

(card)
a stacked hierarchical ARD of class 'card' created using ard_stack_hierarchical(). Must contain the p statistic and at least one by variable.

levels

(list)
a list specifying the two groups being differenced, ⁠p(group 1) - p(group 2)⁠. Required unless x has a single by variable with exactly two levels, in which case the difference defaults to the first level minus the second level (in the order the levels appear in the source data). Two forms are accepted:

  • a flat named list keyed by a single by variable whose name is repeated to give its two levels in order, e.g. list(TRTA = "Xanomeline High Dose", TRTA = "Placebo"). When x has more than one by variable, every other by variable must also be named once to pin it to a single level.

  • a list of two named lists, each fully specifying one group's combination of by variable levels, e.g. list(list(TRTA = "Xanomeline High Dose"), list(TRTA = "Placebo")) or, with two by variables, list(list(TRTA = "Xanomeline High Dose", SEX = "F"), list(TRTA = "Placebo", SEX = "F")). This form is required when x has more than one by variable.

Defaults to NULL.

Details

Rates are stored on the ⁠[0, 1]⁠ scale (as p is), so the returned estimate values lie in ⁠[-1, 1]⁠. A hierarchy node observed in only one of the two groups is treated as a rate of 0 in the group where it is absent.

Value

an ARD data frame of class 'card'

See Also

sort_ard_hierarchical(), filter_ard_hierarchical()

Examples


ard <- ard_stack_hierarchical(
  ADAE,
  variables = c(AESOC, AEDECOD),
  by = TRTA,
  denominator = ADSL,
  id = USUBJID
)

# difference between two of the three treatment arms
diff_ard_hierarchical(ard, levels = list(TRTA = "Xanomeline High Dose", TRTA = "Placebo"))

# equivalent, using the two-cell form
diff_ard_hierarchical(
  ard,
  levels = list(list(TRTA = "Xanomeline High Dose"), list(TRTA = "Placebo"))
)


cards documentation built on Aug. 21, 2026, 5:09 p.m.