There are various functions in R for carrying out a t-test.
GeeksforGeeks (2021) gives
examples for using the t-tests for one sample, two sample, and paired samples. The one-
sample t-test uses “t.test(x, mu= ). The two-sample test will use the syntax “t.test(v1, v2,
var.equal = TRUE/FALSE). Interestingly enough, GeeksforGeeks says R assumes there is
unequal variance, hence the need for the “var.equal” to be TRUE or FALSE.
Statology (2021) talks about the difference between equal and unequal variance. The
“Student’s t-test” assume normal distribution and same variance, whereas “Welch’s t-test”
assumes normal distribution, but not the same variance. Statology (2019) says the Welch test
should be the default because “it performs better than the Student’s t-test when sample sizes
and variances are unequal between groups, and it gives identical results when sample sizes
are variances are equal.” In R, this is done with the “t.test(1,2)” functionality where the 1 and 2
are the different samples/variables.
Statology (2020) gives the example of a teacher with students who prepared for an exam,
versus those who did not. Because R defaults to assuming unequal variance, the format here
is “t.test(group1,group2)”. In that example, the two sample t-test was the correct test to use
because of the different variables.
References
GeeksforGeeks. (2021, December 16). T-Test Approach in R Programming. GeeksforGeeks.
Retrieved March 18, 2023, from https://www.geeksforgeeks.org/t-test-approach-in-r-
programming/
Statology. (2019, May 29). Welch's t-test: When to Use it + Examples. Statology. Retrieved March
18, 2023, from https://www.statology.org/welchs-t-test/
Statology. (2020, October 21). How to Perform Welch's t-Test in R. Statology. Retrieved March 18,
2023, from https://www.statology.org/welch-t-test-in-r/
Statology. (2021, April 11). How to Determine Equal or Unequal Variance in t-tests. Statology.
Retrieved March 18, 2023, from https://www.statology.org/determine-equal-or-unequal-
variance/