Skip to contents

Analysis results data for paired and non-paired Wilcoxon Rank-Sum tests.

Usage

ard_wilcoxtest(data, by, variable, ...)

ard_paired_wilcoxtest(data, by, variable, id, ...)

Arguments

data

(data.frame)
a data frame. See below for details.

by

(tidy-select)
column name to compare by.

variable

(tidy-select)
column name to be compared.

...

arguments passed to wilcox.test(...)

id

(tidy-select)
column name of the subject or participant ID.

Value

ARD data frame

Details

For the ard_wilcoxtest() function, the data is expected to be one row per subject. The data is passed as wilcox.test(data[[variable]] ~ data[[by]], paired = FALSE, ...).

For the ard_paired_wilcoxtest() function, the data is expected to be one row per subject per by level. Before the test is calculated, the data are reshaped to a wide format to be one row per subject. The data are then passed as wilcox.test(x = data_wide[[<by level 1>]], y = data_wide[[<by level 2>]], paired = TRUE, ...).

Examples

cards::ADSL |>
  dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |>
  ard_wilcoxtest(by = "ARM", variable = "AGE")
#> {cards} data frame: 5 x 9
#>   group1 variable context   stat_name stat_label      stat
#> 1    ARM      AGE   ttest   statistic  X-square…    3862.5
#> 2    ARM      AGE   ttest     p.value    p-value     0.435
#> 3    ARM      AGE   ttest      method     method Wilcoxon…
#> 4    ARM      AGE   ttest alternative  alternat… two.sided
#> 5    ARM      AGE   ttest      paired  Paired t…     FALSE
#>  3 more variables: fmt_fn, warning, error

# constructing a paired data set,
# where patients receive both treatments
cards::ADSL[c("ARM", "AGE")] |>
  dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |>
  dplyr::mutate(.by = ARM, USUBJID = dplyr::row_number()) |>
  dplyr::arrange(USUBJID, ARM) |>
  ard_paired_wilcoxtest(by = ARM, variable = AGE, id = USUBJID)
#> {cards} data frame: 5 x 9
#>   group1 variable context   stat_name stat_label      stat
#> 1    ARM      AGE   ttest   statistic  X-square…      1754
#> 2    ARM      AGE   ttest     p.value    p-value     0.522
#> 3    ARM      AGE   ttest      method     method Wilcoxon…
#> 4    ARM      AGE   ttest alternative  alternat… two.sided
#> 5    ARM      AGE   ttest      paired  Paired t…      TRUE
#>  3 more variables: fmt_fn, warning, error