以下のサンプルがあるとして、
100, 102, 93, 96, 94, 101, 90, 92, 96, 95
帰無仮説: μ=100
対立仮説: μ<= 100
という仮説があるときに、サンプルの平均値が100より小さいかどうかを調べるには、1標本の片側t検定を行えばよい。
> sample <- c(100, 102, 93, 96, 94, 101, 90, 92, 96, 95) > t.test(sample, mu=100, alternative="less") One Sample t-test data: sample t = -3.2538, df = 9, p-value = 0.004968 alternative hypothesis: true mean is less than 100 95 percent confidence interval: -Inf 98.20985 sample estimates: mean of x 95.9 >
この場合、p値が充分小さいので帰無仮説は棄却され、サンプルの平均値は有意に100よりも小さい。
対立仮説が μ >= 100の場合は、以下のようになるし、
> t.test(sample, mu=100, alternative="greater")
両側検定を行うときは、
> t.test(sample, mu=100, alternative="two.sided")
とするか、単に
> t.test(sample, mu=100)
とする。