# Method used in t.test()

The results of a t.test() in R provide a parameter $method which seems to be always equal to Welch Two Sample t-test which corrects for unequal variances. Are there other methods used in this function other than Welch's? I have looked in the documentation of the stats package in the CRAN repository but have not been able to find the source code for the t.test function nor information about t.test$method. Thanks for your help.

## 1 Answer

If you set var.equal = TRUE, then you will get the usual Student test without Welch's correction of the degrees of freedom. Similarly, if you run a one-sample t test or a paired t test, you will get different strings.

Here is the secret on how to see source code written in R. (Source code written in C, C++ or Fortran is another story).

Run methods(t.test). You will get the following output:

t.test.default* t.test.formula*

The * means that the method is hidden and not exported from its package (stats in this case). You can access it via stats:::t.test.default and you will get the code.

• Thanks for the secret. I am doing an F-test to determine whether the variances are equal and calculating the degrees of freedom accordingly. I am not using the t.test function but getting the p-values from pt(). It was tempting to let t.test() do the calculations but needed to be sure what was going on. Thanks for this very valuable information. Jun 6 '20 at 17:06