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.

  1. Based on Confidence Interval

  2. Based on Critical Values (using t-table/z-table)

  3. Based on p-values (Reject H0 if \(p-value < \alpha\))

Finding the P-value

Example :

  1. The test statistic for a right-tailed test is z = 1.56. Find the P-value.
pvalue<-pnorm(1.56, lower.tail = FALSE)
pvalue
## [1] 0.05937994
  1. The test statistic for a left-tailed test is z = -2.33. Find the P-value.
pvalue<-pnorm(-2.33, lower.tail = TRUE)
pvalue
## [1] 0.009903076
  1. The test statistic for two-tailed test is z = -3.03. Find the P-value.
pvalue<-2*pnorm(-3.03, lower.tail = TRUE)
pvalue
## [1] 0.002445537

Types of Hypothesis test

  1. Test for a Population Mean

  2. Test for Difference between Two Population Means (Independent/Dependent Samples)

  3. Test for a Population Proportion

  4. 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\)

  1. Significance Level (\(\alpha=0.05\))

  2. Test Statistics:

mean0=22
xbar=23.3
s=3.3
n=121

z_value=(xbar-mean0)/(s/sqrt(n))
z_value
## [1] 4.333333
z_table=qnorm(0.05,lower.tail = FALSE)
z_table
## [1] 1.644854
  1. 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\)

  1. Significance Level (\(\alpha=0.10\))

  2. Test Statistics:

mean0=90
xbar=85
s=10
n=14

t_value=(xbar-mean0)/(s/sqrt(n))
t_value
## [1] -1.870829
t_table=qt(0.10,df=13,lower.tail = TRUE)
t_table
## [1] -1.350171
  1. 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)

  1. Significance Level (\(\alpha=0.05\))

  2. Test Statistics:

delta0<-0
mean1<-2.8
mean2<-1.6

n1<-150
n2<-182

sd1<-3.6
sd2<-2.9

z_value<-((mean1-mean2)-delta0)/sqrt((sd1^2/n1)+(sd2^2/n2))
z_value
## [1] 3.295301

IV.The rejection region

z_table<-qnorm(0.025,lower.tail = FALSE)
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)

  1. Significance Level (\(\alpha=0.05\))

  2. Test Statistics:

  • Equality of Variances Checking
sd1<-4.9
sd2<-4.5

larger_s2<-sd1^2
smaller_s2<-sd2^2

#divide larger and smaller

div_result<- larger_s2/smaller_s2
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:
n1<-10
n2<-12

mean1<-35
mean2<-31

sd1<-4.9
sd2<-4.5

delta0<-0

s2<-((n1-1)*sd1^2 + (n2-1)*sd2^2)/(n1+n2-2)
s2
## [1] 21.942
t_value<-((mean1-mean2)-delta0)/sqrt((s2)*(1/n1+1/n2))
t_value
## [1] 1.994349

IV.The rejection region

t_table<-qt(0.005,df=20,lower.tail = FALSE)
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)

  1. Significance Level (\(\alpha=0.05\))

  2. Test Statistics:

  • Equality of Variances Checking
sd1<-7.6
sd2<-4

larger_s2<-sd1^2
smaller_s2<-sd2^2

#divide larger and smaller

div_result<- larger_s2/smaller_s2
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:
n1<-10
n2<-12

mean1<-35
mean2<-31

sd1<-7.6
sd2<-4

delta0<-0

t_value<-((mean1-mean2)-delta0)/sqrt((sd1^2/n1)+(sd2^2/n2))
t_value
## [1] 1.500188

IV.The rejection region

formula1<-(((sd1^2/n1)+(sd2^2/n2))^2)
formula2<-((((sd1^2)/n1)^2)/(n1-1))+((((sd2^2)/n2)^2)/(n2-1))

df<-formula1/formula2
df
## [1] 13.06509
t_table<-qt(0.025,df=df,lower.tail = FALSE)
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.

  1. The samples must be randomly selected.

  2. The samples must be dependent (paired).

  3. 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)
before<-c(85,96,70,76,81,78)
after<-c(88,85,89,86,92,89)

# Create a data frame
my_data <- data.frame( 
                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)

  1. Significance Level (\(\alpha=0.05\))

  2. Test Statistics:

# compute the difference
d <- with(my_data, 
        score[group == "after"] - score[group == "before"])
d
## [1]   3 -11  19  10  11  11
# Compute t-test
t_value <- t.test(after,before, paired = TRUE)
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

t_table<-qt(0.05,df=5,lower.tail = FALSE)
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%)