R05 STA1511
Hypothesis Testing
Introduction
A statistical hypothesis is a statement about the numerical value of population parameter.
Example problem: The mayor of a small city claims that the average income in his city is $35,000. State the hypothesis.
H0: \(\mu=35000\)
H1: \(\mu\neq 35000\)
Component of Hypothesis Testing
Decision/Conclusion Rule
Depends on the significance level, α, the maximum tolerable risk you want to have of making a mistake, if you decide to reject H0. Usually, the significance level is α = 0.01, α = 0.05, α = 0.10.
Based on Confidence Interval
Based on Critical Values (using t-table/z-table)
Based on p-values (Reject H0 if \(p-value < \alpha\))
Finding the P-value
Example :
- The test statistic for a right-tailed test is z = 1.56. Find the P-value.
<-pnorm(1.56, lower.tail = FALSE)
pvalue pvalue
## [1] 0.05937994
- The test statistic for a left-tailed test is z = -2.33. Find the P-value.
<-pnorm(-2.33, lower.tail = TRUE)
pvalue pvalue
## [1] 0.009903076
- The test statistic for two-tailed test is z = -3.03. Find the P-value.
<-2*pnorm(-3.03, lower.tail = TRUE)
pvalue pvalue
## [1] 0.002445537
Types of Hypothesis test
Test for a Population Mean
Test for Difference between Two Population Means (Independent/Dependent Samples)
Test for a Population Proportion
Test for Difference between Two Population Proportions
1. Test for a Population Mean
Test Statistics
For large sample:
For small sample:
has a t distribution with n-1
degrees of freedom.
Example
Example 1: (Large Sample)
Jim Nasium claims that the mean
A.C.T. score attained by
two year college students is 22
. Al Dente suspects this
claim is too low and selects a random sample of 121
two
year college students. The mean of the sample is 23.3 and the population
standard deviation is assumed to be 3.3. Test at the 5% significance
level (alpha).
Answer:
I. Hypothesis
H0: \(\mu\leq22\)
H1: \(\mu>22\)
Significance Level (\(\alpha=0.05\))
Test Statistics:
=22
mean0=23.3
xbar=3.3
s=121
n
=(xbar-mean0)/(s/sqrt(n))
z_value z_value
## [1] 4.333333
=qnorm(0.05,lower.tail = FALSE)
z_table z_table
## [1] 1.644854
- The rejection region
Reject H0 if z_value>z_table. (Because this is a right tailed test)
V. Conclusion
Because z_value=4.333333 is greater than z_table=1.645, so we can conclude that H0 is rejected at the 5% level of significance.
Example 2:(Small sample)
The secretary of an association of professional landscape gardeners
claims that the average cost of services to customers is 90 USD per
month. Feeling that this figure is too high
, we question a
random sample of 14 customers. Our sample yields a mean cost of 85 USD
and a standard deviation of 10 USD. Test at the 0.10 significance level.
Assume that such costs are normally distributed.
Answer:
I. Hypothesis
H0: \(\mu\geq 90\)
H1: \(\mu<90\)
Significance Level (\(\alpha=0.10\))
Test Statistics:
=90
mean0=85
xbar=10
s=14
n
=(xbar-mean0)/(s/sqrt(n))
t_value t_value
## [1] -1.870829
=qt(0.10,df=13,lower.tail = TRUE)
t_table t_table
## [1] -1.350171
- The rejection region
Reject H0 if t_value<t_table(0,10;df=13). (Because this is a left tailed test)
V. Conclusion
Because t_value=-1.870829 is lower than t_table=-1.350171, so we can conclude that H0 is rejected at the 10% level of significance.
Excercise
A forester studying diameter growth of red pine believes that the mean diameter growth will be different from the known mean growth of 1.35 inches/year if a fertilization treatment is applied to the stand. He conducts his experiment, collects data from a sample of 32 plots, and gets a sample mean diameter growth of 1.6 in./year. The population standard deviation for this stand is known to be 0.46 in./year. Does he have enough evidence to support his claim? Test at the 5% significance level (alpha).
2. Difference Between Two Population Means (Case of Two Independent Samples)
Independent random samples of size n1 and n2 are drawn from population 1 and population 2 with means μ1 and μ2,and variances \(\sigma_{1}^{2}\) and \(\sigma_{2}^{2}\).
Assumptions :
The samples are random & independent of each other
The data must be continuous
The distribution is normal.
Test Statistics
For Large Sample
For Small Sample
Example
Example 1: (Large Sample)
Is there a difference in the average Scores of Hooked on Nicotine Checklist (HONC) for men versus women? (use \(\alpha=0.05\))
Answer:
I. Hypothesis
H0: \(\mu_{1}-\mu_{2}=0\) (same)
H1: \(\mu_{1}-\mu_{2}\neq0\) (different)
Significance Level (\(\alpha=0.05\))
Test Statistics:
<-0
delta0<-2.8
mean1<-1.6
mean2
<-150
n1<-182
n2
<-3.6
sd1<-2.9
sd2
<-((mean1-mean2)-delta0)/sqrt((sd1^2/n1)+(sd2^2/n2))
z_value z_value
## [1] 3.295301
IV.The rejection region
<-qnorm(0.025,lower.tail = FALSE)
z_table z_table
## [1] 1.959964
Reject H0 if \(|z_{value}|>z_{table}\) . (Because this is two-tailed test)
V. Conclusion
Because |z_value|= 3.29 is greater than z_table= 1.96 , so we can conclude that H0 is rejected at the 5% level of significance.
Example 2 : (Small sample)
Two training procedures are compared by measuring the time that it takes trainees to assemble a device. A different group of trainees are taught using each method. Is there a difference in the two methods? Use α = 0.01.
Answer:
I. Hypothesis
H0: \(\mu_{1}-\mu_{2}=0\) (same)
H1: \(\mu_{1}-\mu_{2}\neq0\) (different)
Significance Level (\(\alpha=0.05\))
Test Statistics:
- Equality of Variances Checking
<-4.9
sd1<-4.5
sd2
<-sd1^2
larger_s2<-sd2^2
smaller_s2
#divide larger and smaller
<- larger_s2/smaller_s2
div_result div_result
## [1] 1.185679
Because the result is smaller than 3, so we can use test statistics with equal variances assumption.
- Test Statistics using Equal Variances Assumption:
<-10
n1<-12
n2
<-35
mean1<-31
mean2
<-4.9
sd1<-4.5
sd2
<-0
delta0
<-((n1-1)*sd1^2 + (n2-1)*sd2^2)/(n1+n2-2)
s2 s2
## [1] 21.942
<-((mean1-mean2)-delta0)/sqrt((s2)*(1/n1+1/n2))
t_value t_value
## [1] 1.994349
IV.The rejection region
<-qt(0.005,df=20,lower.tail = FALSE)
t_table t_table
## [1] 2.84534
Reject H0 if \(|t_{value}|>t_{0.005;20}\) . (Because this is two-tailed test)
V. Conclusion
Because |t_value|= 1.99 is lower than \(t_{0.005;20}\)= 2.845 , so we can conclude that H0 is not rejected at the 1% level of significance and there is no difference in two methods.
Example 3 : (Small sample-Unequal Variances)
Two training procedures are compared by measuring the time that it takes trainees to assemble a device. A different group of trainees are taught using each method. Is there a difference in the two methods? Use α = 0.01.
Answer:
I. Hypothesis
H0: \(\mu_{1}-\mu_{2}=0\) (same)
H1: \(\mu_{1}-\mu_{2}\neq0\) (different)
Significance Level (\(\alpha=0.05\))
Test Statistics:
- Equality of Variances Checking
<-7.6
sd1<-4
sd2
<-sd1^2
larger_s2<-sd2^2
smaller_s2
#divide larger and smaller
<- larger_s2/smaller_s2
div_result div_result
## [1] 3.61
Because the result is greater than 3, so we can use test statistics with unequal variances assumption.
- Test Statistics using Equal Variances Assumption:
<-10
n1<-12
n2
<-35
mean1<-31
mean2
<-7.6
sd1<-4
sd2
<-0
delta0
<-((mean1-mean2)-delta0)/sqrt((sd1^2/n1)+(sd2^2/n2))
t_value t_value
## [1] 1.500188
IV.The rejection region
<-(((sd1^2/n1)+(sd2^2/n2))^2)
formula1<-((((sd1^2)/n1)^2)/(n1-1))+((((sd2^2)/n2)^2)/(n2-1))
formula2
<-formula1/formula2
df df
## [1] 13.06509
<-qt(0.025,df=df,lower.tail = FALSE)
t_table t_table
## [1] 2.159275
Reject H0 if \(|t_{value}|>t_{0.005;13.06}\) . (Because this is two-tailed test)
V. Conclusion
Because |t_value|= 1.500188 is lower than \(t_{0.005;13.06}\)= 3.009781 , so we can conclude that H0 is not rejected at the 1% level of significance and there is no difference in two methods.
Excercise
For the 2008 General Social Survey, a comparison of females and males on the number of hours a day that the subject watched TV gave:
Set up the hypotheses of a significance test to analyze whether the population means differ for females and males. (use \(\alpha=0.05\)).
3. Paired-t (Case of Two Dependent Samples)
Two samples are independent if the sample selected from one
population is not related
to the sample selected from the
second population. Two samples are dependent
if each member
of one sample corresponds
to a member of the other sample.
Dependent samples
are also called
paired samples
or matched samples
.
t test for Difference between Means
To perform a two-sample hypothesis test with dependent samples.Three conditions are required to conduct the test.
The samples must be randomly selected.
The samples must be dependent (paired).
Both populations must be normally distributed.
Test Statistics
Example
A reading center claims that students will perform better on a standardized reading test after going through the reading course offered by their center. The table shows the reading scores of 6 students before and after the course. At α = 0.05, is there enough evidence to conclude that the students’ scores after the course are better than the scores before the course?
Answer:
-> Make Data frame in R
library(dplyr)
<-c(85,96,70,76,81,78)
before<-c(88,85,89,86,92,89)
after
# Create a data frame
<- data.frame(
my_data group = rep(c("before", "after"), each = 6),
score = c(before, after)
)
print(my_data)
## group score
## 1 before 85
## 2 before 96
## 3 before 70
## 4 before 76
## 5 before 81
## 6 before 78
## 7 after 88
## 8 after 85
## 9 after 89
## 10 after 86
## 11 after 92
## 12 after 89
group_by(my_data, group) %>%
summarise(
count = n(),
mean = mean(score, na.rm = TRUE),
sd = sd(score, na.rm = TRUE)
)
## # A tibble: 2 x 4
## group count mean sd
## <chr> <int> <dbl> <dbl>
## 1 after 6 88.2 2.48
## 2 before 6 81 8.90
I. Hypothesis
H0: \(\mu_{d}\leq0\)
H1: \(\mu_{d}>0\) (Claim)
Significance Level (\(\alpha=0.05\))
Test Statistics:
# compute the difference
<- with(my_data,
d == "after"] - score[group == "before"])
score[group d
## [1] 3 -11 19 10 11 11
# Compute t-test
<- t.test(after,before, paired = TRUE)
t_value t_value
##
## Paired t-test
##
## data: after and before
## t = 1.7134, df = 5, p-value = 0.1473
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -3.585142 17.918475
## sample estimates:
## mean of the differences
## 7.166667
IV.The rejection region
<-qt(0.05,df=5,lower.tail = FALSE)
t_table t_table
## [1] 2.015048
Reject H0 if \(t_{value}>t_{table}\) . (Because this is two-tailed test)
V. Conclusion
Because t_value=1.7134 is smaller than t_table= 2.015048 , so we can conclude that H0 is not rejected at the 5% level of significance.
Excercise
10 mice received a treatment X during 3 months. We want to know whether the treatment X has an impact on the weight of the mice. The weight of the 20 mice has been measured before and after the treatment. This gives us 20 sets of values before treatment and 20 sets of values after treatment from measuring twice the weight of the same mice. there is any significant difference in the mean weights after treatment?(use alpha = 5%)