## Course description

The **t-test** can be defined as a statistical test used to compare two means. This guide provide multiple tutorials describing the different types of t-test, including:

*one-sample t-tests*. Compares one-sample mean to a know standard mean.*independent samples t-tests: Student’s t-test and Welch’s t-test*. Compares two independent groups*paired samples t-test*. Compares two related samples.

You will learn the *t-test formula* and how to:

**Compute the different t-tests in R****Check t-test assumptions****Calculate and report t-test effect size**using*Cohen’s d*.

Contents:

#### Related Book

Practical Statistics in R II - Comparing Groups: Numerical Variables## Prerequisites

Make sure you have installed the following R packages:

`tidyverse`

for data manipulation and visualization`ggpubr`

for creating easily publication ready plots`rstatix`

provides pipe-friendly R functions for easy statistical analyses.`datarium`

: contains required data sets for this chapter.

Start by loading the following required packages:

```
library(tidyverse)
library(ggpubr)
library(rstatix)
```

## Examples of R codes

Comparing two independent groups:

```
# Data preparation
data("genderweight", package = "datarium")
head(genderweight, 3)
```

```
## # A tibble: 3 x 3
## id group weight
## <fct> <fct> <dbl>
## 1 1 F 61.6
## 2 2 F 64.6
## 3 3 F 66.2
```

```
# Statistical test
stat.test <- genderweight %>%
t_test(weight ~ group) %>%
add_significance()
stat.test
```

```
## # A tibble: 1 x 9
## .y. group1 group2 n1 n2 statistic df p p.signif
## <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <chr>
## 1 weight F M 20 20 -20.8 26.9 4.30e-18 ****
```

```
# Visualization:
# Create a box-plot
bxp <- ggboxplot(
genderweight, x = "group", y = "weight",
ylab = "Weight", xlab = "Groups", add = "jitter"
)
# Add p-value and significance levels
stat.test <- stat.test %>% add_xy_position(x = "group")
bxp +
stat_pvalue_manual(stat.test, tip.length = 0) +
labs(subtitle = get_test_label(stat.test, detailed = TRUE))
```

Version: Français

Fantastic lesson! I’m currently bingeing all of Alboukadel Kassambara’s lessons on this website. Really clear and concise.

Thank you for your positive feedback, highly apprecited

Hi, I have just completed this first course on your website. What a fantastic work – simple, concise and clear, but most of all – with a workable expamles! I enoyed it very much and I’m sure to use many of your other courses right away!

Thanks for all your good work!

Thank you very much for the positive feed. I’m very happy that it was useful for you.