Biostat 200 Lecture 7 1. Hypothesis tests so far T-test of one mean: Null hypothesis µ=µ 0 Test of...
-
Upload
marsha-dorsey -
Category
Documents
-
view
220 -
download
0
Transcript of Biostat 200 Lecture 7 1. Hypothesis tests so far T-test of one mean: Null hypothesis µ=µ 0 Test of...
![Page 1: Biostat 200 Lecture 7 1. Hypothesis tests so far T-test of one mean: Null hypothesis µ=µ 0 Test of one proportion: Null hypothesis p=p 0 Paired t-test:](https://reader036.fdocuments.net/reader036/viewer/2022062423/56649ea95503460f94bad557/html5/thumbnails/1.jpg)
Biostat 200Lecture 7
1
![Page 2: Biostat 200 Lecture 7 1. Hypothesis tests so far T-test of one mean: Null hypothesis µ=µ 0 Test of one proportion: Null hypothesis p=p 0 Paired t-test:](https://reader036.fdocuments.net/reader036/viewer/2022062423/56649ea95503460f94bad557/html5/thumbnails/2.jpg)
Hypothesis tests so far
• T-test of one mean: Null hypothesis µ=µ0
• Test of one proportion: Null hypothesis p=p0
• Paired t-test: Null hypothesis µ1=µ2
• Independent samples t-test: Null hypothesis µ1=µ2
– Assume equal or unequal variances
• Proportion test for two independent samples: Null hypothesis p1 = p2
2
![Page 3: Biostat 200 Lecture 7 1. Hypothesis tests so far T-test of one mean: Null hypothesis µ=µ 0 Test of one proportion: Null hypothesis p=p 0 Paired t-test:](https://reader036.fdocuments.net/reader036/viewer/2022062423/56649ea95503460f94bad557/html5/thumbnails/3.jpg)
Comparison of several means: analysis of variance
• Why is it called analysis of variance?– The test compares the between-group variability
• How different are the groups from the overall mean to the within-group variability
• Why can’t we just do t-tests on the pairs of groups?– Multiple comparisons problem– P(do not reject H0 | H0 ) on one test = 1- – P(do not reject H0 | H0 ) on n tests = (1- )n
– P(reject H0 | H0 ) on at least one test = 1-(1-)n
– If =0.05 and n=4 then this is 0.185Pagano and Gavreau, Chapter 12 3
![Page 4: Biostat 200 Lecture 7 1. Hypothesis tests so far T-test of one mean: Null hypothesis µ=µ 0 Test of one proportion: Null hypothesis p=p 0 Paired t-test:](https://reader036.fdocuments.net/reader036/viewer/2022062423/56649ea95503460f94bad557/html5/thumbnails/4.jpg)
Comparison of several means: analysis of variance
• We calculate the ratio of:– The between group variability
• The variability around the overall (or grand) mean
– to the overall within group variability
Pagano and Gavreau, Chapter 12
x
4
![Page 5: Biostat 200 Lecture 7 1. Hypothesis tests so far T-test of one mean: Null hypothesis µ=µ 0 Test of one proportion: Null hypothesis p=p 0 Paired t-test:](https://reader036.fdocuments.net/reader036/viewer/2022062423/56649ea95503460f94bad557/html5/thumbnails/5.jpg)
Comparison of several means: analysis of variance
• We calculate the ratio of:– The between group variability
• The variability around the overall (or grand) mean
– to the within group variability • A weighted average of the variances within each group
k= the number of groups being comparedn1, n2, nk = the number of observations in each group
Pagano and Gavreau, Chapter 12
1
)(...)()( 2222
2112
k
xxnxxnxxns kkB
knnn
snsnsns
k
kkW
...
)1(...)1()1(
21
2222
2112
x
5
![Page 6: Biostat 200 Lecture 7 1. Hypothesis tests so far T-test of one mean: Null hypothesis µ=µ 0 Test of one proportion: Null hypothesis p=p 0 Paired t-test:](https://reader036.fdocuments.net/reader036/viewer/2022062423/56649ea95503460f94bad557/html5/thumbnails/6.jpg)
Comparison of several means: analysis of variance
• The test statistic is
• We compare our F statistic to the F-distribution, with k-1 and n-k degrees of freedom– k=the number of means being compared– n=the total number of observations
2
2
W
B
s
sF
Pagano and Gavreau, Chapter 12 6
![Page 7: Biostat 200 Lecture 7 1. Hypothesis tests so far T-test of one mean: Null hypothesis µ=µ 0 Test of one proportion: Null hypothesis p=p 0 Paired t-test:](https://reader036.fdocuments.net/reader036/viewer/2022062423/56649ea95503460f94bad557/html5/thumbnails/7.jpg)
F-distribution
Pagano and Gavreau, Chapter 12 7
![Page 8: Biostat 200 Lecture 7 1. Hypothesis tests so far T-test of one mean: Null hypothesis µ=µ 0 Test of one proportion: Null hypothesis p=p 0 Paired t-test:](https://reader036.fdocuments.net/reader036/viewer/2022062423/56649ea95503460f94bad557/html5/thumbnails/8.jpg)
F distribution
0 1 2 3 4 5 6 7 8 9 10x
n2 n3
n5 n20
f dist with n=5 per group
0 1 2 3 4 5 6 7 8 9 10x
n2 n3
n5 n20
f dist with n=50 per group
8
![Page 9: Biostat 200 Lecture 7 1. Hypothesis tests so far T-test of one mean: Null hypothesis µ=µ 0 Test of one proportion: Null hypothesis p=p 0 Paired t-test:](https://reader036.fdocuments.net/reader036/viewer/2022062423/56649ea95503460f94bad557/html5/thumbnails/9.jpg)
ANOVA example• CD4 count by drinking category
Pagano and Gavreau, Chapter 12
010
2030
010
2030
0 500 1000 1500
0 500 1000 1500
Abstainer Past drinker
Current drinkerPer
cent
cd4countGraphs by last time took alcohol- never, past, current
9
![Page 10: Biostat 200 Lecture 7 1. Hypothesis tests so far T-test of one mean: Null hypothesis µ=µ 0 Test of one proportion: Null hypothesis p=p 0 Paired t-test:](https://reader036.fdocuments.net/reader036/viewer/2022062423/56649ea95503460f94bad557/html5/thumbnails/10.jpg)
10
05
001
,000
1,5
00C
D4
ocu
nt
Abstainer Past drinker Current drinker
![Page 11: Biostat 200 Lecture 7 1. Hypothesis tests so far T-test of one mean: Null hypothesis µ=µ 0 Test of one proportion: Null hypothesis p=p 0 Paired t-test:](https://reader036.fdocuments.net/reader036/viewer/2022062423/56649ea95503460f94bad557/html5/thumbnails/11.jpg)
ANOVA example tabstat cd4count, by(last_alc_cat) s(n mean sd min median max)
Summary for variables: cd4count by categories of: last_alc_cat (last time took alcohol- never, past,
current)
last_alc_cat | N mean sd min p50 max----------------+------------------------------------------------------------ Abstainer | 94 278.3191 235.4192 1 213.5 1038 Past drinker | 47 237.1915 238.4878 0 183 1010Current drinker | 126 331.1587 266.1824 0 263.5 1368----------------+------------------------------------------------------------ Total | 267 296.015 252.6171 0 235 1368-----------------------------------------------------------------------------
Pagano and Gavreau, Chapter 12 11
![Page 12: Biostat 200 Lecture 7 1. Hypothesis tests so far T-test of one mean: Null hypothesis µ=µ 0 Test of one proportion: Null hypothesis p=p 0 Paired t-test:](https://reader036.fdocuments.net/reader036/viewer/2022062423/56649ea95503460f94bad557/html5/thumbnails/12.jpg)
ANOVA example• CD4 count, by alcohol consumption category oneway var groupvaroneway cd4count last_alc_cat
Analysis of Variance Source SS df MS F Prob > F------------------------------------------------------------------------Between groups 347685.413 2 173842.706 2.76 0.0651 Within groups 16627208.5 264 62981.8505------------------------------------------------------------------------ Total 16974893.9 266 63815.3908
Bartlett's test for equal variances: chi2(2) = 1.8505 Prob>chi2 = 0.396
Pagano and Gavreau, Chapter 12
2Bs
2Ws
2s
12
![Page 13: Biostat 200 Lecture 7 1. Hypothesis tests so far T-test of one mean: Null hypothesis µ=µ 0 Test of one proportion: Null hypothesis p=p 0 Paired t-test:](https://reader036.fdocuments.net/reader036/viewer/2022062423/56649ea95503460f94bad557/html5/thumbnails/13.jpg)
Multiple comparisons
• If we reject H0 , we might want to know which means differed from each other
• But as noted before, if you test all combinations, you increase your chance of rejecting the null
• To be conservative, we reduce the level of , that is we will reject the p-value at a level smaller than the original
• The Bonferoni methods divides by the number of possible pairs of tests
2
*
k
13
![Page 14: Biostat 200 Lecture 7 1. Hypothesis tests so far T-test of one mean: Null hypothesis µ=µ 0 Test of one proportion: Null hypothesis p=p 0 Paired t-test:](https://reader036.fdocuments.net/reader036/viewer/2022062423/56649ea95503460f94bad557/html5/thumbnails/14.jpg)
Multiple comparisons• Use a t-test, but use the within group variance
that weights over all the groups (not just the 2 being examined)
• The test statistic for each pair of means is:
• and the degrees of freedom is n-k where n is the total number of observations and k is the total number of groups (another difference with the ttest for 2 means)
• Reject if the p-value is <*• There are lots of other methods of dealing with
the multiple comparisons issue
)/1/1(2jiW
jiij
nns
xxt
14
![Page 15: Biostat 200 Lecture 7 1. Hypothesis tests so far T-test of one mean: Null hypothesis µ=µ 0 Test of one proportion: Null hypothesis p=p 0 Paired t-test:](https://reader036.fdocuments.net/reader036/viewer/2022062423/56649ea95503460f94bad557/html5/thumbnails/15.jpg)
Multiple comparisons. oneway cd4count last_alc_cat, bonferroni
Analysis of Variance Source SS df MS F Prob > F------------------------------------------------------------------------Between groups 347685.413 2 173842.706 2.76 0.0651 Within groups 16627208.5 264 62981.8505------------------------------------------------------------------------ Total 16974893.9 266 63815.3908
Bartlett's test for equal variances: chi2(2) = 1.8505 Prob>chi2 = 0.396
Comparison of cd4count by last time took alcohol- never, past, current (Bonferroni)Row Mean-|Col Mean | Abstaine Past dri---------+----------------------Past dri | -41.1277 | 1.000 |Current | 52.8396 93.9672 | 0.371 0.088
Difference between the 2 means
p-value for the difference
15
![Page 16: Biostat 200 Lecture 7 1. Hypothesis tests so far T-test of one mean: Null hypothesis µ=µ 0 Test of one proportion: Null hypothesis p=p 0 Paired t-test:](https://reader036.fdocuments.net/reader036/viewer/2022062423/56649ea95503460f94bad557/html5/thumbnails/16.jpg)
Nonparametric tests• The hypothesis tests that use the z-statistic (i.e. when σ , the population
standard deviation, is known) assume that the underlying distribution of the parameter we are estimating (sample mean, sample proportion) is approximately normal. This will be true under the CLT if n is large enough.
• However, we usually do not know σ, or if the data originally came from a normal distribution. If are data are very skewed, we need to be wary of this assumption.
• Nonparametric techniques make fewer assumptions about the underlying distributions – they only assume the populations being compared have the same basic shape but do not assume an underlying distribution
• The 3 step procedure is the same: hypothesis, test, reject or fail to reject
• We will discuss nonparametric tests that might be used instead of the “parametric” tests we previously discussed
Pagano and Gavreau, Chapter 13 16
![Page 17: Biostat 200 Lecture 7 1. Hypothesis tests so far T-test of one mean: Null hypothesis µ=µ 0 Test of one proportion: Null hypothesis p=p 0 Paired t-test:](https://reader036.fdocuments.net/reader036/viewer/2022062423/56649ea95503460f94bad557/html5/thumbnails/17.jpg)
Test assumptions• The hypothesis tests that use the z-statistic (i.e. when σ , the population
standard deviation, is known) assume that the underlying distribution of the parameter we are estimating (sample mean, sample proportion) is approximately normal. This will be true under the CLT if n is large enough.
• However, we usually do not know σ, and we use s2 and compare our test statistic to the t-distribution. In theory the underlying distribution of the data must be normal, but in practicality, if n is fairly large and there are no extreme outliers, the t-test is valid.
• If the data are not normally distributed, the t-test is not the most powerful test to use. – E.g. outliers will inflate the sample variance, decreasing the test statistic and the
chances of rejecting the null.
• Independence of your observations is more critical than normality.
• The 3 step procedure for nonparametric testing is the same: hypothesis, test, reject or fail to reject
Pagano and Gavreau, Chapter 13 17
![Page 18: Biostat 200 Lecture 7 1. Hypothesis tests so far T-test of one mean: Null hypothesis µ=µ 0 Test of one proportion: Null hypothesis p=p 0 Paired t-test:](https://reader036.fdocuments.net/reader036/viewer/2022062423/56649ea95503460f94bad557/html5/thumbnails/18.jpg)
Nonparametric tests for paired observations
• The Sign test– For paired or matched observations (analogous to the paired
t-test)– H0 : median1 = median2
– Most useful if the sample size is small or the distribution of differences is very skewed
– The differences between the pairs are given a sign: + if a positive difference
– if a negative difference nothing if the difference=0 – Count the number of +s , denoted by D
Pagano and Gavreau, Chapter 13 18
![Page 19: Biostat 200 Lecture 7 1. Hypothesis tests so far T-test of one mean: Null hypothesis µ=µ 0 Test of one proportion: Null hypothesis p=p 0 Paired t-test:](https://reader036.fdocuments.net/reader036/viewer/2022062423/56649ea95503460f94bad557/html5/thumbnails/19.jpg)
Nonparametric tests for paired observations
– Under H0, ½ the differences will be +s and ½ will be –s
– This is equivalent to saying that the each difference is a Bernoulli random variable, that is, each is+ or – with probability p=.5
– Then the total number of + s (D) is a binomial random variable with p=0.5 and with n trials
– So then the p value for the hypothesis test is the probability of observing D + differences if the true distribution is binomial with parameters and p=0.5
– You could use the binomialtail function for a one-sided hypothesis
• di binomialtail(n,D,.5)
Pagano and Gavreau, Chapter 13 19
![Page 20: Biostat 200 Lecture 7 1. Hypothesis tests so far T-test of one mean: Null hypothesis µ=µ 0 Test of one proportion: Null hypothesis p=p 0 Paired t-test:](https://reader036.fdocuments.net/reader036/viewer/2022062423/56649ea95503460f94bad557/html5/thumbnails/20.jpg)
Nonparametric tests for paired observations
– Under H0, ½ the differences will be +s and ½ will be –s
– This is equivalent to saying that the each difference is a Bernoulli random variable, that is, each is+ or – with probability p=.5
– Then the total number of + s (D) is a binomial random variable with p=0.5 and with n trials.
– Binomial mean = np ; Binomial SD = np(1-p)– So mean = .5n and SD=.25n SD – Then D ~ N(.5n, .25n)Because D using the normal
approximation, and z ~ N(0,1) where z is:
Pagano and Gavreau, Chapter 13
n
nDz
25.
)5(.
20
![Page 21: Biostat 200 Lecture 7 1. Hypothesis tests so far T-test of one mean: Null hypothesis µ=µ 0 Test of one proportion: Null hypothesis p=p 0 Paired t-test:](https://reader036.fdocuments.net/reader036/viewer/2022062423/56649ea95503460f94bad557/html5/thumbnails/21.jpg)
Nonparametric tests for paired observations
Pagano and Gavreau, Chapter 13
Obs. no Weight before (kg)
Weight after (kg)
Difference Difference >0?
Signed rank of difference
1 55 58 3 1 2
2 90 87 -3 0 -2
3 48 55 7 1 4
4 76 65 -9 0 -6
5 64 77 13 1 7
6 84 92 8 1 5
7 56 57 1 1 1
8 81 76 -5 0 -3
9 92 93 1 1 1
10 65 72 7 1 4
Total 7
21
![Page 22: Biostat 200 Lecture 7 1. Hypothesis tests so far T-test of one mean: Null hypothesis µ=µ 0 Test of one proportion: Null hypothesis p=p 0 Paired t-test:](https://reader036.fdocuments.net/reader036/viewer/2022062423/56649ea95503460f94bad557/html5/thumbnails/22.jpg)
signtest var1=var2
. signtest wt1=wt2
Sign test
sign | observed expected-------------+------------------------ positive | 3 5 negative | 7 5 zero | 0 0-------------+------------------------ all | 10 10
One-sided tests: Ho: median of wt1 - wt2 = 0 vs. Ha: median of wt1 - wt2 > 0 Pr(#positive >= 3) = Binomial(n = 10, x >= 3, p = 0.5) = 0.9453
Ho: median of wt1 - wt2 = 0 vs. Ha: median of wt1 - wt2 < 0 Pr(#negative >= 7) = Binomial(n = 10, x >= 7, p = 0.5) = 0.1719
Two-sided test: Ho: median of wt1 - wt2 = 0 vs. Ha: median of wt1 - wt2 != 0 Pr(#positive >= 7 or #negative >= 7) = min(1, 2*Binomial(n = 10, x >= 7, p = 0.5)) = 0.3438
Pagano and Gavreau, Chapter 13
Uses the larger of the number of positive or negative signed pairs
22
![Page 23: Biostat 200 Lecture 7 1. Hypothesis tests so far T-test of one mean: Null hypothesis µ=µ 0 Test of one proportion: Null hypothesis p=p 0 Paired t-test:](https://reader036.fdocuments.net/reader036/viewer/2022062423/56649ea95503460f94bad557/html5/thumbnails/23.jpg)
Nonparametric tests for paired observations
• The sign test does not account for the magnitude of the difference
• The Wilcoxon Signed-Rank Test does– Samples from paired populations – analogous to the paired
t-test– The entire sample is ranked, and the sums of the ranks
compared for the two groups– Ties are given an average rank– The smaller sum of the ranks follows a normal distribution
with mean n*(n+1)/4 and standard deviation under the null assumption of no difference in mediansFor n<12, use the exact distribution, table A.6
Pagano and Gavreau, Chapter 13
24
)12)(1(
nnnT
23
![Page 24: Biostat 200 Lecture 7 1. Hypothesis tests so far T-test of one mean: Null hypothesis µ=µ 0 Test of one proportion: Null hypothesis p=p 0 Paired t-test:](https://reader036.fdocuments.net/reader036/viewer/2022062423/56649ea95503460f94bad557/html5/thumbnails/24.jpg)
signrank var1 = var2
. signrank wt1=wt2
Wilcoxon signed-rank test
sign | obs sum ranks expected
-------------+---------------------------------
positive | 3 17.5 27.5
negative | 7 37.5 27.5
zero | 0 0 0
-------------+---------------------------------
all | 10 55 55
unadjusted variance 96.25
adjustment for ties -0.38
adjustment for zeros 0.00
----------
adjusted variance 95.88
Ho: wt1 = wt2
z = -1.021
Prob > |z| = 0.3071
24
![Page 25: Biostat 200 Lecture 7 1. Hypothesis tests so far T-test of one mean: Null hypothesis µ=µ 0 Test of one proportion: Null hypothesis p=p 0 Paired t-test:](https://reader036.fdocuments.net/reader036/viewer/2022062423/56649ea95503460f94bad557/html5/thumbnails/25.jpg)
Nonparametric tests for independent samples
• The Wilcoxon Rank Sum Test– Also called the Mann-Whitney U test (slightly different
calculation)– Null hypothesis is that the distributions of the two groups are
the same– Samples from independent populations – analogous to the t-
test– The entire sample is ranked, and the sums of the ranks
compared for the two groups– An algorithm to deal with ties– The test statistic is compared to the normal distribution– If the sample sizes are small (<10), exact distributions are
needed – Table A.7– Can be extended to multiple groups (Kruskal-Wallis test)
Pagano and Gavreau, Chapter 13 25
![Page 26: Biostat 200 Lecture 7 1. Hypothesis tests so far T-test of one mean: Null hypothesis µ=µ 0 Test of one proportion: Null hypothesis p=p 0 Paired t-test:](https://reader036.fdocuments.net/reader036/viewer/2022062423/56649ea95503460f94bad557/html5/thumbnails/26.jpg)
ranksum var, by(byvar)
. ranksum bmi, by(sex)
Two-sample Wilcoxon rank-sum (Mann-Whitney) test
sex | obs rank sum expected
-------------+---------------------------------
male | 292 63531.5 77964
female | 241 78779.5 64347
-------------+---------------------------------
combined | 533 142311 142311
unadjusted variance 3131554.00
adjustment for ties -104.98
----------
adjusted variance 3131449.02
Ho: bmi(sex==male) = bmi(sex==female)
z = -8.156
Prob > |z| = 0.0000
26
![Page 27: Biostat 200 Lecture 7 1. Hypothesis tests so far T-test of one mean: Null hypothesis µ=µ 0 Test of one proportion: Null hypothesis p=p 0 Paired t-test:](https://reader036.fdocuments.net/reader036/viewer/2022062423/56649ea95503460f94bad557/html5/thumbnails/27.jpg)
Nonparametric tests for independent samples
kwallis var , by(byvar)
. kwallis bmi, by(racegrp)
Kruskal-Wallis equality-of-populations rank test
+-----------------------------------+ | racegrp | Obs | Rank Sum | |------------------+-----+----------| | White, Caucasian | 312 | 85827.00 | | Asian/PI | 158 | 40872.00 | | Other | 65 | 16681.00 | +-----------------------------------+
chi-squared = 1.581 with 2 d.f.probability = 0.4536
chi-squared with ties = 1.581 with 2 d.f.probability = 0.4536
Pagano and Gavreau, Chapter 13 27
![Page 28: Biostat 200 Lecture 7 1. Hypothesis tests so far T-test of one mean: Null hypothesis µ=µ 0 Test of one proportion: Null hypothesis p=p 0 Paired t-test:](https://reader036.fdocuments.net/reader036/viewer/2022062423/56649ea95503460f94bad557/html5/thumbnails/28.jpg)
Parametric vs. non-parametric (distribution free) tests
• Non parametric tests:– No normality requirement– Do require that the underlying distributions being
compared have the same basic shape– Ranks are less sensitive to outliers– Can be used for ordinal data
• If the underlying distributions are approximately normal, then parametric tests are more powerful
28
![Page 29: Biostat 200 Lecture 7 1. Hypothesis tests so far T-test of one mean: Null hypothesis µ=µ 0 Test of one proportion: Null hypothesis p=p 0 Paired t-test:](https://reader036.fdocuments.net/reader036/viewer/2022062423/56649ea95503460f94bad557/html5/thumbnails/29.jpg)
Statistical hypothesis testsData and comparison type
Alternative hypotheses Parametric test Stata command
Non-parametric test Stata command
Continuous; One mean
Ha: μ≠ μa (two-sided)Ha: μ>μa (one-sided)
Z or t-test
ttest var1=hypoth val.
Dichotomous; One proportion
Ha: p≠ pa (two-sided)Ha: p>pa (one-sided)
Proportion test
prtest var1=hypoth value
Continuous; Two means, paired data
Ha: μ1 ≠ μ2 (two-sided)Ha: μ1 >μ2 (one-sided)
Paired t-test
ttest var1=var2
Sign test (signtest var1=var2) or Wilcoxon Signed-Rank (signrank var1=var2)
Continuous; Two means, independent data
Ha: μ1 ≠ μ2 (two-sided)Ha: μ1 >μ2 (one-sided)
T-test (equal or unequal variance) ttest var1, by(byvar) unequal (as needed)
Wilcoxon rank-sum test
ranksum var1, by(byvar)
Dichotomous; two proportions
Ha: p1≠ p2 (two-sided)Ha: p1 >p2 (one-sided)
Proportion test (z-test)
prtest var1, by(byvar)
Continuous, Two or more means, independent data
Ha: μ1 ≠ μ2 or μ1 ≠ μ3 or μ2 ≠ μ3
etc.
ANOVA
oneway var1 byvar
Kruskal Wallis test kwallis var1, by(byvar) 29
![Page 30: Biostat 200 Lecture 7 1. Hypothesis tests so far T-test of one mean: Null hypothesis µ=µ 0 Test of one proportion: Null hypothesis p=p 0 Paired t-test:](https://reader036.fdocuments.net/reader036/viewer/2022062423/56649ea95503460f94bad557/html5/thumbnails/30.jpg)
For next time
• Read Pagano and Gauvreau
– Pagano and Gavreau Chapters 12-13 (review)– Pagano and Gavreau Chapter 15