T-Tests in R

A t-test is a type of inferential statistic used to determine if there is a significant difference between the means of two groups.

Note: When the output says p-value => 4.903e-08 this also means <0.0001.

Load Packages

packages <- c("tidyverse", "ggpubr", "ggcorrplot")

packages <- lapply(packages, FUN = function(x) {

if(!require(x, character.only = TRUE)) {install.packages(x)

library(x, character.only = TRUE)}})

Load dataset

data <- ToothGrowth

Independent 2-Group T-Test

One numeric and one binary factor

t.test(df$len ~ df$supp)

Create Plot

plot <- ggboxplot(df, x = "supp", y = "len", color = "supp", palette = "jco", add = "jitter") +

stat_compare_means() # Add p-value


Both are numeric

t.test(df$len, df$dose)

plot <- ggboxplot(df, x = "len", y = "dose", color = "supp", palette = "jco", add = "jitter") +

stat_compare_means() # Add p-value


Paired T-Test

One numeric and one binary factor

compare_means(len ~ supp, data = df, paired = TRUE)

Create Plot

ggpaired(df, x = "supp", y = "len", color = "supp", line.color = "gray", line.size = 0.4, palette = "jco")+stat_compare_means(paired = TRUE)

Both are numeric

t.test(df$len, df$dose, paired=TRUE)

One Sample T-Test

Ho: mu=3

t.test(df$len, mu=3)

You can use the var.equal = TRUE option to specify equal variances and a pooled variance estimate. You can use the alternative="less" or alternative="greater" option to specify a one tailed test.

The value 2.2e-16 actually means 2.2 X 10 ^ -16. It is just a way R prints numbers that are either too big or too small. As you said that if the P-Value is less than 0.05, we reject the null hypothesis in case of test with 95% confidence or 5% significance. In general, we reject the null hypothesis when the P-value is less then the level of significance of the test.And if you're doing at test with 95% confidence or 5% significance, P-value of 2.2 X 10 ^-16 is very less compared to 5%=0.05. So you will reject the null hypothesis.

Sabalico Logo
Sabali Mail Logo
Domain Search Logo
Test Speed Logo
Website On Logo
Page Load Logo
Code Editor Logo
Format Code Logo
HTML Validator Logo
CSS Validator Logo
ASCII Table Logo
HTML Symbols Logo
Emoji Symbols Logo
Encode File Logo
Sitemap Generator Logo
Generator Password Logo
QR Code Generator Logo
Barcode Generator Logo
Online Sign Logo
Dictionary Online Logo
Counter Word Logo
Text Convert Logo
Lorem Ipsum Generator Logo
Sprite Sheet Logo
Edit Picture Logo
Resize Image Logo
Image Compress Logo
Image Color Logo
Image Crop Logo
Combine Images Logo
Favicon Generator Logo
Color Palette Logo
Color Picker Logo
Color Mix Logo
Color Convert Logo
CSS Gradient Logo
To-Do List Logo
Calendar Free Logo
Generator Meme Logo
Word Spinner Logo
Phone Country Logo
Sabalytics Logo
Senty Logo
World Map Logo
SEO Guide Logo
Keyword Tool Logo
What is my IP Logo
My Device Logo
My Browser Logo
My Location Logo
Time Zone Logo
Day Map Logo
My Weather Logo
My Galaxy Logo
The Moon Logo
Periodic Table Logo
rStatistics Logo
Unit Convert Logo
Data Convert Logo
Coordinate Converter Logo
Temperature Convert Logo
2020 Election Logo
Sabali Finance Logo
Currency Convert Logo
Free Calculator Logo
Finance Calculator Logo
Loan Calculator Logo
Calculator Mortgage Logo
Stock Calculator Logo
Bond Calculator Logo
Tax Calculator Logo
Tip Calculator Logo
Gas Mileage Logo
History of Humanity - History Archive Logo
History of Humanity - History Mysteries Logo
History of Humanity - Ancient Mesopotamia Logo
History of Humanity - Egypt History Logo
History of Humanity - Persian Empire Logo
History of Humanity - Greek History Logo
History of Humanity - Alexander the Great Logo
History of Humanity - Roman History Logo
History of Humanity - Punic Wars Logo
History of Humanity - Golden Age of Piracy Logo
History of Humanity - Revolutionary War Logo
History of Humanity - Mafia History Logo