How to do a one-sided hypothesis test for two sample means
Description
If we have two samples,
Related tasks:
- How to compute a confidence interval for a population mean
- How to do a two-sided hypothesis test for a sample mean
- How to do a two-sided hypothesis test for two sample means
- How to do a one-way analysis of variance (ANOVA)
- How to do a hypothesis test for a mean difference (matched pairs)
- How to do a hypothesis test for a population proportion
Using SciPy, in Python
If we call the mean of the first sample
1
2
3
4
5
6
7
8
9
from scipy import stats
# Replace these first three lines with the values from your situation.
sample1 = [ 6, 9, 7, 10, 10, 9 ]
sample2 = [ 12, 14, 10, 17, 9 ]
# Run a one-sample t-test and print out alpha, the p value,
# and whether the comparison says to reject the null hypothesis.
stats.ttest_ind( sample1, sample2, equal_var=False, alternative="less" )
Ttest_indResult(statistic=-2.4616581720814326, pvalue=0.02548641870923849)
The output says that the
The equal_var
parameter tells SciPy not to assume that the two samples
have equal variances. If in your case they do, you can omit that parameter,
and it will revert to its default value of True
.
Content last modified on 24 July 2023.
See a problem? Tell us or edit the source.
Solution, in R
If we call the mean of the first sample
1
2
3
4
5
6
7
8
# Replace these first three lines with the values from your situation.
alpha <- 0.10
sample1 <- c( 6, 9, 7, 10, 10, 9 )
sample2 <- c( 12, 14, 10, 17, 9 )
# 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( sample1, sample2, conf.level=1-alpha, alternative = "less" )
Welch Two Sample t-test
data: sample1 and sample2
t = -2.4617, df = 5.7201, p-value = 0.02549
alternative hypothesis: true difference in means is less than 0
90 percent confidence interval:
-Inf -1.605229
sample estimates:
mean of x mean of y
8.5 12.4
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( sample1, sample2, conf.level=1-alpha, alternative = "less" )
result$p.value < alpha
[1] TRUE
In this case, the samples give us enough evidence to reject the null hypothesis
at the
Here we did not assume that the two samples had equal variance.
If in your case they do, you can pass the parameter var.equal=TRUE
to t.test
.
Content last modified on 24 July 2023.
See a problem? Tell us or edit the source.
Topics that include this task
Opportunities
This website does not yet contain a solution for this task in any of the following software packages.
- Excel
- Julia
If you can contribute a solution using any of these pieces of software, see our Contributing page for how to help extend this website.