Skip to content

Instantly share code, notes, and snippets.

@lundquist-ecology-lab
Last active April 10, 2023 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lundquist-ecology-lab/968bdc52a2630dfdd5320570a230fd4b to your computer and use it in GitHub Desktop.
Save lundquist-ecology-lab/968bdc52a2630dfdd5320570a230fd4b to your computer and use it in GitHub Desktop.
t test suite in R
# 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