# The following the example is the t-test for independent means, where we compared
# heights of female students who's mothers were taller or shorter than the median.
# Load in the survey data
survey <-read.csv("http://www.courses.washington.edu/psy315/datasets/Psych315W20survey.csv")
# First find the heights of the mothers of female students, removing NA's
mheight <- survey$mheight[!is.na(survey$mheight) & survey$gender=="Female" ]
# This is the median of the mother's heights:
median(mheight)
# Find the heights of the female students who's mother's aren't NA's:
height <- survey$height[!is.na(survey$mheight) & survey$gender=="Female"]
# Find the heights of female students who's mothers are taller than the median. Call them 'x'
x <- height[mheight>median(mheight)]
# Find the heights of female students who's mother's heights are lessthan or equal to the median. Call them 'x'
y <- height[mheight<=median(mheight)]
# Run the two-tailed t-test. If you send in both x and y, t.test
# assumes it's a two-sample independent measures t-test. The 'var.equal = TRUE'
# tells R to use the pooled standard deviation to combine the two measures
# of standard deviation.
out <- t.test(x,y,
alternative = "two.sided",
var.equal = TRUE)
# The p-pvalue is:
out$p.value
# Displaying the result in APA format:
sprintf('t(%g) = %4.2f, p = %5.1f',out$parameter,out$statistic,out$p.value)