TTEST() performs a t-test for one-sample, two-sample, paired, pairwise,
or formula-based comparisons.
Arguments
- .model
A model ID from
x_by(),pairwise(), or a formula. When supplied, the test executes immediately. WhenNULL(default), returns atest_specfor use in the pipeline viaprepare_test().- .data
A data frame. Only used on the standalone path.
- ...
Additional arguments passed to the implementation:
.paired,.mu,.alt,.cifor the classical path.
Supported model IDs
x_by()— two-sample or paired t-testpairwise()— pairwise t-tests across variablesformula — one-sample or two-sample t-test
Method variants (via via())
"boot"— bootstrap confidence interval"permute"— permutation test"permute_rfast"— permutation test backed by Rfast2
Examples
# eager
TTEST(x_by(extra, group), sleep)
#> -- Summary ---------------------------------------------------------------------
#>
#> ─────────────────────────────────
#> groups diff t-stat pval
#> ─────────────────────────────────
#> group -1.580 -1.861 0.079
#> ─────────────────────────────────
#>
#>
#> -- Confidence Interval ---------------------------------------------------------
#>
#> ──────────────────────────────
#> groups lower_95 upper_95
#> ──────────────────────────────
#> group -3.365 0.205
#> ──────────────────────────────
#>
#>
# pipeline
sleep |>
define_model(x_by(extra, group)) |>
prepare_test(TTEST) |>
conclude()
#>
#> == Model =======================================================================
#>
#> Model ID : x_by
#> Args : extra | group
#> x_vars : 1
#> by_vars : 1
#>
#> == T-Test ======================================================================
#>
#> -- Summary ---------------------------------------------------------------------
#>
#> ─────────────────────────────────
#> groups diff t-stat pval
#> ─────────────────────────────────
#> group -1.580 -1.861 0.079
#> ─────────────────────────────────
#>
#>
#> -- Confidence Interval ---------------------------------------------------------
#>
#> ──────────────────────────────
#> groups lower_95 upper_95
#> ──────────────────────────────
#> group -3.365 0.205
#> ──────────────────────────────
#>
#>
# bootstrap
sleep |>
define_model(x_by(extra, group)) |>
prepare_test(TTEST) |>
via("boot", n = 2000) |>
conclude()
#>
#> == Model =======================================================================
#>
#> Model ID : x_by
#> Args : extra | group
#> x_vars : 1
#> by_vars : 1
#>
#> == T-Test · boot ===============================================================
#>
#> ============================== Bootstrapped T-test =============================
#>
#>
#> -- Summary ---------------------------------------------------------------------
#>
#> Warning: running command 'tput cols' had status 2
#> ------------------------------
#> CI : [-3.21, 0.0702]
#> n_reps : 2000
#> ------------------------------
#>
#>
# permutation
sleep |>
define_model(x_by(extra, group)) |>
prepare_test(TTEST) |>
via("permute", n = 2000) |>
conclude()
#>
#> == Model =======================================================================
#>
#> Model ID : x_by
#> Args : extra | group
#> x_vars : 1
#> by_vars : 1
#>
#> == T-Test · permute ============================================================
#>
#> ============================== T-test Permutation ==============================
#>
#>
#> -- Summary ---------------------------------------------------------------------
#>
#> ───────────────────────────────
#> Statistic p-value n_perms
#> ───────────────────────────────
#> -1.580 0.092 2000
#> ───────────────────────────────
#>
#>