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.
diff_ard_hierarchical(x, levels = NULL)(card)
a stacked hierarchical ARD of class 'card' created using
ard_stack_hierarchical(). Must contain the p statistic and at least one
by variable.
(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.
an ARD data frame of class 'card'
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.
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>