Skip to contents

Analysis results data for paired and non-paired t-tests.

Usage

ard_ttest(data, by, variable, ...)

ard_paired_ttest(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 t.test(...)

id

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

Value

ARD data frame

Details

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

For the ard_paired_ttest() function, the data is expected to be one row per subject per by level. Before the t-test is calculated, the data are reshaped to a wide format to be one row per subject. The data are then passed as t.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_ttest(by = ARM, variable = AGE)
#> {cards} data frame: 11 x 9
#>    group1 variable context   stat_name stat_label      stat
#> 1     ARM      AGE   ttest    estimate  Mean Dif…     0.828
#> 2     ARM      AGE   ttest   estimate1  Group 1 …    75.209
#> 3     ARM      AGE   ttest   estimate2  Group 2 …    74.381
#> 4     ARM      AGE   ttest   statistic  t Statis…     0.655
#> 5     ARM      AGE   ttest     p.value    p-value     0.513
#> 6     ARM      AGE   ttest   parameter  Degrees …   167.362
#> 7     ARM      AGE   ttest    conf.low  CI Lower…    -1.668
#> 8     ARM      AGE   ttest   conf.high  CI Upper…     3.324
#> 9     ARM      AGE   ttest      method     method Welch Tw…
#> 10    ARM      AGE   ttest alternative  alternat… two.sided
#> 11    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_ttest(by = ARM, variable = AGE, id = USUBJID)
#> {cards} data frame: 9 x 9
#>   group1 variable context   stat_name stat_label      stat
#> 1    ARM      AGE   ttest    estimate  Mean Dif…     0.798
#> 2    ARM      AGE   ttest   statistic  t Statis…     0.628
#> 3    ARM      AGE   ttest     p.value    p-value     0.531
#> 4    ARM      AGE   ttest   parameter  Degrees …        83
#> 5    ARM      AGE   ttest    conf.low  CI Lower…    -1.727
#> 6    ARM      AGE   ttest   conf.high  CI Upper…     3.322
#> 7    ARM      AGE   ttest      method     method Paired t…
#> 8    ARM      AGE   ttest alternative  alternat… two.sided
#> 9    ARM      AGE   ttest      paired  Paired t…      TRUE
#>  3 more variables: fmt_fn, warning, error