Patient | Adren | Synth | d | Sign |
---|---|---|---|---|
1 | 3.5 | 3.2 | -0.3 | - |
2 | 2.6 | 3.1 | 0.5 | + |
3 | 3.0 | 3.3 | 0.3 | + |
4 | 1.9 | 2.4 | 0.5 | + |
5 | 2.9 | 2.9 | 0.0 | NA |
6 | 2.4 | 2.8 | 0.4 | + |
7 | 2.0 | 2.6 | 0.6 | + |
Pagona TB, Chapter 13
2024-12-04
Understand the difference between and appropriate use of parametric and nonparametric tests
Use the (Wilcoxon) Signed-rank test to determine if a single sample or paired sample are symmetric around some value.
Use the Wilcoxon Rank-Sum test to compare two independent numeric samples.
Use the Fisher’s Exact test to determine if two categorical variables are associated.
Use the Kruskal-Wallis test to compare two or more independent numeric samples.
Use the (Wilcoxon) Signed-rank test to determine if a single sample or paired sample are symmetric around some value.
Use the Wilcoxon Rank-Sum test to compare two independent numeric samples.
Use the Fisher’s Exact test to determine if two categorical variables are associated.
Use the Kruskal-Wallis test to compare two or more independent numeric samples.
Pros
Cons
Type of data | Parametric test | Nonparametric test |
---|---|---|
Single sample, numeric | Single mean hypothesis test or t-test (L11) | Sign test or (Wilcoxon) signed-rank test |
Paired sample, numeric | Mean difference (paired) hypothesis test or t-test (L12) | Sign test or (Wilcoxon) signed-rank test |
Two independent sample, numeric | Difference in means hypothesis test or two sample t-test (L13) | Wilcoxon rank-sum test or Mann-Whitney U test |
Single sample, binary | Single proportion hypothesis test (L15) | |
Two independent sample, binary | Difference in proportions hypothesis test (L15) | |
2+ independent samples, binary | Chi-squared test (L16) | Fisher’s Exact test |
2+ independent samples, numeric | ANOVA test or F-test (L17) | Kruskal-Wallis test |
Check the assumptions
Set the level of significance \(\alpha\)
Specify the null ( \(H_0\) ) and alternative ( \(H_A\) ) hypotheses
Calculate the test statistic and p-value
Write a conclusion to the hypothesis test
Use the Wilcoxon Rank-Sum test to compare two independent numeric samples.
Use the Fisher’s Exact test to determine if two categorical variables are associated.
Use the Kruskal-Wallis test to compare two or more independent numeric samples.
Type of data | Parametric test | Nonparametric test |
---|---|---|
Single sample, numeric | Single mean hypothesis test or t-test (L11) | Sign test or (Wilcoxon) signed-rank test |
Paired sample, numeric | Mean difference (paired) hypothesis test or t-test (L12) | Sign test or (Wilcoxon) signed-rank test |
Two independent sample, numeric | Difference in means hypothesis test or two sample t-test (L13) | Wilcoxon rank-sum test or Mann-Whitney U test |
Single sample, binary | Single proportion hypothesis test (L15) | |
Two independent sample, binary | Difference in proportions hypothesis test (L15) | |
2+ independent samples, binary | Chi-squared test (L16) | Fisher’s Exact test |
2+ independent samples, numeric | ANOVA test or F-test (L17) | Kruskal-Wallis test |
Patient | Adren | Synth | d | Sign |
---|---|---|---|---|
1 | 3.5 | 3.2 | -0.3 | - |
2 | 2.6 | 3.1 | 0.5 | + |
3 | 3.0 | 3.3 | 0.3 | + |
4 | 1.9 | 2.4 | 0.5 | + |
5 | 2.9 | 2.9 | 0.0 | NA |
6 | 2.4 | 2.8 | 0.4 | + |
7 | 2.0 | 2.6 | 0.6 | + |
+
if the difference is positive and -
if the difference is negativeGeneral wording for hypotheses
\(H_0:\) population is symmetric around some value \(\tilde{\mu}_0\)
\(H_a:\) population is not symmetric around some value \(\tilde{\mu}_0\)
Hypotheses test for example
\(H_0:\) the population difference in reduction of intraocular pressure in treatment with adrenaline vs. new synthetic drug is symmetric around \(\tilde{\mu}_0 =0\)
\(H_a:\) the population difference in reduction of intraocular pressure in treatment with adrenaline vs. new synthetic drug is not symmetric around \(\tilde{\mu}_0 =0\)
Visualize the differences in reduction of pressure \(d\) : Synth - Adren
Patient | Adren | Synth | d | Sign | Rank | Signed_rank |
---|---|---|---|---|---|---|
1 | 3.5 | 3.2 | -0.3 | - | 1.5 | -1.5 |
2 | 2.6 | 3.1 | 0.5 | + | 4.5 | 4.5 |
3 | 3.0 | 3.3 | 0.3 | + | 1.5 | 1.5 |
4 | 1.9 | 2.4 | 0.5 | + | 4.5 | 4.5 |
5 | 2.9 | 2.9 | 0.0 | NA | NA | NA |
6 | 2.4 | 2.8 | 0.4 | + | 3.0 | 3.0 |
7 | 2.0 | 2.6 | 0.6 | + | 6.0 | 6.0 |
Patient | Adren | Synth | d | Sign | Rank | Signed_rank |
---|---|---|---|---|---|---|
1 | 3.5 | 3.2 | -0.3 | - | 1.5 | -1.5 |
2 | 2.6 | 3.1 | 0.5 | + | 4.5 | 4.5 |
3 | 3.0 | 3.3 | 0.3 | + | 1.5 | 1.5 |
4 | 1.9 | 2.4 | 0.5 | + | 4.5 | 4.5 |
5 | 2.9 | 2.9 | 0.0 | NA | NA | NA |
6 | 2.4 | 2.8 | 0.4 | + | 3.0 | 3.0 |
7 | 2.0 | 2.6 | 0.6 | + | 6.0 | 6.0 |
wilcox.test()
\[p-value = 2 * P(\min(T^+,T^−) \leq t)\]
“Attempt” with exact p-value & running one sample test with differences
Recall the hypotheses to the (Wilcoxon) Signed-rank test:
\(H_0:\) the population difference in reduction of intraocular pressure in treatment with adrenaline vs. new synthetic drug is symmetric around \(\tilde{\mu}_0 =0\)
\(H_a:\) the population difference in reduction of intraocular pressure in treatment with adrenaline vs. new synthetic drug is not symmetric around \(\tilde{\mu}_0 =0\)
Conclusion:
There is insufficient evidence the differences in reduction in intraocular pressure differs between the synthetic drug and adrenaline are symmetric about 0 (2-sided Wilcoxon signed rank test \(p\)-value = 0.07314)
\(H_0:\) The population median is \(m\)
\(H_a:\) The population median is NOT \(m\)
Not-so-real example: Run (Wilcoxon) Signed-rank test for paired data with null \(m = 0.7\)
Understand the difference between and appropriate use of parametric and nonparametric tests
Use the (Wilcoxon) Signed-rank test to determine if a single sample or paired sample are symmetric around some value.
Use the Fisher’s Exact test to determine if two categorical variables are associated.
Use the Kruskal-Wallis test to compare two or more independent numeric samples.
Type of data | Parametric test | Nonparametric test |
---|---|---|
Single sample, numeric | Single mean hypothesis test or t-test (L11) | Sign test or (Wilcoxon) signed-rank test |
Paired sample, numeric | Mean difference (paired) hypothesis test or t-test (L12) | Sign test or (Wilcoxon) signed-rank test |
Two independent sample, numeric | Difference in means hypothesis test or two sample t-test (L13) | Wilcoxon rank-sum test or Mann-Whitney U test |
Single sample, binary | Single proportion hypothesis test (L15) | |
Two independent sample, binary | Difference in proportions hypothesis test (L15) | |
2+ independent samples, binary | Chi-squared test (L16) | Fisher’s Exact test |
2+ independent samples, numeric | ANOVA test or F-test (L17) | Kruskal-Wallis test |
The nonparametric alternative to the two-sample \(t\)-test
Also called the Mann-Whitney U test
Unlike the signed-rank test, there is no need to assume symmetry
Necessary condition is that the two populations being compared
Since they have the same shape, when summarizing the test, we can describe the results in terms of a difference in medians.
Hypotheses:
\(H_0:\) the two populations have the same median
\(H_a:\) the two populations do NOT have the same median
Dr. Priya Chaudhary (OHSU) examined the evoked membrane current of dental sensory neurons (in rats) under control conditions and a mixture of capsaicin plus capsazepine (CPZ). J. Dental Research} 80:1518–23, 2001.
Group | variable | n | median |
---|---|---|---|
Capsaicin + CPZ | Memb_current | 6 | 112 |
Control | Memb_current | 6 | 822 |
Rat_ID | Group | Current |
---|---|---|
1 | Control | 3024 |
2 | Control | 2164 |
3 | Control | 864 |
4 | Control | 780 |
5 | Control | 125 |
6 | Control | 110 |
7 | Capsaicin + CPZ | 426 |
8 | Capsaicin + CPZ | 232 |
9 | Capsaicin + CPZ | 130 |
10 | Capsaicin + CPZ | 94 |
11 | Capsaicin + CPZ | 75 |
12 | Capsaicin + CPZ | 55 |
Do the independent samples have the same distribution?
Combine the two samples together (keep track of which observations came from each sample).
Rank the full set of \(N=n_1 + n_2\) observations.
Sum the ranks corresponding to those observations from the smaller sample.
If \(n_1, n_2\) are both less than 10, then use an exact test (can only be done if no ties are present)
In our example, both groups have equal n; choose either for computing W.
\[W_{CPZ}=1+2+3+6+7+8 = 27\]
\[W_{control}=4+5+9+10+11+12 = 51\]
Rat_ID | Group | Current | Rank |
---|---|---|---|
12 | Capsaicin + CPZ | 55 | 1 |
11 | Capsaicin + CPZ | 75 | 2 |
10 | Capsaicin + CPZ | 94 | 3 |
6 | Control | 110 | 4 |
5 | Control | 125 | 5 |
9 | Capsaicin + CPZ | 130 | 6 |
8 | Capsaicin + CPZ | 232 | 7 |
7 | Capsaicin + CPZ | 426 | 8 |
4 | Control | 780 | 9 |
3 | Control | 864 | 10 |
2 | Control | 2164 | 11 |
1 | Control | 3024 | 12 |
\[p-value = 2 \cdot P(W_{CPZ} \leq 27)\]
Exact p-value
Recall the hypotheses to the Wilcoxon rank-sum test:
\(H_0:\) the control and treated populations have the same median
\(H_a:\) the control and treated populations do NOT have the same median
Conclusion:
There is suggestive but inconclusive evidence that the evoked membrane current of dental sensory neurons (in rats) differs between the control group and the group exposed to a mixture of capsaicin plus capsazepine (2-sided Wilcoxon rank-sum test \(p\)-value = 0.06494).
Understand the difference between and appropriate use of parametric and nonparametric tests
Use the (Wilcoxon) Signed-rank test to determine if a single sample or paired sample are symmetric around some value.
Use the Wilcoxon Rank-Sum test to compare two independent numeric samples.
Type of data | Parametric test | Nonparametric test |
---|---|---|
Single sample, numeric | Single mean hypothesis test or t-test (L11) | Sign test or (Wilcoxon) signed-rank test |
Paired sample, numeric | Mean difference (paired) hypothesis test or t-test (L12) | Sign test or (Wilcoxon) signed-rank test |
Two independent sample, numeric | Difference in means hypothesis test or two sample t-test (L13) | Wilcoxon rank-sum test or Mann-Whitney U test |
Single sample, binary | Single proportion hypothesis test (L15) | |
Two independent sample, binary | Difference in proportions hypothesis test (L15) | |
2+ independent samples, binary | Chi-squared test (L16) | Fisher’s Exact test |
2+ independent samples, numeric | ANOVA test or F-test (L17) | Kruskal-Wallis test |
\[P(a, b, c, d) = \dfrac{(a+b)!\cdot(c+d)!\cdot(a+c)!\cdot(b+d)!}{n!\cdot a!\cdot b!\cdot c!\cdot d!}\]
Question: Is there an association between age group and hypertension?
Age Group | Hypertension | No Hypertension | Total |
---|---|---|---|
18-39 yrs | 1 | 11 | 12 |
40-59 yrs | 4 | 9 | 13 |
60+ yrs | 4 | 2 | 6 |
Total | 9 | 22 | 31 |
Hypertension No_Hypertension
[1,] 3.483871 8.516129
[2,] 3.774194 9.225806
[3,] 1.741935 4.258065
We’re going to pretend they are less than 5.
\(\alpha = 0.05\)
Hypothesis test:
Fisher's Exact Test for Count Data
data: hyp_data2
p-value = 0.04062
alternative hypothesis: two.sided
We reject the null hypothesis that age group and hypertension are not associated (\(p=0.04062\)). There is sufficient evidence that age group and hypertension are associated.
Understand the difference between and appropriate use of parametric and nonparametric tests
Use the (Wilcoxon) Signed-rank test to determine if a single sample or paired sample are symmetric around some value.
Use the Wilcoxon Rank-Sum test to compare two independent numeric samples.
Use the Fisher’s Exact test to determine if two categorical variables are associated.
Type of data | Parametric test | Nonparametric test |
---|---|---|
Single sample, numeric | Single mean hypothesis test or t-test (L11) | Sign test or (Wilcoxon) signed-rank test |
Paired sample, numeric | Mean difference (paired) hypothesis test or t-test (L12) | Sign test or (Wilcoxon) signed-rank test |
Two independent sample, numeric | Difference in means hypothesis test or two sample t-test (L13) | Wilcoxon rank-sum test or Mann-Whitney U test |
Single sample, binary | Single proportion hypothesis test (L15) | |
Two independent sample, binary | Difference in proportions hypothesis test (L15) | |
2+ independent samples, binary | Chi-squared test (L16) | Fisher’s Exact test |
2+ independent samples, numeric | ANOVA test or F-test (L17) | Kruskal-Wallis test |
\[\begin{align} H_0 &: \text{pop median}_1 = \text{pop median}_2 = ... = \text{pop median}_k\\ \text{vs. } H_A&: \text{At least one pair } \text{pop median}_i \neq \text{pop median}_j \text{ for } i \neq j \end{align}\]
If \(H_0\) is true, we expect the populations to have the same medians, and thus the ranks to be similar as well.
airquality
data included in base R - no need to load itMonth | variable | n | mean | median | sd |
---|---|---|---|---|---|
5 | Ozone | 26 | 23.615 | 18 | 22.224 |
6 | Ozone | 9 | 29.444 | 23 | 18.208 |
7 | Ozone | 26 | 59.115 | 60 | 31.636 |
8 | Ozone | 26 | 59.962 | 52 | 39.681 |
9 | Ozone | 29 | 31.448 | 23 | 24.142 |
Kruskal-Wallis rank sum test
data: Ozone by Month
Kruskal-Wallis chi-squared = 29.267, df = 4, p-value = 6.901e-06
There is sufficient evidence that the median ozone levels are different in at least two months from May - September, 1973 in New York City (p < 0.001; Kruskal-Wallis test).
Lesson 19 Slides