How to do a two-sided hypothesis test for two sample means (in Julia)
Task
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 one-way analysis of variance (ANOVA)
- 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
If we call the mean of the first sample
1
2
3
4
5
6
7
8
9
10
11
# Replace these first three lines with the values from your situation.
alpha = 0.10
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.
using HypothesisTests
p_value = pvalue( UnequalVarianceTTest( sample1, sample2 ) )
reject_H0 = p_value < alpha
alpha, p_value, reject_H0
(0.1, 0.050972837418476996, true)
In this case, the
When you are using the most common value for
1
UnequalVarianceTTest( sample1, sample2 )
Two sample t-test (unequal variance)
------------------------------------
Population details:
parameter of interest: Mean difference
value under h_0: 0
point estimate: -3.9
95% confidence interval: (-7.823, 0.02309)
Test summary:
outcome with 95% confidence: fail to reject h_0
two-sided p-value: 0.0510
Details:
number of observations: [6,5]
t-statistic: -2.4616581720814326
degrees of freedom: 5.720083530052662
empirical standard error: 1.584297951775486
Here we did not assume that the two samples had equal variance.
If in your case they do, you can use EqualVarianceTTest()
instead of
UnequalVarianceTTest()
.
Content last modified on 24 July 2023.
See a problem? Tell us or edit the source.
Contributed by Nathan Carter (ncarter@bentley.edu)