
Rate Differences for Stacked Hierarchical ARDs
Source:R/diff_ard_hierarchical.R
diff_ard_hierarchical.RdCalculate 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.
Arguments
- x
(
card)
a stacked hierarchical ARD of class'card'created usingard_stack_hierarchical(). Must contain thepstatistic and at least onebyvariable.- levels
(
list)
a list specifying the two groups being differenced,p(group 1) - p(group 2). Required unlessxhas a singlebyvariable 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
byvariable whose name is repeated to give its two levels in order, e.g.list(TRTA = "Xanomeline High Dose", TRTA = "Placebo"). Whenxhas more than onebyvariable, every otherbyvariable 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
byvariable levels, e.g.list(list(TRTA = "Xanomeline High Dose"), list(TRTA = "Placebo"))or, with twobyvariables,list(list(TRTA = "Xanomeline High Dose", SEX = "F"), list(TRTA = "Placebo", SEX = "F")). This form is required whenxhas more than onebyvariable.
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.
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"))
#> # An ARD data frame: 265 × 11
#> group1 group1_level variable variable_level context stat_name stat
#> <chr> <list> <chr> <list> <chr> <chr> <list>
#> 1 NA <NULL> AESOC CARDIAC DISORDERS diff_h… estimate 0.0631
#> 2 AESOC CARDIAC DISORDERS AEDECOD ATRIAL FIBRILLAT… diff_h… estimate 0.0241
#> 3 AESOC CARDIAC DISORDERS AEDECOD ATRIAL FLUTTER diff_h… estimate 0.0119
#> 4 AESOC CARDIAC DISORDERS AEDECOD ATRIAL HYPERTROP… diff_h… estimate -0.0116
#> 5 AESOC CARDIAC DISORDERS AEDECOD ATRIOVENTRICULAR… diff_h… estimate -0.0116
#> 6 AESOC CARDIAC DISORDERS AEDECOD ATRIOVENTRICULAR… diff_h… estimate 0.0125
#> 7 AESOC CARDIAC DISORDERS AEDECOD BRADYCARDIA diff_h… estimate -0.0116
#> 8 AESOC CARDIAC DISORDERS AEDECOD BUNDLE BRANCH BL… diff_h… estimate -0.0116
#> 9 AESOC CARDIAC DISORDERS AEDECOD BUNDLE BRANCH BL… diff_h… estimate -0.0116
#> 10 AESOC CARDIAC DISORDERS AEDECOD CARDIAC DISORDER diff_h… estimate 0.0119
#> # ℹ 255 more rows
#> # ℹ 4 more variables: stat_label <chr>, fmt_fun <list>, warning <list>,
#> # error <list>
# equivalent, using the two-cell form
diff_ard_hierarchical(
ard,
levels = list(list(TRTA = "Xanomeline High Dose"), list(TRTA = "Placebo"))
)
#> # An ARD data frame: 265 × 11
#> group1 group1_level variable variable_level context stat_name stat
#> <chr> <list> <chr> <list> <chr> <chr> <list>
#> 1 NA <NULL> AESOC CARDIAC DISORDERS diff_h… estimate 0.0631
#> 2 AESOC CARDIAC DISORDERS AEDECOD ATRIAL FIBRILLAT… diff_h… estimate 0.0241
#> 3 AESOC CARDIAC DISORDERS AEDECOD ATRIAL FLUTTER diff_h… estimate 0.0119
#> 4 AESOC CARDIAC DISORDERS AEDECOD ATRIAL HYPERTROP… diff_h… estimate -0.0116
#> 5 AESOC CARDIAC DISORDERS AEDECOD ATRIOVENTRICULAR… diff_h… estimate -0.0116
#> 6 AESOC CARDIAC DISORDERS AEDECOD ATRIOVENTRICULAR… diff_h… estimate 0.0125
#> 7 AESOC CARDIAC DISORDERS AEDECOD BRADYCARDIA diff_h… estimate -0.0116
#> 8 AESOC CARDIAC DISORDERS AEDECOD BUNDLE BRANCH BL… diff_h… estimate -0.0116
#> 9 AESOC CARDIAC DISORDERS AEDECOD BUNDLE BRANCH BL… diff_h… estimate -0.0116
#> 10 AESOC CARDIAC DISORDERS AEDECOD CARDIAC DISORDER diff_h… estimate 0.0119
#> # ℹ 255 more rows
#> # ℹ 4 more variables: stat_label <chr>, fmt_fun <list>, warning <list>,
#> # error <list>