# Heights in the call above 5 feet. ---- men=c(10,12,13,12,9,8,16,12,22,13,8) women=c(6,7,6,4,5,0,11,5,9,5,5,3,5,5,3,3,7,8,4,7,3,3) men.mean = mean(men) men.var = var(men) men.n = length(men) women.mean = mean(women) women.var = var(women) women.n = length(women) # We compute the pooled variance using # intermediate values so it looks nicer a = (men.n-1)*men.var + (women.n-1)*women.var a = a/(men.n + women.n -2) b = 1/men.n + 1/women.n pooledVar = a*b tstatistic = (men.mean-women.mean)/pooledVar df = men.n + women.n - 2 p.value = 1-pt(tstatistic, df) #Display the relevant numbers men.mean men.n men.var women.mean women.n women.var tstatistic p.value # NHST with alpha = 0.05 alpha = 0.05 print(p.value) # p.value << .05 so we reject H_0 in favor of the # hypothesis that men are taller than woment if (p.value < alpha) print("Rejected the null hypothesis") if (p.value >= alpha) print("Failed to reject the null hypothesis")