1.t-test的功能:单因素二水平的假设检验。
H0:与我们想过要的结果相反的假设,比如我们想要的是两组数据的差异性,那么这个假设是:两组数据没有差异性。
H1或Ha:备择假设,与H0假设相反。
2.t-test的前提:正态性和方差齐性
3.R中的t-test的使用。
t.test(x, y = NULL,alternative = c("two.sided", "less", "greater"),mu = 0, paired = FALSE, var.equal = FALSE,conf.level = 0.95, ...)
或 t.test(formula, data, subset, na.action, ...)
> data druga drugb 1 10 20 2 11 21 3 13 19 4 9 18 > t.test(data$druga,data$drugb) Welch Two Sample t-test data: data$druga and data$drugb t = -8.1742, df = 5.5846, p-value = 0.0002598 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -11.417221 -6.082779 sample estimates: mean of x mean of y 10.75 19.50
> df drug effect 1 1 10 2 1 11 3 1 13 4 1 9 5 2 20 6 2 21 7 2 19 8 2 18 > t.test(effect~drug,data=df) Welch Two Sample t-test data: effect by drug t = -8.1742, df = 5.5846, p-value = 0.0002598 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -11.417221 -6.082779 sample estimates: mean in group 1 mean in group 2 10.75 19.50
结果解读:
t:t统计值。
df:自由度。
p:H0假设成立的概率。