cochranQTest¶
Performs a Cochran Q test for related observations.
Synopsis¶
cochranQTest (x)
Required Arguments¶
- float
x[[]](Input) - Array of size
nObservations×nVariablescontaining the matrix of dichotomized data. There arenObservationsreadings of zero or one on each of thenVariablestreatments.
Return Value¶
The p-value, pValue, for the Cochran Q statistic.
Optional Arguments¶
qStatistic(Output)- Cochran’s Q statistic.
Description¶
Function cochranQTest computes the Cochran Q test statistic that may
be used to determine whether or not M matched sets of responses differ
significantly among themselves. The data may be thought of as arising out of
a randomized block design in which the outcome variable must be success or
failure, coded as 1.0 and 0.0, respectively. Within each block, a
multivariate vector of 1’s or 0’s is observed. The hypothesis is that the
probability of success within a block does not depend upon the treatment.
Assumptions¶
- The blocks are a random sample from the population of all possible blocks.
- The outcome of each treatment is dichotomous.
Hypothesis¶
The hypothesis being tested may be stated in at least two ways.
\(H_0\) : All treatments have the same effect.
\(H_1\) : The treatments do not all have the same effect.
Let \(p_{ij}\) denote the probability of outcome 1.0 in block i, treatment j.
\(H_0 : p_{i1}=p_{i2}=\ldots=p_{ic}\) for each i.
\(H_1 : p_{ij}\neq p_{ik}\) for some i, and some \(j\neq k\).
where c (equal to
nVariables) is the number of treatments.
The null hypothesis is rejected if Cochrans’s Q statistic is too large.
Remarks¶
- The input data must consist of zeros and ones only. For example, the data
may be pass-fail information on
nVariablesquestions asked ofnObservationspeople or the test responses ofnObservationsindividuals tonVariablesdifferent conditions. - The resulting statistic is distributed approximately as chi-squared with
nVariables− 1 degrees of freedom ifnObservationsis not too small.nObservationsgreater than or equal to 5 ×nVariablesis a conservative recommendation.
Example¶
The following example is taken from Siegal (1956, p. 164). It measures the responses of 18 women to 3 types of interviews.
from __future__ import print_function
from numpy import *
from pyimsl.stat.cochranQTest import cochranQTest
x = array([
[0.0, 0.0, 0.0],
[1.0, 1.0, 0.0],
[0.0, 1.0, 0.0],
[0.0, 0.0, 0.0],
[1.0, 0.0, 0.0],
[1.0, 1.0, 0.0],
[1.0, 1.0, 0.0],
[0.0, 1.0, 0.0],
[1.0, 0.0, 0.0],
[0.0, 0.0, 0.0],
[1.0, 1.0, 1.0],
[1.0, 1.0, 1.0],
[1.0, 1.0, 0.0],
[1.0, 1.0, 0.0],
[1.0, 1.0, 0.0],
[1.0, 1.0, 1.0],
[1.0, 1.0, 0.0],
[1.0, 1.0, 0.0]])
pq = cochranQTest(x)
print("pq = %9.5f" % pq)
Output¶
pq = 0.00024
Warning Errors¶
IMSLS_ALL_0_OR_1 |
“x” consists of either all ones or all
zeros. “q” is set to NaN (not a
number). “pq” is set to 1.0. |
Fatal Errors¶
IMSLS_INVALID_X_VALUES |
“x[#][#]” = #. “x” must consist
of zeros and ones only. |