2025-09-20

Introduction to T Tests

Brief History of the T Test

  • The T Test was invented by a guy named William Gosset.
  • Gosset was employed by Guinness and used this as a primitive way to analyze and estimate barley crop yields.
  • Gosset was allowed to publish his work under the name “Student” to not give away any of Guinness’s confidential information.
  • He later partnered with Ronald Fisher who refined the t-test to be what it is today.
  • (see end slide for references)

What is the the T Test used for?

  • The “Student’s” t-test is used to compare the means of two groups to test if the difference between those means is statistically significant.
  • It is very possible that two groups with apparently different means have no statistically significant difference between them due to larger variance.

Assumptions for the T Test

  • Normal distribution
  • Measurement scale is continuous
  • Only two means/values are being compared

Types of T Tests

  • Paired T Test: A comparison of the same group before and after a specific event
  • Independent T Test: A comparison of the means of two independent groups
  • One Sample T Test: A comparison of the mean of one group with an expected or known value

How to Perform an Independent T Test

Independent T Test

\[ t = \frac{\bar{x_1} - \bar{x_2}}{\sqrt{\frac{s_1^2}{n_1} + \frac{s_2^2}{n_2}}} \]

  • t = the t value
  • x_bar_1 = the mean of the first group
  • x_bar_2 = the mean of the second group
  • s_1 = the standard deviation of the first group
  • s_2 = the standard deviation of the second group
  • n_1 = the number of samples in group 1
  • n_2 = the number of samples in group 2

How to Perform a Paired T Test

Paired T Test Calculation \[ t = \frac{\bar{D}}{s_D / \sqrt{n}} \] * D_bar = the mean of the differences * sD = the standard deviation of the differences * n = the number of samples or sample size

Code for T Test in R and Sample output

  • In R, the code for a t test is as follows:
  •      (t.test(group1, group2, paired = TRUE or FALSE, var.equal = TRUE or FALSE))
  • As you can see, this allows for different kinds of t tests.

Here is a sample data frame:

And another example from the same data frame

T Test Output

  • Here is a sample output of the t test from the reading_hours data frame comparing the number of hours read daily by students who are in school vs students who are not. Note: This data is completely made up
## 
##  Welch Two Sample t-test
## 
## data:  in_school_group and out_school_group
## t = -0.16059, df = 17.95, p-value = 0.8742
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -5.634183  4.834183
## sample estimates:
## mean of x mean of y 
##       4.6       5.0
  • because our p value is greater than 0.05, one could conclude that there is no significant difference between the two groups

T Tables

  • Most commonly, unless you have software calculating this for you, you would use a t table paired with the desired p value to find if your data is significant or not.
  • Based on this, you would be able to reject or accept the null hypothesis.

References