Skip to contents

The formula implementation performs one-sample or two-sample t-tests specified via a standard R formula. The response variable is taken from the left-hand side; the right-hand side determines the test type:

  1. y ~ group: two-sample t-test, one test per grouping variable.

  2. y ~ 1: one-sample t-test against .mu.

  3. y ~ group + 1" both tests in a single call.

Use a formula directly as the variable mapper <var_id> to select this implementation.

Arguments

The following arguments are passed via ... in TTEST():

.mu

Numeric. Hypothesized mean or mean difference. Default 0.

.alt

String. One of "two.sided", "greater", or "less". Default "two.sided".

.ci

Numeric. Confidence level. Default 0.95.

Variants

No variants are currently registered for the formula path. Use add_variant() to register custom variants at the user or package level.

Formula-based t-test class

Returns a tibble with columns type, group, and ttest (a list-column of stats::t.test() objects). This path does not currently return a class_stat_infer subclass. Otherwise, to process outputs:

See also

Other ttest-implementations: ttest-on, ttest-pairwise, ttest-xby

Examples

sleep |>
    define_model(extra ~ group) |>
    prepare_test(TTEST) |>
    conclude()
#> 
#> == Model ======================================================================= 
#> 
#> Variable Mapper : formula 
#> Args : extra ~ group 
#>     left_var : 1 
#>     right_var : 1 
#> 
#> == T-Test ====================================================================== 
#> 
#> -- Summary ---------------------------------------------------------------------
#> 
#> ───────────────────────────────────────────────────────
#>   groups     type     est_type   est    t-stat  pval   
#> ───────────────────────────────────────────────────────
#>   group   two sample  mu_diff   -1.580  -1.861  0.079  
#> ───────────────────────────────────────────────────────
#> 
#> 
#> -- Confidence Interval ---------------------------------------------------------
#> 
#> ──────────────────────────────────────────
#>   groups     type     lower_95  upper_95  
#> ──────────────────────────────────────────
#>   group   two sample   -3.365    0.205    
#> ──────────────────────────────────────────
#> 
#> 

# one-sample
sleep |>
    define_model(extra ~ 1) |>
    prepare_test(TTEST) |>
    conclude()
#> 
#> == Model ======================================================================= 
#> 
#> Variable Mapper : formula 
#> Args : extra ~ 1 
#>     left_var : 1 
#>     right_var : 0 
#> 
#> == T-Test ====================================================================== 
#> 
#> -- Summary ---------------------------------------------------------------------
#> 
#> ───────────────────────────────────────────────────────
#>   groups     type     est_type   est   t-stat   pval   
#> ───────────────────────────────────────────────────────
#>     1     one sample     mu     1.540  3.413   <0.001  
#> ───────────────────────────────────────────────────────
#> 
#> 
#> -- Confidence Interval ---------------------------------------------------------
#> 
#> ──────────────────────────────────────────
#>   groups     type     lower_95  upper_95  
#> ──────────────────────────────────────────
#>     1     one sample   0.596     2.484    
#> ──────────────────────────────────────────
#> 
#> 

# both in one call
sleep |>
    define_model(extra ~ group + 1) |>
    prepare_test(TTEST) |>
    conclude()
#> 
#> == Model ======================================================================= 
#> 
#> Variable Mapper : formula 
#> Args : extra ~ group + 1 
#>     left_var : 1 
#>     right_var : 1 
#> 
#> == T-Test ====================================================================== 
#> 
#> -- Summary ---------------------------------------------------------------------
#> 
#> ────────────────────────────────────────────────────────
#>   groups     type     est_type   est    t-stat   pval   
#> ────────────────────────────────────────────────────────
#>   group   two sample  mu_diff   -1.580  -1.861  0.079   
#>     1     one sample     mu     1.540   3.413   <0.001  
#> ────────────────────────────────────────────────────────
#> 
#> 
#> -- Confidence Interval ---------------------------------------------------------
#> 
#> ──────────────────────────────────────────
#>   groups     type     lower_95  upper_95  
#> ──────────────────────────────────────────
#>   group   two sample   -3.365    0.205    
#>     1     one sample   0.596     2.484    
#> ──────────────────────────────────────────
#> 
#>