Professional Documents
Culture Documents
Hypothesis T-Test
Hypothesis T-Test
Sample
Typical hypothesis in
Environmental Science
𝜇 < 𝜇0
X < Xstandard
Xstandard
Frequency
90% 10%
n = 10
x
Frequency
Sample
x
Mean
Variation
x
Mean Xstandard
1. Distribution?
Probability
Population 2. Probability?
x
When H is true When H is false
If H is rejected Type I error No error
false positive
If H is not rejected No error Type II error
false negative
* ** ***
H0: You are not pregnant.
Statistic
Appendix on OCWi
𝑋~ 𝑁 𝜇, 𝜎
𝜇 = mean
𝜎 = standard deviation
𝑋−𝜇
= Statistic
𝜎
𝑋−𝜇
For normal distribution, 𝑋~ 𝑁 𝜇, 𝜎 𝑍=
𝜎
Normal 𝑡𝛼,∞ = 𝑍𝛼
t, n=4
t, n=3
t, n=2
𝑥
Population Sample (n)
𝜇: Population mean 𝑋: Sample mean
𝜎: SD of population 𝑠𝑋 : SD of sample mean
𝛼 = 0.05
𝑡𝛼,𝑑𝑓
When H is true When H is false
If H is rejected Type I error No error
false positive
If H is not rejected No error Type II error
false negative
* ** ***
Example 5
Consider the test H0 : µ = 35 vs. Ha : µ > 35 for a
population that is normally distributed.
(a) A random sample of 18 observations taken
from this population produced a sample mean
of 40 and a sample standard deviation of 5.
Using α = 0.025, would you reject the null
hypothesis?
(b) Another random sample of 18 observations
produced a sample mean of 36.8 and a sample
standard deviation of 6.9. Using α = 0.025,
would you reject the null hypothesis?
(c) Compare and discuss the decisions of parts (a)
and (b).
(a)R code:
alpha = 0.025
mu_0 = 35
n = 18
x_bar = 40
s=5
t = (x_bar - mu_0 )/(s/sqrt(n))
p_value = pt(t, df = (n-1), lower.tail = FALSE)
if(p value < = alpha){ print("The null hypothesis
is rejected") } else{ print("There is not enough
evidence to reject the null hypothesis.") }
(b)R code:
alpha = 0.025
mu_0 = 35
n = 18
x_bar = 36.8
s = 6.9
t = (x_bar – mu_0 )/(s/sqrt(n))
p_value = pt(t, df = (n-1), lower.tail = FALSE)
if(p value < = alpha){
print("The null hypothesis is rejected") } else{ print("There is
not enough evidence to reject the null hypothesis.") }
(c) The sample in (a) produces larger t value than that of (b).
The larger t value is, the more frequent H0 is rejected.
Sample Codes for One-side Test for One Sample
x <- c(1,2,2,3)
x
t.test(x, mu=0, alternative="greater") # H0: 𝜇 ≤ 0
t.test(x, mu=2, alternative="greater") # H0: 𝜇 ≤ 2
data: x
t = 4.899, df = 3, p-value = 0.008138
alternative hypothesis: true mean is greater than 0
95 percent confidence interval:
1.039243 Inf
sample estimates:
mean of x
2
One-sample hypothesis:
𝜇0
𝑋
• 𝐻0 : 𝜇 < 𝜇0 --- Null
• 𝐻1 : 𝜇 ≥ 𝜇0 --- Alternative
Probability? • Probability of H1 (p).
Data
t distribution
Probability?
Statistic “t”
t 0
t test: test of mean
𝑋 𝜇0
One-sample hypothesis
(One set of samples)
𝑋1 𝑋2
Two-sample hypothesis
(Two sets of samples)
𝑋 𝜇0
One-sample hypothesis
𝑋 − 𝜇0 𝑠2
𝑡= , 𝑠𝑋 =
𝑠𝑋 𝑛
• One-side test
for H0: 𝜇 ≤ 𝜇0
If 𝑡 ≥ 𝑡𝛼 1 ,𝑑𝑓 , then reject H0
• Two-side test
for H0: 𝜇 ≠ 𝜇0
If 𝑡 ≥ 𝑡𝛼 2 ,𝑑𝑓 , then reject H0
Two-sample hypothesis 𝑋1 𝑋2
2 2
𝑋1 −𝑋2 𝑠𝑝 𝑠𝑝
𝑡= , 𝑠𝑋1 −𝑋2 = +
𝑠𝑋1 −𝑋2 𝑛1 𝑛2
• One-side test
for H0: 𝜇1 ≤ 𝜇2 𝑠𝑋1 −𝑋2
If 𝑡 ≥ 𝑡𝛼 1 ,𝑑𝑓 , then reject H0 Standard error of the
difference between
sample means
• Two-side test
for H0: 𝜇1 ≠ 𝜇2 𝑠𝑝2
If 𝑡 ≥ 𝑡𝛼 2 ,𝑑𝑓 , then reject H0 Pooled variance
Confidence interval of t-distribution
Confidence limit
𝑠2
𝑠𝑋 = 𝑠 2 : Sample variance
𝑛
1
Confidence interval ∝
𝑛
Exercise
Student’s t Test
1) Make a histogram of a set of your sample data. If necessary,
transform the data so that its symmetry and kurtosis become similar
to normal distribution. If you cannot find data showing normal
distribution, please send an email to Sokly to do this task.