Last active
April 10, 2023 15:16
-
-
Save lundquist-ecology-lab/968bdc52a2630dfdd5320570a230fd4b to your computer and use it in GitHub Desktop.
t test suite in R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# One sample t assuming a population mean of 15 | |
data <- c(13, 14, 13, 12, 14, 15, 16, 13, 14, 12) | |
t.test(data, mu = 15) | |
# Paired t test | |
group1 <- c(14, 12, 13, 12, 15, 12, 15, 15, 12, 13) | |
group2 <- c(12, 15, 14, 12, 13, 13, 14, 13, 12, 12) | |
t.test(group1, group2, paired = TRUE) | |
# Two sample t | |
group1 <- c(14, 12, 13, 12, 15, 12, 15, 15, 12, 13) | |
group2 <- c(12, 15, 14, 12, 13, 13, 14, 13, 12, 12) | |
# Test equal variances | |
var.test(group1, group2) | |
# If variances are equal (Student's t-test) | |
t.test(group1, group2, var.equal = TRUE) | |
# If variances are not equal (Welch's t-test) | |
t.test(group1, group2) # This is the default in R |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment