G08ALF (PDF version)
G08 Chapter Contents
G08 Chapter Introduction
NAG Library Manual

NAG Library Routine Document

G08ALF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

G08ALF performs the Cochran Q-test on cross-classified binary data.

2  Specification

SUBROUTINE G08ALF ( N, K, X, LDX, Q, PROB, IFAIL)
INTEGER  N, K, LDX, IFAIL
REAL (KIND=nag_wp)  X(LDX,K), Q, PROB

3  Description

Cochran's Q-test may be used to test for differences between k treatments applied independently to n individuals or blocks (k related samples of equal size n), 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 1 or 0 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.
H0 : the treatments are equally effective, that is the probability of obtaining a 1 within a block is the same for each treatment.
H1 : there is a difference between the treatments, that is the probability of obtaining a 1 is not the same for different treatments within blocks.
The data is often represented in the form of a table with the n rows representing the blocks and the k columns the treatments. Let Ri represent the row totals, for i=1,2,,n, and Cj represent the column totals, for j=1,2,,k. Let xij represent the response or result where xij=0​ or ​1.
  Treatments  
Blocks 1 2   k Row Totals
1 x11 x12 x1k R1
2 x21 x22 x2k R2
     
n xn1 xn2 xnk Rn
Column Totals C1 C2   Ck N=Grand Total
If pij=Prxij=1, for i=1,2,,n and j=1,2,,k, then the hypotheses may be restated as follows
H0 : pi1=pi2==pik, for each i=1,2,,n.
H1: pijpik, for some j and k, and for some i.
The test statistic is defined as
Q=kk-1j=1k Cj-Nk 2 i=1nRik-Ri .
When the number of blocks, n, is large relative to the number of treatments, k, Q has an approximate χ2-distribution with k-1 degrees of freedom. This is used to find the probability, p, of obtaining a statistic greater than or equal to the computed value of Q. Thus p is the upper tail probability associated with the computed value of Q, where the χ2-distribution is used to approximate the true distribution of Q.

4  References

Conover W J (1980) Practical Nonparametric Statistics Wiley
Siegel S (1956) Non-parametric Statistics for the Behavioral Sciences McGraw–Hill

5  Parameters

1:     N – INTEGERInput
On entry: n, the number of blocks.
Constraint: N2.
2:     K – INTEGERInput
On entry: k, the number of treatments.
Constraint: K2.
3:     X(LDX,K) – REAL (KIND=nag_wp) arrayInput
On entry: the matrix of observed zero-one data. Xij must contain the value xij, for i=1,2,,n and j=1,2,,k.
Constraint: Xij=0.0 or 1.0, for i=1,2,,n and j=1,2,,k.
4:     LDX – INTEGERInput
On entry: the first dimension of the array X as declared in the (sub)program from which G08ALF is called.
Constraint: LDXN.
5:     Q – REAL (KIND=nag_wp)Output
On exit: the value of the Cochran Q-test statistic.
6:     PROB – REAL (KIND=nag_wp)Output
On exit: the upper tail probability, p, associated with the Cochran Q-test statistic, that is the probability of obtaining a value greater than or equal to the observed value (the output value of Q).
7:     IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ or ​1. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ or ​1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is 0. When the value -1​ or ​1 is used it is essential to test the value of IFAIL on exit.
On exit: IFAIL=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6  Error Indicators and Warnings

If on entry IFAIL=0 or -1, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
IFAIL=1
On entry,N<2,
orK<2,
orLDX<N.
IFAIL=2
On entry,Xij0.0 or 1.0 for some i and j, i=1,2,,n and j=1,2,,k.
IFAIL=3
The approximation process used to calculate the tail probability has failed to converge. The result returned in PROB may still be a reasonable approximation.

7  Accuracy

The use of the χ2-distribution as an approximation to the true distribution of the Cochran Q-test statistic improves as k increases and as n increases relative to k. This approximation should be a reasonable one when the total number of observations left, after omitting those rows containing all 0 or 1, is greater than about 25 and the number of rows left is larger than 5.

8  Further Comments

None.

9  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 12 collegiate basketball games, selected at random, using 1 for successful prediction of the outcome and 0 for unsuccessful prediction. This data is read in and the Cochran Q-test statistic and its corresponding upper tail probability are computed and printed.

9.1  Program Text

Program Text (g08alfe.f90)

9.2  Program Data

Program Data (g08alfe.d)

9.3  Program Results

Program Results (g08alfe.r)


G08ALF (PDF version)
G08 Chapter Contents
G08 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2012