Always, we have to make assumptions in determining the distribution of the test statistic. In many cases, you saw the assumptions. In some, they were hidden.
Review: Procedure Requirements
Test
Assumption
\(Z\)-test
Normality
\(t\)-test
Normality
Variance Test
Normality
Wilcoxon Test
Symmetry
Mann-Whitney Test
none
Binomial Test
none
Proportions Test
Normality
Chi-Square Goodness-of-Fit Test
Normality
ANOVA Requirements
For the analysis of variance procedure, there are two assumptions that we needed to make:
Normality in each group.
Equal variances across the groups.
ANOVA Requirements
These assumptions can be tested using the following tests:
Shapiro-Wilk test (shapiroTest)
Fligner-Killeen test (fligner.test)
The null hypothesis for each test is:
\(H_0 :\) the data are from a Normal distribution.
\(H_0 :\) The variances are equal. (\(\sigma_1^2 = \sigma_2^2 = \dots = \sigma_k^2\))
Thus, small \(p\)-values indicate the requirement is not met by the data.
Example #1: Rice Yields
Does rice variety influence average yield amongst these four varieties?
First, because we are testing for independence between a numeric variable (yield) and a categorical variable (variety), we would like to use the analysis of variance procedure.
The hypotheses are:
\[
\begin{aligned}
H_0 &: \mu_1 = \mu_2 = \mu_3 = \mu_4 \\
H_A &: \textrm{At least one of the means differs from the others.}
\end{aligned}
\]
Example #1: Rice Yields
The following code loads the data and tests the assumptions:
Shapiro-Wilk Test
Adjustment: Bonferroni correction (k = 4 )
Level p.value
A 0.3148640
B 1.0000000
C 0.5065811
D 0.8381207
fligner.test(yield ~ variety)
Fligner-Killeen test of homogeneity of variances
data: yield by variety
Fligner-Killeen:med chi-squared = 1.0026, df = 3, p-value = 0.8006
Example #1: Rice Yields
Incomplete Conclusion: We are asked to determine if the rice yield and the rice variety are independent. To do this, we would prefer to use the analysis of variance procedure, because it is the most powerful of the available tests. It has two requirements: The data are from a Normal distribution in each group; and the variances are the same across the groups. Neither assumption is violated. The minimum \(p\)-value from the Shapiro-Wilk test is \(0.0787\), which is greater than \(\alpha = 0.05\). The \(p\)-value from the Fligner-Killeen test, \(0.8006\), is also greater than our \(\alpha = 0.05\). Because neither assumption is violated, we can use the analysis of variance procedure.
The small \(p\)-value of \(0.00503\) of the ANOVA procedure indicates that the two variables, yield and variety, are dependent. Not all varieties have the same average yield.
Beyond ANOVA
Note that the conclusion was at least one mean differed from the others. That is hardly helpful.
What we really want to know is “which variety is different?”
ANOVA cannot answer that question.
Tukey’s HSD Test
However, there is a procedure that can answer it: Tukey’s Honestly Significant Difference Test.
Its assumptions are the same as for ANOVA. So, if you use ANOVA, then you can use Tukey’s HSD test.
Tukey’s HSD Test
The code to perform Tukey’s HSD test on our model is:
Find the \(p\)-values and interpret them for the null hypothesis “the difference in averages between these two levels is 0.”
At our usual level of significance, we were only able to detect differences in average yield between Varieties B and D and between Varieties C and D.
Variety D has a higher average yield than Variety B by between 53 and 324.
Variety D has a higher average yield than Variety C by between 43 and 313.
We did not detect a difference between average yield between any other comparisons.
Tukey’s HSD Test
These conclusions are hardly surprising in light of the data:
Kruskal-Wallis Test
If any of the assumptions necessary for ANOVA are violated, you should not use ANOVA.
Like the \(t\)-test, there is a non-parametric alternative to ANOVA. It is called the Kruskal-Wallis test.
It has the same requirements as the Mann-Whitney test.
It is a part of the agricolae package, which you have to install.
Its output is simpler than that of ANOVA.
It has its own multiple comparisons test, the Kruskal (multiple comparisons) test.
The Kruskal test output is also simpler than that of Tukey’s HSD.
Example #2: Citizen’s Initiative
The citizen’s initiatize allows the people of the state to force a vote on a given issue. Do the different political cultures use the initiative at the same rates?
The hypotheses are:
\[
\begin{aligned}
H_0 &: \mu_m = \mu_i = \mu_t \\
H_A &: \textrm{At least one of the means differs from the others.}
\end{aligned}
\]
Example #2: Citizen’s Initiative
Because we are comparing multiple means, we would like to use the ANOVA procedure. It has two assumptions:
The data come from a Normal distribution in each group.
The data have the same variance across the groups.
Fligner-Killeen test of homogeneity of variances
data: inituse by domPolCulture
Fligner-Killeen:med chi-squared = 10.007, df = 2, p-value = 0.006715
Example #2: Citizen’s Initiative
Because at least one requirement was not met, we should not use ANOVA.
We will use the Kruskal-Wallis test:
kruskal.test(inituse, domPolCulture)
Kruskal-Wallis rank sum test
data: inituse and domPolCulture
Kruskal-Wallis chi-squared = 6.3238, df = 2, p-value = 0.04235
Because the \(p\)-value is less that our usual \(\alpha = 0.05\), we reject the null hypothesis. We can conclude that at least one mean differs from the others. Which one?
Example #2: Citizen’s Initiative
To determine which is different, we use Kruskal’s multiple comparisons test:
print(kruskal(inituse, domPolCulture))
$statistics
Chisq Df p.chisq t.value MSD
6.323785 2 0.04234553 2.010635 8.932211
$parameters
test p.ajusted name.t ntr alpha
Kruskal-Wallis none domPolCulture 3 0.05
$means
inituse rank std r Min Max Q25 Q50 Q75
Individualistic 4.705882 24.91176 6.272606 17 0 18 0 0 10
Moralistic 14.764706 32.32353 19.533719 17 0 60 0 8 16
Traditionalistic 2.764706 20.76471 5.984662 17 0 23 0 0 2
$comparison
NULL
$groups
inituse groups
Moralistic 32.32353 a
Individualistic 24.91176 ab
Traditionalistic 20.76471 b
attr(,"class")
[1] "group"
Example #2: Citizen’s Initiative
Treatments with the same letter are not significantly different.
From this, we know we detected a difference in average initiative use between the moralistic states and the traditionalistic states. No other differences were detected.
Example #2: Citizen’s Initiative
Conclusion:
We are asked to determine if the initiative use and the political culture are independent. To do this, we would prefer to use the analysis of variance procedure, because it is the most powerful of the available tests. It has two requirements: The data are from a Normal distribution in each group; and the variances are the same across the groups. Both assumptions are violated. The maximum \(p\)-value from the Shapiro-Wilk test is 0.00204, which is much less than \(\alpha = 0.05\). The \(p\)-value from the Fligner-Killeen test, 0.0067, is also less than our \(\alpha = 0.05\). Because both assumptions are violated, we should not use the analysis of variance procedure. We must use the Kruskal-Wallis test.
Example #2: Citizen’s Initiative
Conclusion:
The small \(p\)-value of 0.0424 of the Kruskal-Wallis test indicates that the two variables, initiative use and political culture are dependent. Not all political cultures use the initiative process equally. According to the Kruskal multiple comparisons test, we can conclude that states with a moralistic political culture tend to use the initiative more frequently than states with a traditionalistic culture. No other comparisons were significant.
Example #2: Citizen’s Initiative
Again, these conclusions make sense when seeing the graphic:
Example #3: Violent Crime
Does the 2000 violent crime rate significantly vary across the four census regions?
The hypotheses are:
\[
\begin{aligned}
H_0 &: \mu_N = \mu_S = \mu_M = \mu_W \\
H_A &: \textrm{At least one of the means differs from the others.}
\end{aligned}
\]
Example #3: Violent Crime
Because we are comparing multiple means, we would like to use the ANOVA procedure. It has two assumptions:
The data come from a Normal distribution in each group.
The data have the same variance across the groups.
Example #3: Violent Crime
To check this using R, we run the following code:
shapiroTest(vcrime00 ~ census4)
Shapiro-Wilk Test
Adjustment: Bonferroni correction (k = 4 )
Level p.value
Northeast 1.0000000
Midwest 1.0000000
South 0.2251474
West 1.0000000
fligner.test(vcrime00 ~ census4)
Fligner-Killeen test of homogeneity of variances
data: vcrime00 by census4
Fligner-Killeen:med chi-squared = 6.0913, df = 3, p-value = 0.1073
Example #3: Violent Crime
Because no requirement was violated, we can use ANOVA. Here is the code:
cmod1 =aov(vcrime00 ~ census4)summary(cmod1)
Df Sum Sq Mean Sq F value Pr(>F)
census4 3 689569 229856 4.855 0.00505 **
Residuals 47 2225268 47346
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Because the \(p\)-value of 0.00505 is less than our usual \(\alpha = 0.05\), we reject the null hypothesis. We can conclude that at least one mean differs from the others. Again, which one?
Example #3: Violent Crime
To determine which is different, we use the Tukey HSD test.
From this, we now we detected a difference in average violent crime rate between the South and Northwest states and the West and South states, where the South is significantly higher than the Northeast and the South is significantly higher that the West.
Example #3: Violent Crime
Conclusion:
We are asked to determine if the violent crime rate and the census region are independent. To do this, we would prefer to use the analysis of variance procedure, because it is the most powerful of the available tests. It has two requirements: The data are from a Normal distribution in each group; and the variances are the same across the groups. Neither assumption is violated. The minimum \(p\)-value from the Shapiro-Wilk test is 0.2251, which is greater than \(\alpha = 0.05\). The \(p\)-value from the Fligner-Killeen test, 0.1073, is also greater than our \(\alpha = 0.05\). Because neither assumption is violated, we can – and should – use the analysis of variance procedure.
Example #3: Violent Crime
Conclusion:
The small \(p\)-value of 0.00505 of the ANOVA test indicates that the two variables, violent crime rate and census region are dependent. Not all census regions have the same average violent crime rate. According to Tukey’s HSD test, we can conclude that southern states have a significantly higher average violent crime rate than the Northeastern states and the Western states. No other comparisons were significant.
Example #4: Education
Does the 2000 violent crime rate significantly vary across the four census regions?
The hypotheses are:
\[
\begin{aligned}
H_0 &: \textrm{All the means are the same.} \\
H_A &: \textrm{At least one of the means differs from the others.}
\end{aligned}
\]
Example #4: Education
Because we are comparing multiple means, we would like to use the ANOVA procedure. It has two assumptions:
The data come from a Normal distribution in each group.
The data have the same variance across the groups.
Df Sum Sq Mean Sq F value Pr(>F)
domPolCulture 2 276.0 138.02 17.19 2.35e-06 ***
Residuals 48 385.4 8.03
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Because the \(p\)-value is much less than our usual \(\alpha = 0.05\), we reject the null hypothesis. We can conclude that at least one mean differs from the others. Which one?
Example #4: Education
To determine which is different, we use the Tukey HSD test.
From this, we now we detected a difference in average WAEA rate between the traditionalist states and both of the other two types. In both cases, the traditionalistic states tended to have lower WAEA. No other comparisons were statistically significant.
Example #4: Education
Conclusion:
We are asked to determine if the violent crime rate and the census region are independent. To do this, we would prefer to use the analysis of variance procedure, because it is the most powerful of the available tests. It has two requirements: The data are from a Normal distribution in each group; and the variances are the same across the groups. Neither assumption is violated. The minimum \(p\)-value from the Shapiro-Wilk test is 0.6072, which is greater than \(\alpha = 0.05\). The \(p\)-value from the Fligner-Killeen test, 0.2381, is also greater than our \(\alpha = 0.05\). Because neither assumption is violated, we can – and should – use the analysis of variance procedure.
Example #4: Education
Conclusion:
The small \(p\)-value of \(2.35 \times 10^{-6}\) of the ANOVA test indicates that the two variables, WAEA and dominant political culture are dependent. According to Tukey’s HSD test, we can conclude that traditionalistic states have a significantly lower average WAEA than the moralistic and individualistic states. No other comparisons were significant.
Example #5: Average Wealth
Does the 2000 GSP per capita significantly vary across the three political cultures?
The hypotheses are:
\[
\begin{aligned}
H_0 &: \mu_I = \mu_M = \mu_T \\
H_A &: \textrm{At least one of the means differs from the others.}
\end{aligned}
\]
Example #5: Average Wealth
Because we are comparing multiple means, we would like to use the ANOVA procedure. It has two assumptions:
The data come from a Normal distribution in each group.
The data have the same variance across the groups.
Fligner-Killeen test of homogeneity of variances
data: gspcap00 by domPolCulture
Fligner-Killeen:med chi-squared = 0.77112, df = 2, p-value = 0.6801
Example #5: Average Wealth
Because at least one requirement was violated, we should not use ANOVA. We need to use the Kruskal-Wallis test. Here is the code:
kruskal.test(gspcap00 ~ domPolCulture)
Kruskal-Wallis rank sum test
data: gspcap00 by domPolCulture
Kruskal-Wallis chi-squared = 13.752, df = 2, p-value = 0.001032
Because the \(p\)-value of 0.0010 is less than our usual \(\alpha = 0.05\), we reject the null hypothesis. We can conclude that at least one mean differs from the others. Which one? [fragile=singleslide]
Example #5: Average Wealth
To determine which is different, we use Kruskal’s multiple comparisons test:
Treatments with the same letter are not significantly different.
Example #5: Average Wealth
From this, we now we detected a difference in average GSP per capita between the individualistic states and both of the other two types. In both cases, the individualistic states tended to have higher GSP per capita. No other comparisons were statistically significant.
Example #5: Average Wealth
Conclusion:
We are asked to determine if the average GSP per capita and the dominant political culture are independent. To do this, we would prefer to use the analysis of variance procedure, because it is the most powerful of the available tests. It has two requirements: The data are from a Normal distribution in each group; and the variances are the same across the groups. The Normality assumption is violated. The minimum \(p\)-value from the Shapiro-Wilk test is 0.000033, which is much less than \(\alpha = 0.05\). Because an assumption is violated, we need to use the Kruskal-Wallis test.
Example #5: Average Wealth
Conclusion:
The small \(p\)-value of 0.0010 of the Kruskal-Wallis test indicates that the two variables, GSP per capita and dominant political culture are dependent. According to the Kruskal multiple comparison test, we can conclude that individualist states have a significantly higher GSP per capita than the moralistic and traditionalistic. No other comparisons were significant.
Example #6: Legislature Professionalism
Does the professional level of the state’s legislature significantly vary across the three political cultures?
The hypotheses are:
\[
\begin{aligned}
H_0 &: \mu_I = \mu_M = \mu_T \\
H_A &: \textrm{At least one of the means differs from the others.}
\end{aligned}
\]
Example #6: Legislature Professionalism
Because we are comparing multiple means, we would like to use the ANOVA procedure. It has two assumptions:
The data come from a Normal distribution in each group.
The data have the same variance across the groups.
Fligner-Killeen test of homogeneity of variances
data: profleg by domPolCulture
Fligner-Killeen:med chi-squared = 5.1794, df = 2, p-value = 0.07504
Example #6: Legislature Professionalism
Because at least one requirement was violated, we should not use ANOVA. We need to use the Kruskal-Wallis test. Here is the code:
kruskal.test(profleg ~ domPolCulture)
Kruskal-Wallis rank sum test
data: profleg by domPolCulture
Kruskal-Wallis chi-squared = 6.5777, df = 2, p-value = 0.0373
Because the \(p\)-value of 0.0373 is less than our usual \(\alpha = 0.05\), we reject the null hypothesis. We can conclude that at least one mean differs from the others. Which one?
Example #6: Legislature Professionalism
To determine which is different, we use Kruskal’s multiple comparisons test:
print(kruskal(profleg, domPolCulture))
$statistics
Chisq Df p.chisq
6.577695 2 0.03729682
$parameters
test p.ajusted name.t ntr alpha
Kruskal-Wallis none domPolCulture 3 0.05
$means
profleg rank std r Min Max Q25 Q50 Q75
Individualistic 0.2764706 32.82353 0.15519911 17 0.06 0.66 0.19 0.260 0.3100
Moralistic 0.2152941 22.35294 0.17507561 17 0.04 0.65 0.11 0.160 0.2300
Traditionalistic 0.1712500 21.06250 0.05264662 16 0.10 0.26 0.13 0.165 0.2025
$comparison
NULL
$groups
profleg groups
Individualistic 32.82353 a
Moralistic 22.35294 b
Traditionalistic 21.06250 b
attr(,"class")
[1] "group"
Treatments with the same letter are not significantly different.
Example #6: Legislature Professionalism
From this, we now we detected a difference in average level of legislative professionalism between the individualistic states and both of the other two types. In both cases, the individualistic states tended to have higher levels of legislative professionalism. No other comparisons were statistically significant.
Example #6: Legislature Professionalism
Conclusion:
We are asked to determine if the level of legislative professionalism and the dominant political culture are independent. To do this, we would prefer to use the analysis of variance procedure, because it is the most powerful of the available tests. It has two requirements: The data are from a Normal distribution in each group; and the variances are the same across the groups. The Normality assumption is violated. The minimum \(p\)-value from the Shapiro-Wilk test is 0.0020, which is much less than \(\alpha = 0.05\). Because an assumption is violated, we need to use the Kruskal-Wallis test.
Example #6: Legislature Professionalism
Conclusion:
The small \(p\)-value of 0.0373 of the Kruskal-Wallis test indicates that the two variables, legislative professionalism and dominant political culture, are dependent. According to Kruskal’s multiple comparisons test, we can conclude that individualistic states tend to have a significantly higher level of legislative professionalism than the moralistic and traditionalistic states. No other comparisons were significant.