- Home
- Appointment Information
- Workshops
- Information for Staff
- Stats ResourcesToggle Dropdown
- Stats with SPSSToggle Dropdown
- Independent-Samples t-Test
- Paired-Samples t-Test
- Mann Whitney U-Test
- Wilcoxon Signed-Ranks Test
- One-Way Between-Subjects ANOVA
- One-Way Repeated-Measures ANOVA
- Two-Way Mixed ANOVA
- One-Way Between-Subjects ANCOVA
- Kruskal Wallis H-Test
- Friedman's ANOVA
- Pearson's 'r' Correlation
- Spearman's Rho Correlation
- Simple Linear Regression
- Multiple Linear Regression
- Chi-Squared (χ2) Test of Association
- Shapiro-Wilk Test of Normality
- Cronbach's Alpha

- Stats with R
- Stats with JamoviToggle Dropdown
- Maths ResourcesToggle Dropdown
- Numeracy ResourcesToggle Dropdown
- Stats/Maths Software
- A-Z of Terminology
- Meet the Team

An independent-samples t-test compares the means between two unrelated groups, such as comparing the difference between class 1 and class 2, another very common example would be used to compare a binary gender difference.

If you have more than three groups consider using a **One-Way Between-Subjects ANOVA**

It is considered a parametric test and is only suitable for parametric data. To check if your data is parametric, please read our dedicated guide: **Parametric or Not Guide (PDF)**

If your data is non-parametric you should consider using a **Mann-Whitney U-Test**.

Based on whether the two independent groups/samples have similar or different variances, you can run two types of t-tests in R. In order to learn how to check the equality of variances of two groups, please see our brief guide on Levene's test of equality of variances.

This is used for when the data is structured using a grouping variable. A grouping variable is a categorical variable indicating which scores belong to different groups.

Data:

The first argument entered in the t.test() function is a formula that takes the following structure: **dependent variable ~ independent variable**. In the case of t-tests, the independent variable should be a grouping variable with two categories (levels).

The second argument is the data frame.

By default, the t-test function is assuming that variances are unequal. It has an option called var.equal that is equal to FALSE by default. For that reason, no additional arguments are required here.

`t.test(English_Score ~ Class, englishdata1)`

```
##
## Welch Two Sample t-test
##
## data: English_Score by Class
## t = 0.89443, df = 12.303, p-value = 0.3883
## alternative hypothesis: true difference in means between group 1 and group 2 is not equal to 0
## 95 percent confidence interval:
## -1.429355 3.429355
## sample estimates:
## mean in group 1 mean in group 2
## 6 5
```

This method is used when your data is structured into two separate variables. Both of your variables should be numeric.

Data:

Put both of your variables in the t.test() function in any order. If you have your variables stored in a data frame, use the following structure to indicate the variable: data_frame$variable_name

`t.test(englishdata2$group1, englishdata2$group2)`

```
##
## Welch Two Sample t-test
##
## data: englishdata2$group1 and englishdata2$group2
## t = 0.89443, df = 12.303, p-value = 0.3883
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -1.429355 3.429355
## sample estimates:
## mean of x mean of y
## 6 5
```

Same as with the previously run t-test, the first argument entered in the t.test() function is a formula that takes the following structure: dependent variable ~ independent variable. In the case of t-tests, the independent variable should be a grouping variable with two categories (levels).

The second argument is the data frame.

The third argument is the option to run the t-test with equal variances assumed (var.equal = TRUE). The argument is FALSE by default, so we need to change it to TRUE.

`t.test(English_Score ~ Class, englishdata1, var.equal = TRUE)`

```
##
## Two Sample t-test
##
## data: English_Score by Class
## t = 0.89443, df = 14, p-value = 0.3862
## alternative hypothesis: true difference in means between group 1 and group 2 is not equal to 0
## 95 percent confidence interval:
## -1.397944 3.397944
## sample estimates:
## mean in group 1 mean in group 2
## 6 5
```

Similar to the previous example, this method is used when your data is structured into two separate variables. Both of your variables should be numeric.

For the first two arguments, put both of your variables in the t.test() function in any order. If you have your variables stored in a data frame, use the following structure to indicate the variable: data_frame$variable_name

The third argument is the option to run the t-test with equal variances assumed (var.equal = TRUE).

`t.test(englishdata2$group1, englishdata2$group2, var.equal = TRUE)`

```
##
## Two Sample t-test
##
## data: englishdata2$group1 and englishdata2$group2
## t = 0.89443, df = 14, p-value = 0.3862
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -1.397944 3.397944
## sample estimates:
## mean of x mean of y
## 6 5
```

R will generate largely the same output for both formula and variables methods.

The results show the means for the two groups, but no standard deviations. As standard deviations are commonly reported, please check our guide on **descriptive statistics**.

This table shows the specific test results including the t-statistic (t), the degrees of freedom (df) the two-tailed significance or p-value (Two-Sided p), and the 95% Confidence Interval (95% Confidence Interval of the Difference).

The only difference between the two tests is that for the Welch test, the degrees of freedom (df) are adjusted by a formula, making them smaller. This affects the p-value, making it less likel to be significant. They are reported in the exact same way.

*M *= 6.00, *SD* = 1.77) scored higher than class 2 students (*M* = 5.00, *SD *= 2.62). An independent-samples t-test indicated that this difference, 1.00, 95%*CI* [-1.40, 3.40], was not statistically significant, *t *(14) = 0.89, *p *=.386

- Last Updated: Apr 12, 2024 5:49 PM
- URL: https://guides.library.lincoln.ac.uk/mash
- Print Page

© University of Lincoln