Skip to content

Instantly share code, notes, and snippets.

@geofferyzh
Created May 23, 2012 19:27
Show Gist options
  • Save geofferyzh/2777240 to your computer and use it in GitHub Desktop.
Save geofferyzh/2777240 to your computer and use it in GitHub Desktop.
RinAction - T-Tests
########################################################
########################################################
# -------------------- T-Test ----------------- #
########################################################
########################################################
# Group comparisons, assuming continuous outcome variable and normal distribution
#####################
## independent t-test
#####################
library(MASS)
t.test(Prob ~ So, data=UScrime) # by default assume unequal variance
t.test(Prob ~ So, data=UScrime, var.equal=TRUE)
t.test(Prob ~ So, data=UScrime, alternative="greater")
t.test(Prob ~ So, data=UScrime, alternative="two.sided")
t.test(Prob ~ So, data=UScrime, alternative="less")
#####################
## dependent t-test
#####################
library(MASS)
sapply(UScrime[c("U1", "U2")], function(x) (c(mean = mean(x),
sd = sd(x))))
with(UScrime, t.test(U1, U2, paired = TRUE))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment