Sei sulla pagina 1di 32

Statistics for Computing

(MA4413)
Lecture 12
Dr. Ali Sheikhi
(ali.sheikhi@ul.ie)

Department of Mathematics and Statistics


University of Limerick
Hypothesis Testing

A hypothesis is a theory or statement which has yet to be


proven or disproven.
Statistical methods will never prove or disprove a hypothesis
with certainty.
Examples of Hypotheses

1. Smoking causes lung cancer.


2. Sales in a shop are greater on a Friday than on
other weekdays.
3. 60% of the population are dissatisfied with the
government.
A hypothesis always relates to populations, but statistical
inference is based on results from a sample (or samples). For
example, two samples are used to test Hypothesis 1 (the
proportion of lung cancer in two samples, smokers and
non-smokers), but the conclusions of the test relate to the whole
population of interest (in this case, all the people in that
population).
Examples of Hypotheses

A hypothesis can very often be presented in terms of population


means or proportions.
1. The proportion of the population of smokers
affected by lung cancer differs from the proportion
in the population of non-smokers.
2. The mean value of sales on Fridays are greater
than the mean value of sales on other weekdays.
3. 60% of the population are dissatisfied with the
government.
Intuition Behind Hypothesis Testing

We always choose between one of two hypotheses:


1. The null hypothesis, denoted H0 , which always
includes some equality, i.e. 60% of the population
are dissatisfied with the government, i.e.
(H0 : p = 0.60).
2. The alterative hypothesis, denoted HA or H1 .
Possible Conclusions of a Test

Initially, we assume H0 is correct.


There are 2 possible conclusions of a test:
1. The evidence is not strong enough to reject H0 . In
this case the conclusion is we fail to reject H0 .
2. There is enough evidence to reject H0 . In this case
the conclusion is we reject H0 .
One and Two Tailed Hypotheses

If the alternative hypothesis is only one side of the sampling


distribution, then the hypothesis test is called one-tailed. For
example, HA : > 10 or HA : < 10.

If the alternative hypothesis is on two sides of the sampling


distribution, then the hypothesis test is called two-tailed. For
example, HA : 6= 10.
Errors in Statistical Inference

Since our conclusions are never 100% certain, we should


consider the possible errors.
A type I error is made when H0 is true, but we reject it. A type
II error is made when H0 is false, but we do not reject it.
(the probability of rejecting H0 when H0 is true) is called the
significance level of a test.
Errors in Statistical Inference

Conclusion: Do not reject H0 Conclusion: Reject H0


Reality: H0 is true OK Type I error
Reality: H0 is false Type II error OK
Relation Between the Probabilities of Type I and Type
II Errors

The significance level is chosen. Obviously, we wish to be


small.
However, decreasing makes it harder to reject the null
hypothesis even when the null hypothesis is false.
Hence, decreasing increases the probability of a Type II
error (not rejecting H0 when H0 is false).
In order for both and to be small, we must have a large
sample.
Commonly Used Significance Levels

The significance level is normally taken to be 0.05 (5%).


If for some reason we require strong evidence against H0 (e.g.
the costs associated with wrongly accepting HA may be very
high), we may test at a significance level of 0.01 or even 0.001
(1% or 0.1% respectively).
Example

Suppose we were given data on the salaries of males and females


in comparable positions (say secondary school teachers).
We may wish to test the hypothesis that the mean salary of all
male secondary school teachers is equal to the mean salary of
all female secondary school teachers.
Since this hypothesis contains an equality, it must be H0 .
Example
HA is the complement of H0 , i.e. the hypothesis that the mean
salaries of male and female secondary school teachers is not
equal.
Given our data we would reject H0 if the mean salary of
sampled males is significantly different from the mean salary
of sampled females (the concept of significantly different is
defined by the critical value for the significance level given - see
later).
Suppose H0 is true (i.e. salary levels do not depend on sex). If
we reject H0 in favour of HA (i.e. that salary levels depend on
sex), we commit a Type I error.
Suppose HA is true (i.e. salary levels do depend on sex). If we
do not reject H0 (that salaries do not depend on sex), then we
commit a Type II error.
The Procedure for Testing

Hypothesis testing is based on a sample (or samples) of data.


The standard procedure is as follows:
1. State H0 and HA .
2. Choice of test statistic (this is a random variable, a
measure of the distance between the data and H0 ).
Since the samples are random there will always be
some variation, but if H0 is true then realisations
of this distance will tend to be small.
3. Calculate the realisation of the test statistic (based
on the sample).
The Procedure for Testing

4. Either
a) Comparison of the realisation of the test
statistic with the appropriate critical value. If the
distance of the data from H0 is greater than the
distance given by this critical value, then we reject
H0 .
or
b) Calculation of the p-value of a test. This is a
measure of the credibility of H0 (it is not the
probability that H0 is true). If p < (the
significance level), then we reject H0 .
5. The conclusion should be clearly stated.
Interpretation of the p-value

SPSS gives the p-value for tests (in the SIG. column).
If p < , then we reject H0 . More precisely, if,
1. p < 0.05, there is evidence against H0 .
2. p < 0.01, there is strong evidence against H0 .
3. p < 0.001, there is very strong evidence against H0 .
Testing a Hypothesis About a Population Mean

The testing procedure depends on whether the sample is small


(n < 30) or large.
We wish to test between the two hypotheses,

H0 : = 0
HA : 6= 0 .
Procedure for Large Samples

This test is called the Z test.


The test statistic is,

n(X 0 ) X 0
Z= = .
s S.E(X)

Note that this is a measure of distance from the null hypothesis


= 0 . If the null hypothesis is correct, then realisations of this
test statistic should be close to 0.
The larger the sample size n, the more significant a given
difference X 0 .
The larger the dispersion of the data s (we expect that the
distribution of X is more dispersed), the less significant a given
difference X 0 .
Distribution of the Test Statistic

For large samples, the sample mean will be approximately


normally distributed. It follows that,


n(X 0 )
N (0, 1).

Since s will be a good approximation of , the test statistic,

n(X 0 ) X 0
Z= =
s S.E(X)

is approximately N (0, 1) [i.e. standard normal].


Calculation of the p-value

Denote the realisation of the test statistic by t (this is obtained


by substituting in the appropriate values for the sample mean
and standard deviation).
|t| is the absolute value of this realisation,

t, if t 0
|t| =
t, if t < 0.

The p-value of such a test is given by

2P (Z > |t|),

where Z N (0, 1).


Calculation of p-value
Critical values for t-test

Instead of using the p-value, we can use the critical value for a
given significance level.
We reject H0 when t deviates strongly from 0.
1. At a 100% significance level, we reject H0 iff
|t| > t, 2 , in particular
2. At a 5% significance level, we reject H0 iff
|t| > t,0.025 = 1.96.
3. At a 1% significance level, we reject H0 iff
|t| > t,0.005 = 2.576.
4. At a 0.1% significance level, we reject H0 iff
|t| > t,0.0005 = 3.291.
Critical Values and p-values

It should be noted that t, 2 satisfies,

2P (Z > t, 2 ) = .

e.g. 2P (Z > 1.96) = 2 0.025 = 0.05.


Hence, if t = t, 2 , then the p-value is .
Clearly, if t > t, 2 , then the p-value is less than .
Critical Values and p-values
Critical values and p-values

Hence, when the sample size is large


1. when |t| > 1.96, p < 0.05 i.e. we have evidence
against H0 .
2. when |t| > 2.576, p < 0.01 we have strong evidence
against H0 .
3. when |t| > 3.291, p < 0.001 we have very strong
evidence against H0 .
Example

A sample of 100 Irish people were measured. Their mean height


was 168cm and the sample standard deviation 12cm.
Test the hypothesis that the average height of Irish people is
170cm at a significance level of 5%.
Solution to Example

i) The hypotheses are,

H0 : = 170
HA : 6= 170.
Solution to Example - Test Statistic

ii) Since the sample size is large, we use the test statistic

n(X 0 )
Z= N (0, 1),
s
where 0 is the mean from the null hypothesis.
Solution to Example - Realisation of the Test Statistic

iii) Now we calculate the realisation of the test statistic


(distance from H0 ).

100(168 170)
t= = 1.667.
12
Solution to Example - Comparison with Critical Value

iv) Now we compare this realisation with the appropriate


critical value
|t| = 1.667 < t,0.025 = 1.96.
Solution to Example - Conclusion

v) Finally, we make our conclusion. Since |t| < t,0.025 = 1.96,


there is no evidence to reject H0 . In conclusion, we do not reject
the hypothesis that the mean height of Irish people is 170cm.
Solution to Example - Calculating the p-value

Note that at stage iv for large samples we can calculate the


p-value.

p = 2P (Z > |t|) 2P (Z > 1.67) = 20.0475 = 0.095 > = 0.05.

Since the p-value (measure of the credibility of H0 ) is greater


than the significance level, we do not reject H0 .

Potrebbero piacerti anche