multipleComparisons¶
Performs multiple comparisons of means using one of Student-Newman-Keuls, LSD, Bonferroni, or Tukey’s procedures.
Synopsis¶
multipleComparisons (means, df, stdError)
Required Arguments¶
- float
means[]
(Input) - Array of length
nGroups
containing the means. - int
df
(Input) - Degrees of freedom associated with
stdError
. - float
stdError
(Input) Effective estimated standard error of a mean. In fixed effects models,
stdError
equals the estimated standard error of a mean. For example, in a one-way model\[\mathrm{stdError} = \sqrt{\frac{s^2}{n}}\]where \(s^2\) is the estimate of \(\sigma^2\) and n is the number of responses in a sample mean. In models with random components, use
\[\mathrm{stdError} = \frac{\mathit{sedif}}{\sqrt{2}}\]where sedif is the estimated standard error of the difference of two means.
Return Value¶
The array of length nGroups
- 1 indicating the size of the groups of
means declared to be equal. Value equalMeans
[I
] = J
indicates
the I
-th smallest mean and the next J
- 1 larger means are declared
equal. Value equalMeans
[I
] = 0 indicates no group of means starts
with the I
-th smallest mean.
Optional Arguments¶
alpha
(Input)Significance level of test. Argument
alpha
must be in the interval [0.01, 0.10].Default:
alpha
= 0.01
snk
or
lsd
or
tukey
or
bonferroni
Argument | Method |
---|---|
snk |
Student-Newman-Keuls (default) |
lsd |
Least significant difference |
tukey |
Tukey’s w-procedure, also called the honestly significant difference procedure. |
bonferroni |
Bonferroni t statistic |
Description¶
Function multipleComparisons
performs a multiple comparison analysis of
means using one of Student-Newman-Keuls, LSD, Bonferroni, or Tukey’s
procedures. The null hypothesis is equality of all possible ordered subsets
of a set of means. The methods are discussed in many elementary statistics
texts, e.g., Kirk (1982, pp. 123–125).
The output consists of an array of nGroups
–1 integers that describe
grouping of means that are considered not statistically significantly
different.
For example, if nGroups
=4 and the returned array is equal to {0, 2, 2}
then we conclude that:
- The smallest mean is significantly different from the others.
- The second and third smallest means are not significantly different from one another.
- The second and fourth means are significantly different.
- The third and fourth means are not significantly different from one another.
These relationships can be depicted graphically as three groups of means:
Smallest Mean | Group 1 | Group 2 | Group 3 |
---|---|---|---|
1 | x | ||
2 | x | ||
3 | x | x | |
4 | x |
Examples¶
Example 1¶
A multiple-comparisons analysis is performed using data discussed by Kirk (1982, pp. 123-125). The results show that there are three groups of means with three separate sets of values: (36.7, 40.3, 43.4), (40.3, 43.4, 47.2), and (43.4, 47.2, 48.7).
In this case, the ordered means are {36.7, 40.3, 43.4, 47.2, 48.7} corresponding to treatments {1, 5, 3, 4, 2}. Since the output table is:
we can say that within each of these three groups, means are not significantly different from one another.
Treatment | Mean | Group 1 | Group 2 | Group 3 |
---|---|---|---|---|
1 | 36.7 | x | ||
5 | 40.3 | x | x | |
3 | 43.4 | x | x | x |
4 | 47.2 | x | x | |
2 | 48.7 | x |
from numpy import *
from pyimsl.stat.multipleComparisons import multipleComparisons
from pyimsl.stat.writeMatrix import writeMatrix
n_groups = 5
df = 45
std_error = 1.6970563
means = [36.7, 48.7, 43.4, 47.2, 40.3]
# Perform multiple comparisons tests
equal_means = multipleComparisons(means, df, std_error)
# Print results
writeMatrix("Size of Groups of Means", equal_means)
Output¶
Size of Groups of Means
1 2 3 4
3 3 3 0
Example 2¶
This example uses the same data as the previous example but also uses additional methods by specifying optional arguments.
Example 2 uses the same data as Example 1: Ordered treatment means correspond to treatment order {1,5,3,4,2}.
The table produced for Bonferroni is:
Thus, these are two groups of similar means.
Treatment | Mean | Group 1 | Group 2 |
---|---|---|---|
1 | 36.7 | x | |
5 | 40.3 | x | x |
3 | 43.4 | x | x |
4 | 47.2 | x | |
2 | 48.7 | x |
from numpy import *
from pyimsl.stat.multipleComparisons import multipleComparisons
from pyimsl.stat.writeMatrix import writeMatrix
n_groups = 5
df = 45
std_error = 1.6970563
means = [36.7, 48.7, 43.4, 47.2, 40.3]
# Student-Newman-Keuls
equal_means = multipleComparisons(means, df, std_error)
writeMatrix("SNK ", equal_means)
# Bonferroni
equal_means = multipleComparisons(means, df, std_error,
bonferroni=True)
writeMatrix("Bonferonni ", equal_means)
# Least Significant Difference
equal_means = multipleComparisons(means, df, std_error,
lsd=True)
writeMatrix("LSD ", equal_means)
# Tukey's
equal_means = multipleComparisons(means, df, std_error,
tukey=True)
writeMatrix("Tukey ", equal_means)
Output¶
SNK
1 2 3 4
3 3 3 0
Bonferonni
1 2 3 4
3 4 0 0
LSD
1 2 3 4
2 2 3 0
Tukey
1 2 3 4
3 3 3 0