How to do a two-sided hypothesis test for a sample mean (in R)
Task
Say we have a population whose mean
Related tasks:
- How to compute a confidence interval for a population mean
- How to do a two-sided hypothesis test for two sample means
- How to do a one-sided hypothesis test for two sample means
- How to do a hypothesis test for a mean difference (matched pairs)
- How to do a hypothesis test for a population proportion
Solution
This is a two-sided test with the null hypothesis
1
2
3
4
5
6
7
8
# Replace these first three lines with the values from your situation.
alpha <- 0.05
pop.mean <- 10
sample <- c( 9, 12, 14, 8, 13 )
# Run a one-sample t-test and print out alpha, the p value,
# and whether the comparison says to reject the null hypothesis.
t.test( sample, mu=pop.mean, conf.level=1-alpha )
One Sample t-test
data: sample
t = 1.0366, df = 4, p-value = 0.3585
alternative hypothesis: true mean is not equal to 10
95 percent confidence interval:
7.986032 14.413968
sample estimates:
mean of x
11.2
Although we can deduce the answer to our question from the above output,
by comparing the
1
2
3
# Is there enough evidence to reject the null hypothesis?
result <- t.test( sample, mu=pop.mean, conf.level=1-alpha )
result$p.value < alpha
[1] FALSE
In this case, the sample does not give us enough information to reject
the null hypothesis. We would continue to assume that the sample is like
the population,
Content last modified on 24 July 2023.
See a problem? Tell us or edit the source.
Contributed by Nathan Carter (ncarter@bentley.edu)