Download Comparison of

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Degrees of freedom (statistics) wikipedia , lookup

Psychometrics wikipedia , lookup

Foundations of statistics wikipedia , lookup

Bootstrapping (statistics) wikipedia , lookup

Taylor's law wikipedia , lookup

Omnibus test wikipedia , lookup

Resampling (statistics) wikipedia , lookup

Misuse of statistics wikipedia , lookup

Student's t-test wikipedia , lookup

Transcript
Lesson 1:
Comparison of Population Means
Part c: Comparison of TwoMeans
Welcome to lesson 1c. This third lesson of lesson 1 will discuss hypothesis testing
for two independent means.
1
Steps in Hypothesis
Testing
1.
2.
3.
4.
State the null hypothesis H0 and
the alternative hypothesis Ha.
Calculate the value of the test
statistic on which the test will be
based.
Find the p-value for the observed
data.
State a conclusion.
2
Recall the steps in hypothesis testing. First, we state the null and alternative
hypothesis to address our research question.
Next, calculate the test statistic. We then compare the test statistic to a density
curve to find the p-value.
Finally, we compare this p-value to the type I error probability to determine our
conclusion.
2
Hypothesis Testing:
Comparing Two Means
„
Identify two independent populations.
„
Draw a simple random sample of size n1
from population 1 and a simple random
sample of size n2 from population 2.
„
Compute the mean for each sample.
„
Formulate hypothesis test based on the
difference of the means
3
Let’s discuss the setting for hypothesis testing of two means. First, we take random
samples from two independent populations. We wish to compare the average value
mu from these two independent populations to see if they are similar or different.
From each sample we compute an average value, xbar. We will then use these
sample means to determine if the populations are centered in the same location or
different locations.
We look at a linear combination (xbar1-xbar2) to help us make this decision.
If xbar1-xbar2 is close to zero, the populations probably have the same center. If
xbar1-xbar2 is not close to zero the populations may have different centers.
3
Hypothesis Testing:
Comparing Two Means
„
Step 1: State your hypotheses
H0: μ1- μ2= 0
„ Ha: μ1 - μ2 ≠ 0 (two-sided)
Or
„ Ha: μ1 - μ2 < 0 (one-sided)
Or
„ Ha: μ1 - μ2 > 0 (one-sided)
„
4
First step is to represent our scientific question is the null and alternative
hypothesis.
The null: Ho: m1-m2 = 0 represents the condition that the populations are centered
in the same spot.
As with one-sample and matched pairs hypothesis testing we can have a one-sided
or two-sided alternative.
The two sided alternative is that the means differ. That is m1-m2 does not equal
zero.
We could also look at the alternative that m2 is greater than m1. This would be if
we subtract m2 from m1 we would obtain a negative number.
Or
We could look at the alternative that m1 is greater than m2. This would be if we
subtract m2 from m1 we would obtain a positive number.
4
Two sample Problem
with σ1 and σ2 known.
z=
( x1 − x2 )
σ 12
n1
+
σ 22
n2
5
If the population standard deviation for both populations is known then the statistic
we use is the z statistic. You can see the standard error of the difference of xbar1
and xbar2 is in the denominator.
You will recall that when we make a linear combination of two means that the
variances are additive. This is why the standard error in the denominator has a plus
sign instead of a minus sign.
As before, knowing the variance of the population is not typical. So we usually
substitute the value of the sample variance in where the population variance is in
this equation.
5
Two sample Problem
with σ1 and σ2 unknown
(do not assume σ1=σ2) .
Use this t when
slarger/ssmaller > 2
t=
df= smaller of
n1-1 or n2-1
( x1 − x2 )
s12 s22
+
n1 n2
6
When we do this substitution we switch to using the student’s t statistic. Notice in
the title it also says “do not assume s1=s2.”
There are two ways to calculate the standard error of the difference of samples
means. The first is what you see in the denominator here. This is when we cannot
assume that the population standard deviations are the same from the two
independent populations. We do not know the populations standard deviations so
we look at our sample standard deviations.
If the larger sample standard deviation divided by the smaller sample standard
deviation is greater than two, we do not assume sigma1=sigma2. This is a rule of
thumb. It says our sample standard deviations are different enough we cannot
assume sigma1=sigma2.
Our degrees of freedom for this t-test are the smaller of n1-1 or n2-1.
6
Two sample Problem
with σ1 and σ2 unknown and
assumption σ1= σ2.
Use this t when
slarger/ssmaller < 2
t=
(x1 − x2 ) − μo
⎛1 1⎞
s2p ⎜⎜ + ⎟⎟
⎝ n1 n2 ⎠
withs2p =
with n1 + n2 − 2
degreesof freedom
(n1 −1)s12 + (n2 −1)s22
n1 + n2 − 2
7
So what happens when s larger over s smaller is less than two? Well, we can
assume sigma1=sigma2.
If we make this assumption we use the t test given in this slide. Notice we pool the
variances to create a common variance. This is called sp. We then use sp in the
denominator to calculate the standard error of the difference of sample means.
So why worry about whether or not to assume sigma1=sigma2? Notice the degrees
of freedom when we make the assumption are n1+n2-2. This is more degrees of
freedom than in the previous t test.
When we have more degrees of freedom in the t-test we have more power to detect
a difference should there be one. We want to make the assumption that the
population variances are equal when we can.
7
SAS Example
„
„
„
„
„
We have 10 students, 5 are randomly assigned to
control and 5 are randomly assigned to treatment.
Response times to a stimulus is measured for all 10
participants.
Research question: Do the treatment scores come
from a population whose mean is different from which
the control scores were drawn?
Control mean = 88.6 millisec
Treatment mean = 101.6 millisec
8
Let’s try an example. We will also introduce a bit of SAS to understand our
example.
Recall: SAS is a computer language that helps us analyze data. At this point you
may have tried the SAS tutorial for the first assignment. If not, you may want to do
this before moving on.
Consider the example above. You have 10 students, 5 are randomly assigned to
control and 5 are randomly assigned to treatment. The outcome of interest is
response times to a stimulus.
We are wondering of the treatment group and the control group come from
populations whose mean values are different.
The control sample mean was 88.6 milliseconds.
The treatment sample mean was 101.6 milliseconds.
8
Data Response;
SAS: Proc ttest
Input Group $ Time;
Datalines;
C 80
C 93
C 83
C 89
C 98
T 100
T 103
T 104
T 99
T 102
;
Proc ttest data = response;
Title "T-test example";
class group;
var time;
run;
This is a SAS program that reads in data and performs a two sample t-test.
The first line “Data response;” tells SAS that we want to create a temporary data set
called response.
The next line “Input Group $ Time;” tells SAS that we have two variables. One is
called Group and it is categorical. This is indicated by the dollar sign following the
word Group. The second variable is called time. There is no designation of type of
variable after time. SAS will assume it is quantitative if there is not a designation.
Next we have “Datalines;” this tells SAS: Here comes the actual data. Following
datalines is the data C and T are control and treatment. The data is separated by a
single space with a new line for each person’s data. Notice the semicolon is a line
below the final piece of data.
The data step is now complete. We can then do a procedure on this data.
9
Data Response;
SAS: Proc ttest
Input Group $ Time;
Datalines;
C 80
C 93
C 83
C 89
C 98
T 100
T 103
T 104
T 99
T 102
;
Proc ttest data = response;
Title "T-test example";
class group;
var time;
run;
The procedure is “Proc ttest” SAS will analyze the data using a ttest.
We tell SAS which data set by “data=response;”
We can insert a title with the title command followed by the title in quotes.
Next “class group;” tells SAS between which two groups we would like to perform
the t-test. In our case it is the variable called Groups with control or treatment as
group.
“var time;” tells SAS that we want to analyze the outcome time;
Finally, “run;” tells SAS go ahead and analyze using the procedure.
Again, for more on SAS programming see the class SAS tutorials.
10
The TTEST Procedure
Statistics
Variable
Time
Time
Time
Group
N
C
5
T
5
Diff (1-2)
Lower CL
Mean
79.535
99.025
-20.83
Mean
88.6
101.6
-13
Upper CL Lower CL
Mean
Std Dev Std Dev
97.665
104.17
-5.173
4.3741
1.2424
3.6249
7.3007
2.0736
5.3666
Upper
Std Dev
Std Err
20.979
5.9587
10.281
3.265
0.9274
3.3941
Note: SAS Tests ->Ho: μ1=μ2 vs. Ha: μ1 not
equal μ2
11
If everything ran without error you will see output. This is the first piece of output
you see.
We have variable time divided by our two groups, Control and treatment. We also
have a row indicating the difference of control – treatment outcomes.
Let’s start with row 1. We see this is our control group with n=5. We have the
sample mean of 88.6 with a 95% confidence interval from 79.5 to 97.7. We have a
sample standard deviation of 7.3. SAS also gives us the 95% confidence interval
for the standard deviation. Finally, SAS gives us the standard error of 7.3 divided
by the square root of 5 with value 3.27.
We have the same information in row 2 for our treatment group.
The third row has the confidence interval for m1-m2 from –20.8 to –5.2. Notice this
confidence interval does not contain zero. Later we will see why this is important to
us.
Finally, notice SAS is always testing the two sided hypothesis test:
Ho: u1=u2 vs. Ha: u1 not equal u2.
11
T-Tests
Variable
Method
Variances
Time
Time
Pooled
Satterthwaite
Equal
Unequal
DF
t Value
Pr > |t|
8
4.64
-3.83
-3.83
0.0050
0.0141
Note: SAS tests both with assumption σ1=σ2 and σ1 not
equal σ2
12
This is the output for the t-test statistic. Notice we have two results Pooled and
Satterthwaite. These correspond to the two choices that we have for the t statistic.
We need to decide which is appropriate for our analysis based on our data.
If we go back to the previous slide we see the standard deviation for the control
group over the standard deviation for the treatment group is greater than 2. This
means we cannot assume the population standard deviations are the same. We
need to choose the variances unequal option (Satterthwaite). Our degrees of
freedom when we do this calculation by hand are the smalelr of n1-1 or n2-1. SAS
uses a formula to calculate more exact degrees of freedom, so our number will not
match. The t-value is -3.83 with a two sided p-value of 0.0141.
At a = 0.05 we would reject the null and conclude response times are different.
12
Equality of Variances
Variable
Method
Time
Folded F
Num DF
Den DF
F Value
Pr > F
4
4
12.40
0.0318
Note: If Pr > F is < 0.05 do NOT assume σ1=σ2 do not
pool sample variances.
13
So why this final piece of output when we are able to draw our conclusion from the
previous output? Well, SAS performs a test of equality for population variances
instead of using our ratio as a rule of thumb. Generally, the results will agree.
Here SAS has the Ho: sigma1=sigma2 vs. Ha: sigma1 not equal sigma 2.
The test statistic is an f with a p-value of 0.03. At a = 0.05 we would reject the null
and conclude the population variance cannot be assumed to be equal. This would
lead us to use the Satterthwaite test above – as we had decided before.
Recall: we said that the confidence interval for the difference of means does not
contain zero. This corresponds to the two sided hypothesis test of the difference of
means. If the confidence interval does not contain zero we would reject the null
hypothesis of equal means. Note however; SAS calculates this confidence interval
is based on the assumption that sigma1=sigma2. Your results may not always
match if you cannot make this assumption.
13
Hypothesis Testing
Comparing Two Means:
An Example
„
The effect of environmental exposure to
lead on intellectual development is
investigated using two randomly
selected samples of 7 year old children
from similar backgrounds but with
different lead exposures.
14
Here is an example not using SAS to do our analysis.
Lead has detrimental effect on intellectual development, especially when young
children are exposed. The effect of environmental exposure to lead on intellectual
development is investigated using two randomly selected samples of 7 year old
children from similar backgrounds but with different lead exposures.
14
Hypothesis Testing
Comparing Two Means:
An Example
„
„
Serum lead levels in group 1 > 30 ug/dL
Serum lead levels in group 2 < 30 ug/dL
15
The two groups of children have different lead levels. One group had lead levels
above 30 micrograms per deci liter. The other group had lead levels below 30
micrograms per deci liter.
Researchers are wondering if children with lead levels above 30 micrograms per
deci liter will score differently on intelligence tests than the children with lead levels
that are lower.
15
Hypothesis Testing
Comparing Two Means:
An Example
„
Does a significant difference exist between
the mean intelligence test score in these
two groups?
„
The data for intelligence test score is
summarized below:
n1=61
n2=41
x1=94
x2=101
s1=17
s2=8
16
A random sample was drawn from each populations and the children were given an
establish intelligence test.
The results are as follows. Of the 61 kids in the higher lead level group the average
score was 94 with a standard deviation of 17 points. Of the 41 kids with the lower
lead level the average score was 101 with a standard deviation of 8 points.
Is there a difference between mean intelligence test scores for the different
populations? The sample averages are different, but this could have happened by
chance.
We can do a hypothesis test of two means to see if the means are significantly
different.
16
Hypothesis Testing
Comparing Two Means:
An Example
„
„
Step 1: State your hypotheses (set α=.01)
„ H 0 : μ1 - μ2 = 0
„ Ha: μ1 - μ2 ≠ 0 (two-sided)
Step 2 : Calculate your test statistic
t=
( x1 − x2 ) − ( μo )
s12 s22
+
n1 n2
=
(94 − 101) − 0
17 2 82
+
61 41
= −2.789
17
The first step is to write our null and alternative hypothesis. Remember this is a
two-sided hypothesis. We did not specify that either group would be lower.
Next we need to decide with test statistic to use. We do not know sigma for either
populations so we will use a t statistic, but which one?
If we look at the ratio of the sample standard deviations, the larger over the smaller,
we see that this value is greater than two. We do not assume the population
standard deviations are the same and we do not pool the variance.
The unpooled t value is –2.789.
17
Hypothesis Testing
Comparing Two Means:
An Example
„
Step 3: Calculate the p-value
2 * p (t ≤ −2.789) = 2 * .0025 = .005
Degrees of freedom = 40
„
Step 4 : Make a conclusion
p-value < α, then reject Ho
The data suggests a significant mean
difference exists in intelligence scores for the
two groups.
18
Step 3 is calculate our pvalue. We look at 2 times the probability that a t with 40
degrees of freedom is less than - 2.789.
Our conclusion is to reject Ho. This means the scores are significantly differenct at
the alpha 0.05 level. Our sample means were not likely different by chance. It is
likely the average score for the populations would have different locations.
In other words, the data suggests a significant mean difference exists in intelligence
scores for the two groups.
18
Hypothesis Testing:
A Pooled T-test Example
„
Independent random samples selected from two
normal populations produced the sample means
and standard deviations shown in the table:
Sample 1
Sample 2
Sample size
17
12
Mean
5.4
7.9
Sample Standard deviation
3.4
4.8
„
„
Test the null hypothesis that the population means
are equal vs. the alternative that they are not equal.
Let α=0.05, this means we will reject the null
hypothesis when it is true 5% of the time.
19
Here is an example where we would choose to use the pooled t test.
Independent random samples selected from two normal populations produced the
following results. There were 17 subjects in sample 1 with a mean value of 5.4 and
a sample standard deviation of 3.4. There were 12 subjects in sample 2 with a
mean value of 7.9 and a standard deviation of 4.8.
I want to test the null hypothesis that the population means are equal vs. the
alternative that they are not equal.
Let =0.05, this means we will reject the null hypothesis when it is true 5% of the
time.
Notice the ratio of the larger sample standard deviation divided by the smaller
sample standard deviation is less than two.
19
Hypothesis Testing:
A Pooled T-test Example
Ho: μ1- μ2 =0
Ha: μ1- μ2 ≠0
Calculate the test statistic:
1.
2.
s 2p =
( n1 − 1) s12 + (n2 − 1) s22 (17 − 1)( 3.42 ) + (12 − 1)( 4.82 )
=
= 16.24
n1 + n2 − 2
17 + 12 − 2
and
t=
( x1 − x2 ) − μo
⎛1 1⎞
s p ⎜⎜ + ⎟⎟
⎝ n1 n2 ⎠
2
=
(5.4 − 7.9) − 0
1⎞
⎛1
16.24⎜ + ⎟
17
12
⎝
⎠
= −1.645
20
We choose to use the pooled t –test . First, we need to figure out what the pooled
estimate of the variance would be. We call this sp. It’s value is 16.24. We use this
value in the denominator for the t statistic.
Our statistic yields a value of –1.645.
20
Hypothesis Testing:
A Pooled T-test Example
2.
3.
4.
This test statistic follows the t-distribution
with 27 degrees of freedom.
P-value=2*P(T>1.645) =0.112 (answer from
calculator).
Therefore we fail to reject the null hypothesis
based on an α-level of 0.05 and conclude
that the two population means are not likely
different.
21
This test statistic follows the t-distribution with 27 degrees of freedom. This is n1 +
n2 –2.
The P-value=2*P(T>1.645) =0.112 . I obtained this answer from a calculator of a
computer program. You cannot get an exact value using the table in your book.
Our p-value leads us to fail to reject the null hypothesis based on an ?-level of 0.05
and conclude that the two population means are not likely different.
This assumes we had the power to detect a difference should there be one.
This ends lesson 1c. Please go to self assessment 1c.
21