# 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.

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)}})

data <- ToothGrowth

### 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") +

plot

### Both are numeric

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

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

plot

### 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.