t-test - Banks and Markets

Download Report

Transcript t-test - Banks and Markets

Day 3
Continued
Hypothesis Testing
1
Confidence Interval
• With a sample size n>30 we can estimate
the range within which the population mean
lies (the confidence interval for the mean)
by:
pop mean = x +/- 1.96 se (95% CI)
pop mean = x +/- 2.58 se (99% CI)
se = sd for sample/ /n
2
Testing a mean
What happens if we know the value of some
population mean and a sample taken from this
population doesn’t appear to agree with it?
Either
• the population parameter is not what we think, or
• the difference between the sample and population
is simply due to chance effects
3
The null hypothesis
• We make the hypothesis that any departure
from the supposed true population
parameter by the sample estimate is due to
chance effects
• We then see if we can disprove this
hypothesis at a particular significance level
• The null hypothesis is written as H0
4
The alternative hypothesis
• If we reject the null hypothesis we
automatically accept the alternative
hypothesis, H1
• This hypothesis can be two-tailed or onetailed
5
Types of tests
The form of the test depends on:
• the size of the sample
• the number of samples
• whether it is the mean or proportion that is of
interest
For tests on the mean we use the Z-statistic
for large samples and the t-statistic for small
samples
6
Large (single) sample test
for a mean
• When the sample size is large we use the
normal approximation
• The test can be one-sided or two-sided
7
A two-tailed test (not equal to)
using a 5% significance level
H
0
rejected
H
0
accepted
95%
2.5%
0
rejected
2.5%
1.96
-1.96
Lower critical
region
H
Upper critical
Critical values
region
8
One-tailed test (less than) using
a 5% significance level
H0 rejected
H0 accepted
95%
Lower critical
region
Z
-1.645
9
One-tailed test (greater than)
using a 5% significance level
H0 rejected
H0 accepted
95%
Upper critical
region
Z
1.645
10
Steps for carrying out a
hypothesis test
• Set up the null and alternative hypotheses
• Decide on the significance level (normally 5%)
and determine the critical values
• Calculate the test statistic (this is the number of
standard deviations that the sample estimate is
away from the population parameter)
• Decide whether to accept or reject the null
hypothesis
11
Example 1
A food manufacturer processes and cans
baked beans. The net weight of a standard
can of beans is supposed to be 420g but a
random sample of 50 cans gave an average
weight of 415g with a standard deviation of
30g. Is there any evidence that the true
mean weight is not 420g?
(Use a 5% significance level)
12
Solution to Example 1
H 0 :   420g
SE 
Z 
H1 :   420g
30
50
 4.243
x 
SE
415  420
4.243
 1.178
Z
13
Conclusion of the test result
As the test statistic is between –1.96 and 1.96
we cannot reject H0. That is, there is no
evidence at the 5% level of significance that
the mean is not 420g.
14
Example 2 (1 of 3)
• Bags of sugar weighing 1000g
• Weight packed by machine drifts
• Need to detect drift and reset machine but
not stop process unnecessarily
• Null hypothesis
u = 1000
ie:
H0 :
u = 1000
15
Example 2 (2 of 3)
• Standard deviation = 50g
• For 100 bags in a sample:
• s.e. =
s.d.
=
50
=
5g
n
10
• Sample mean x to test H0
• Z =
x - u = x - 1000
s.e.
5
• Test is two-sided so compare value of Z with 1.96
and 2.576
16
Example 2 (3 of 3)
• e.g. if sample mean 1015g
•
Z
=
1015-1000 =
3
5
• This is > 2.576 (1% level of significance)
• H0 rejected, H1 : u = 1000 accepted
• Mean weight now over 1kg with < 1%
chance of being wrong to conclude this
17
Example 3 (1 of 3)
• Noise in street
• Measured over long time between 4:30pm and
5:30pm
• Average noise 130 decibels
• s.d.
20 decibels
• Residents take 50 readings
• Mean 134 decibels
• Is noise increasing?
18
Example 3 (2 of 3)
•
•
•
•
H0 :
u = 130
H1 :
u > 130
(Is test one or two-sided?)
Z =
|x-u|
=
134 - 130
s.e.
20/ 50
=
1.41
19
Example 3 (3 of 3)
• Critical values of Z 1.645 (5%) and 2.326
(1%)
• Difference between population mean and
sample mean not significant as
• Z =
1.41 < 1.645
20
t-test for a sample mean
• When the sample size is small we can use
the t-test.
• The procedure is the same except that the
critical value is found from t-tables using
n–1 degrees of freedom.
21
Example 4 (1 of 3)
The average height for women between the ages of 20 – 24 in
university math class last year was determined to be 165cm. The
heights for the same age group was measured this year and the
following values were obtained:
175cm; 172.5cm; 159cm; 167cm; 170cm; 165cm; 160cm; 162.5cm;
171cm and 167cm.
Determine if there is evidence of systematic error?
α = 0.05
Solution:
H0 = µ
Example 4 (2 of 3)
H1 ≠ µ
Mean height =(175+172.5+159+167+170+
165+160+162.5+171+167) ÷10
= 166.9 cm
Standard deviation = 5.337
n = 10
µ = 165cm
df = 10 – 1 = 9
Example 4 (3 of 3)
t=
(166.9  165)  10
5.337
= 1.126
tcrit = tα/2, df = 2.262
Reject H0 if ItI > tcrit
Since ItI = 1.126 < tcrit = 2.262, H0 is retained.
Therefore there is no evidence of systematic error.
Hypothesis tests involving two
means
We can have:
• two large independent samples
• two small independent samples
• paired samples
25
Two large independent samples
The standard error of the difference between
the means is:
2
1  2 
 ( x1 x2 )    
 n1 n2 
2
The test statistic is:
x1  x2   1   2 
Z=
 (x x
1
2)
26
Two large independent samples
continued
The null and alternative hypotheses are:
H1: 1 - 2  0 for a two sided test and
H1: 1 > 2 or 1 < 2 for a one sided test
27
Two small independent samples:
t-test
The standard error for two small samples is:
= ˆ  1  1 
 
x1  x2
 n1
n2 
where ̂ (AKA S2p) is the estimate of the
pooled standard deviation of the populations
and is given by:
n  1s  n  1s
2
ˆ 
1
1
2
2
2
n1  n2  2
28
t-test for two independent
small samples continued
The test statistic is given by:
t
 x  x      
1
2
 ( x1 x2 )
1
2
29
Example 5 (1 of 4)
You’re a financial analyst for Charles Schwab. You collect
the following data:
Sample Size
Mean
Standard
Deviation
NYSE
21
3.27
1.30
NASDAQ
25
2.53
1.16
Is there a difference in average yield at the 95 % confidence
level between the stocks listed on the NYSE & NASDAQ?
Solution:
H0: µ1= µ2
Example 5 (2 of 4)
H1: µ1 ≠ µ2
(n1  1) s1  (n2  1) s2

n1  n2  2
2
sp
2
2
(21  1)1.302  (25  1)1.162
sp2=
(21  25  2)
sp2=
66.0944
44
Therefore sp2 = 1. 502
Example 5 (3 of 4)
t
t=
 x  x      
1
2
 ( x1 x2 )
1
2
(3.27  2.53)
1 1 
1.502   
 21 25 
Therefore t = 0.74/0.363
= 2.04
Degrees of freedom = 21+25-2 = 44
Example 5 (4 of 4)
tcrit = tα/2,df = 2.015
We reject H0 if t calculated > tα/2,df
Since t calculated = 2.04 > tα/2,df= 2.015, H0 is rejected and
H1 is accepted.
Therefore there is significant difference between the means
at the 95% confidence level.
Paired samples
The null hypothesis is that the difference of the
population means is zero and the alternative
hypothesis can be either one-tailed or two-tailed.
The test statistic for this test is:
xd   d
t

d
Where

d
sd

n
34
Example 6 (1 of 5)
Your school is thinking about purchasing new
finance software. The table below give the results
for trial runs to compare the processing times for
new system with the existing one. Is the new
financial software faster? α = 0.05.
Example 6 (2 of 5)
Trial Run
Old Software (s)
New Software (s)
Difference (d)
1
9.98
9.88
+0.10
2
9.76
9.86
-0.10
3
9.84
9.75
+0.09
4
9.99
9.80
+0.19
5
9.85
9.81
+0.04
6
9.90
9.95
-0.05
7
10.12
9.98
+0.14
8
9.91
9.86
+0.05
9
9.88
9.89
-0.01
10
9.86
9.80
+0.06
Example 6 (3 of 5)
Solution:
H0: µd = 0
H1: µd > 0
Mean of the difference ( x d ) is :
=( 0.10 + -0.10 + 0.09 + 0.19 + 0.04 + -0.05 +
0.14 + 0.05+ -0.01 + 0.06)/ 10
= 0.51/10
sd



= 0.051
d
n
sd = 0.08698, n = 10


d

0.08698
 0.02751
10
Example 6 (4 of 5)
t
xd   d


d
0.051  0
t
 1.854
0.02751
Example 6 (5 of 5)
df = n – 1 = 10 – 1 = 9
tcrit = tα,df = t0.05,9 = 1.833
We reject H0 if t > tcrit
Since t = 1.854 > tcrit = 1.833, H0 is rejected and H1 is
accepted.
Therefore it can be concluded that the new financial software
is faster.
F test
F test is a test to find if the variances of the two
normal populations are equal (that is whether
21 = 22 ). Since we can not observe the two
population variances, we obtain the sample
variances i.e. test if s21 = s22
If the two population variances are in fact equal,
the F ratio should be about 1, greater the
difference between the two variances the
greater the F value will be
40
F Test
2
1
2
2
s
Test Statistic: F =
s
Where:
2
s1 = Variance of Sample 1; with n1 - 1 degrees of
freedom
s22 = Variance of Sample 2; with n2 – 1 degrees of
freedom
Note: By convention in computing the F value the
variance with the larger numerical value is put in the
numerator. If 2 tailed test, divide alpha by 2 and then
find the right critical value
Example 7
Same question was given to Birmingham and Manchester students. Bgham
had 100 students and Man 150. Random samples of 25 from Bgham and 31
from Man gave sample mark variances of 100 and 132 respectively. Can we
assume that the variances of marks in Bgham is greater than in Man? Test at
5% level of significance.
H0: σ12 = σ22
F=
2
1
2
2
s
s
H1: σ22 < σ12
= 132/ 100 = 1.32,
DF1 (numerator) 25-1=24 and DF2 (denominator) = 31-1 = 30
From F distribution Fcrit = F30,24 (p= 0.05) = 1.98, Since Fcalc < Fcrit, H0 is
accepted at the 95% confidence level ( α = 0.05), i.e. the variances are
same.
Example 8 (Question)
A proposed method for the determination of the chemical oxygen demand of waste
water was compared with the standard (mercury salt) method. The following results
were obtained for a sewage effluent sample:
Mean (mg l-1)
Standard Deviation (mg
l-1)
Standard Method
72
3.31
Proposed method
72
1.51
For each method 8 determinations were made.
Is the precision of the proposed method significantly greater than that of the
standard method?
Type I and Type II Errors
Rejecting a null-hypothesis when it should not
have been rejected creates a type I error
Failing to reject a null-hypothesis when it should
have been rejected creates a type II error
Hypothesis\Decision
Accept
Reject
True
Correct Decision.
Type II error.
P(Type II)=
False
Type I error.
p(Type I)= 
Correct Decision
44
Type I and Type II Errors
Example: Testing for pregnancy. Differential
between type I and type II errors
a) Not pregnant but test found +ve
b) Pregnant but test found -ve
45