Skip to content
R for the Rest of Us Logo

Inferential Statistics with R

Independent t-test

Transcript

Click on the transcript to go to that point in the video. Please note that transcripts are auto generated and may contain minor inaccuracies.

Your Turn

  1. Perform an independent samples t-test to test whether there is a difference in exam_1 by athlete. Use var.equal = TRUE. Is there a difference? What is the p-value?

  2. Perform an independent samples t-test to test whether there is a difference in act_english by gender. Use var.equal = TRUE. Is there a difference? What is the p-value?

Notice what happens since gender has 3 levels. Try out using the filter() function from dplyr to only check the difference between Female and Male students. Alternatively, check out the page on t_test() to see how to use the comparisons argument to specify the groups to compare.

Learn More

We are using the rstatix package for the t_test() function (and other functions in later lessons). We use this package because it is tidyverse-friendly while some base R functions for inferential statistics are not. If you did want to use the base R equivalent function for a t-test, it is t.test().

Have any questions? Put them below and we will help you out!

You need to be signed-in to comment on this post. Login.

gene trevino

gene trevino • January 26, 2025

Just curious why my output is not in the same format as yours. This is how mine appears.

.y. group1 group2 n1 n2 statistic df p

Thanks

David Keyes

David Keyes Founder • January 27, 2025

We'd have to see your exact code to be able to give you an answer.

gene trevino

gene trevino • January 27, 2025

college %>% select(exam_1, exam_2) %>% pivot_longer(cols = everything(), names_to = "exam", values_to = "score") %>% t_test(score ~exam, paired = TRUE)

Thanks, Gene Trevino

David Keyes

David Keyes Founder • January 29, 2025

I believe the difference is because Dana is displaying her output using a table function. The difference is merely aesthetic though – the output is identical to yours.

gene trevino

gene trevino • January 29, 2025

How can I learn about the table function ?

David Keyes

David Keyes Founder • January 29, 2025

These slides are made with the {xaringan} package. You can learn about that in my book. In terms of options to make tables, see this blog post. There are many packages to make tables. I typically recommend {gt} and {flextable}.