A function for a bootstrap method for t-tests.

boot_t_test(x, ...)

# S3 method for default
  y = NULL,
  var.equal = FALSE,
  paired = FALSE,
  alternative = c("two.sided", "less", "greater", "equivalence", "minimal.effect"),
  mu = 0,
  alpha = 0.05,
  boot_ci = c("stud", "basic", "perc"),
  R = 1999,

# S3 method for formula
boot_t_test(formula, data, subset, na.action, ...)



a (non-empty) numeric vector of data values.


further arguments to be passed to or from methods.


an optional (non-empty) numeric vector of data values.


a logical variable indicating whether to treat the two variances as being equal. If TRUE then the pooled variance is used to estimate the variance otherwise the Welch (or Satterthwaite) approximation to the degrees of freedom is used.


a logical indicating whether you want a paired t-test.


a character string specifying the alternative hypothesis, must be one of "two.sided" (default), "greater", "less", "equivalence" (TOST), or "minimal.effect" (TOST). You can specify just the initial letter.


a number specifying an optional parameter used to form the null hypothesis. See ‘Details’.


alpha level (default = 0.05)


type of bootstrap confidence interval. Options include studentized (stud), empirical/basic (basic) and percentile (perc) confidence intervals.


number of bootstrap replicates


a formula of the form lhs ~ rhs where lhs is a numeric variable giving the data values and rhs either 1 for a one-sample or paired test or a factor with two levels giving the corresponding groups. If lhs is of class "Pair" and rhs is 1, a paired test is done.


an optional matrix or data frame (or similar: see model.frame) containing the variables in the formula formula. By default the variables are taken from environment(formula).


an optional vector specifying a subset of observations to be used.


a function which indicates what should happen when the data contain NAs. Defaults to getOption("na.action").


A list with class "htest" containing the following components:

  • "statistic": the value of the t-statistic.

  • "parameter": the degrees of freedom for the t-statistic.

  • "p.value": the p-value for the test.

  • "conf.int": a confidence interval for the mean appropriate to the specified alternative hypothesis.

  • "estimate": the estimated mean or difference in means depending on whether it was a one-sample test or a two-sample test.

  • "null.value": the specified hypothesized value of the mean or mean difference. May be 2 values.

  • "stderr": the standard error of the mean (difference), used as denominator in the t-statistic formula.

  • "alternative": a character string describing the alternative hypothesis.

  • "method": a character string indicating what type of t-test was performed.

  • "data.name": a character string giving the name(s) of the data.


The implemented test(s) corresponds to the proposal of Chapter 16 of Efron and Tibshirani (1994).

For two-sample tests, the test is of \(\bar x - \bar y\) (mean of x minus mean of y). For paired samples, the test is of the difference scores (z), wherein \(z = x - y\), and the test is of \(\bar z\) (mean of the difference scores). For one-sample tests, the test is of \(\bar x \) (mean of x).

For details on the calculations in this function see vignette("robustTOST").


Efron, B., & Tibshirani, R. J. (1994). An introduction to the bootstrap. CRC press.

See also

Other Robust tests: boot_log_TOST(), boot_t_TOST(), brunner_munzel(), log_TOST(), wilcox_TOST()


# example code

boot_t_test(extra ~ group, data = sleep)
#> 	Bootstrapped Welch Two Sample t-test
#> data:  extra by group
#> p-value = 0.04902
#> alternative hypothesis: true difference in means is not equal to 0
#> 95 percent confidence interval:
#>  -3.2905761  0.1709839
#> sample estimates:
#> mean of x mean of y 
#>      0.75      2.33