Created
May 23, 2012 19:27
-
-
Save geofferyzh/2777240 to your computer and use it in GitHub Desktop.
RinAction - T-Tests
This file contains hidden or 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
######################################################## | |
######################################################## | |
# -------------------- 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