PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_nonpar_test_cochranq (g08al)
Purpose
nag_nonpar_test_cochranq (g08al) performs the Cochran -test on cross-classified binary data.
Syntax
Note: the interface to this routine has changed since earlier releases of the toolbox:
At Mark 22: |
n was made optional |
Description
Cochran's -test may be used to test for differences between treatments applied independently to individuals or blocks ( related samples of equal size ), where the observed response can take only one of two possible values; for example a treatment may result in a ‘success’ or ‘failure’. The data is recorded as either or to represent this dichotomization.
The use of this ‘randomized block design’ allows the effect of differences between the blocks to be separated from the differences between the treatments. The test assumes that the blocks were randomly selected from all possible blocks and that the result may be one of two possible outcomes common to all treatments within blocks.
The null and alternative hypotheses to be tested may be stated as follows.
: | the treatments are equally effective, that is the probability of obtaining a within a block is the same for each treatment. |
: | there is a difference between the treatments, that is the probability of obtaining a is not the same for different treatments within blocks. |
The data is often represented in the form of a table with the
rows representing the blocks and the
columns the treatments. Let
represent the row totals, for
, and
represent the column totals, for
. Let
represent the response or result where
.
|
Treatments |
|
Blocks |
1 |
2 |
|
|
Row Totals |
1 |
|
|
|
|
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Column Totals |
|
|
|
|
|
If
, for
and
, then the hypotheses may be restated as follows
: | , for each . |
: | , for some and , and for some . |
The test statistic is defined as
When the number of blocks,
, is large relative to the number of treatments,
,
has an approximate
-distribution with
degrees of freedom. This is used to find the probability,
, of obtaining a statistic greater than or equal to the computed value of
. Thus
is the upper tail probability associated with the computed value of
, where the
-distribution is used to approximate the true distribution of
.
References
Conover W J (1980) Practical Nonparametric Statistics Wiley
Siegel S (1956) Non-parametric Statistics for the Behavioral Sciences McGraw–Hill
Parameters
Compulsory Input Parameters
- 1:
– double array
-
ldx, the first dimension of the array, must satisfy the constraint
.
The matrix of observed zero-one data.
must contain the value , for and .
Constraint:
or , for and .
Optional Input Parameters
- 1:
– int64int32nag_int scalar
-
Default:
the first dimension of the array
x.
, the number of blocks.
Constraint:
.
- 2:
– int64int32nag_int scalar
-
Default:
the second dimension of the array
x.
, the number of treatments.
Constraint:
.
Output Parameters
- 1:
– double scalar
-
The value of the Cochran -test statistic.
- 2:
– double scalar
-
The upper tail probability,
, associated with the Cochran
-test statistic, that is the probability of obtaining a value greater than or equal to the observed value (the output value of
q).
- 3:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Errors or warnings detected by the function:
Cases prefixed with W are classified as warnings and
do not generate an error of type NAG:error_n. See nag_issue_warnings.
-
-
On entry, | , |
or | , |
or | . |
-
-
On entry, | or for some and , and . |
- W
-
The approximation process used to calculate the tail probability has failed to converge. The result returned in
prob may still be a reasonable approximation.
-
An unexpected error has been triggered by this routine. Please
contact
NAG.
-
Your licence key may have expired or may not have been installed correctly.
-
Dynamic memory allocation failed.
Accuracy
The use of the -distribution as an approximation to the true distribution of the Cochran -test statistic improves as increases and as increases relative to . This approximation should be a reasonable one when the total number of observations left, after omitting those rows containing all or , is greater than about and the number of rows left is larger than .
Further Comments
None.
Example
The following example is taken from page 201 of
Conover (1980). The data represents the success of three basketball enthusiasts in predicting the outcome of
collegiate basketball games, selected at random, using
for successful prediction of the outcome and
for unsuccessful prediction. This data is read in and the Cochran
-test statistic and its corresponding upper tail probability are computed and printed.
Open in the MATLAB editor:
g08al_example
function g08al_example
fprintf('g08al example results\n\n');
x = [1, 1, 1;
1, 1, 1;
0, 1, 0;
1, 1, 0;
0, 0, 0;
1, 1, 1;
1, 1, 1;
1, 1, 0;
0, 0, 1;
0, 1, 0;
1, 1, 1;
1, 1, 1];
[ifail] = x04ca( ...
'General', 'Non-unit', x, 'Data matrix');
fprintf('\n');
[q, prob, ifail] = g08al(x);
fprintf('Cochrans Q test statistic = %10.4f\n', q);
fprintf('Degrees of freedom = %5d\n', size(x,2)-1);
fprintf('Upper-tail probability = %10.4f\n', prob);
g08al example results
Data matrix
1 2 3
1 1.0000 1.0000 1.0000
2 1.0000 1.0000 1.0000
3 0.0000 1.0000 0.0000
4 1.0000 1.0000 0.0000
5 0.0000 0.0000 0.0000
6 1.0000 1.0000 1.0000
7 1.0000 1.0000 1.0000
8 1.0000 1.0000 0.0000
9 0.0000 0.0000 1.0000
10 0.0000 1.0000 0.0000
11 1.0000 1.0000 1.0000
12 1.0000 1.0000 1.0000
Cochrans Q test statistic = 2.8000
Degrees of freedom = 2
Upper-tail probability = 0.2466
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015