Skip to contents

[Experimental]

This function is used to sort stacked hierarchical ARDs.

For the purposes of this function, we define a "variable group" as a combination of ARD rows grouped by the combination of all their variable levels, but excluding any by variables.

Usage

sort_ard_hierarchical(x, sort = c("descending", "alphanumeric"))

Arguments

x

(card)
a stacked hierarchical ARD of class 'card' created using ard_stack_hierarchical() or ard_stack_hierarchical_count().

sort

(string)
type of sorting to perform. Value must be one of:

  • "alphanumeric" - within each hierarchical section of the ARD, groups are ordered alphanumerically (i.e. A to Z) by variable_level text.

  • "descending" - within each variable group of the ARD, count sums are calculated for each group and groups are sorted in descending order by sum. If sort = "descending", the n statistic is used to calculate variable group sums if included in statistic for all variables, otherwise p is used. If neither n nor p are present in x for all variables, an error will occur.

Defaults to "descending".

Value

an ARD data frame of class 'card'

Note

If overall data is present in x (i.e. the ARD was created with ard_stack_hierarchical(overall=TRUE)), the overall data will be sorted last within each variable group (i.e. after any other rows with the same combination of variable levels).

Examples

ard_stack_hierarchical(
  ADAE,
  variables = c(AESOC, AEDECOD),
  by = TRTA,
  denominator = ADSL |> dplyr::rename(TRTA = ARM),
  id = USUBJID
) |>
  sort_ard_hierarchical("alphanumeric")
#> {cards} data frame: 2394 x 13
#>    group1 group1_level group2 group2_level variable variable_level stat_name
#> 1    <NA>                <NA>                  TRTA        Placebo         n
#> 2    <NA>                <NA>                  TRTA        Placebo         N
#> 3    <NA>                <NA>                  TRTA        Placebo         p
#> 4    <NA>                <NA>                  TRTA      Xanomeli…         n
#> 5    <NA>                <NA>                  TRTA      Xanomeli…         N
#> 6    <NA>                <NA>                  TRTA      Xanomeli…         p
#> 7    <NA>                <NA>                  TRTA      Xanomeli…         n
#> 8    <NA>                <NA>                  TRTA      Xanomeli…         N
#> 9    <NA>                <NA>                  TRTA      Xanomeli…         p
#> 10   TRTA      Placebo   <NA>                 AESOC      CARDIAC …         n
#>    stat_label  stat
#> 1           n    86
#> 2           N   254
#> 3           % 0.339
#> 4           n    84
#> 5           N   254
#> 6           % 0.331
#> 7           n    84
#> 8           N   254
#> 9           % 0.331
#> 10          n    13
#>  2384 more rows
#>  Use `print(n = ...)` to see more rows
#>  4 more variables: context, fmt_fn, warning, error

ard_stack_hierarchical_count(
  ADAE,
  variables = c(AESOC, AEDECOD),
  by = TRTA,
  denominator = ADSL |> dplyr::rename(TRTA = ARM)
) |>
  sort_ard_hierarchical("descending")
#> {cards} data frame: 804 x 13
#>    group1 group1_level group2 group2_level variable variable_level stat_name
#> 1    <NA>                <NA>                  TRTA        Placebo         n
#> 2    <NA>                <NA>                  TRTA        Placebo         N
#> 3    <NA>                <NA>                  TRTA        Placebo         p
#> 4    <NA>                <NA>                  TRTA      Xanomeli…         n
#> 5    <NA>                <NA>                  TRTA      Xanomeli…         N
#> 6    <NA>                <NA>                  TRTA      Xanomeli…         p
#> 7    <NA>                <NA>                  TRTA      Xanomeli…         n
#> 8    <NA>                <NA>                  TRTA      Xanomeli…         N
#> 9    <NA>                <NA>                  TRTA      Xanomeli…         p
#> 10   TRTA      Placebo   <NA>                 AESOC      GENERAL …         n
#>    stat_label  stat
#> 1           n    86
#> 2           N   254
#> 3           % 0.339
#> 4           n    84
#> 5           N   254
#> 6           % 0.331
#> 7           n    84
#> 8           N   254
#> 9           % 0.331
#> 10          n    48
#>  794 more rows
#>  Use `print(n = ...)` to see more rows
#>  4 more variables: context, fmt_fn, warning, error