NAG Library Routine Document
G08AEF performs the Friedman two-way analysis of variance by ranks on related samples of size .
||LDX, K, N, IFAIL
||X(LDX,N), W1(K), W2(K), FR, P
The Friedman test investigates the score differences between
matched samples of size
, the scores in the
th sample being denoted by
(Thus the sample scores may be regarded as a two-way table with
columns.) The hypothesis under test,
, often called the null hypothesis, is that the samples come from the same population, and this is to be tested against the alternative hypothesis
that they come from different populations.
The test is based on the observed distribution of score rankings between the matched observations in different samples.
The test proceeds as follows
||The scores in each column are ranked, denoting the rank within column of the observation in row . Average ranks are assigned to tied scores.
||The ranks are summed over each row to give rank sums , for .
||The Friedman test statistic is computed, where
G08AEF returns the value of
, and also an approximation,
, to the significance of this value. (
approximately follows a
distribution, so large values of
imply rejection of
is rejected by a test of chosen size
. The approximation
is acceptable unless
, tables should be consulted (e.g., Siegel (1956)
the Sign test (see G08AAF
) or Wilcoxon test (see G08AGF
) is in any case more appropriate.
Siegel S (1956) Non-parametric Statistics for the Behavioral Sciences McGraw–Hill
- 1: X(LDX,N) – REAL (KIND=nag_wp) arrayInput
On entry: must be set to the value, , of observation in sample , for and .
- 2: LDX – INTEGERInput
: the first dimension of the array X
as declared in the (sub)program from which G08AEF is called.
- 3: K – INTEGERInput
On entry: , the number of samples.
- 4: N – INTEGERInput
On entry: , the size of each sample.
- 5: W1(K) – REAL (KIND=nag_wp) arrayWorkspace
- 6: W2(K) – REAL (KIND=nag_wp) arrayWorkspace
- 7: FR – REAL (KIND=nag_wp)Output
On exit: the value of the Friedman test statistic, .
- 8: P – REAL (KIND=nag_wp)Output
On exit: the approximate significance, , of the Friedman test statistic.
- 9: IFAIL – INTEGERInput/Output
must be set to
. 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
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is
. When the value is used it is essential to test the value of IFAIL on exit.
unless the routine detects an error or a warning has been flagged (see Section 6
6 Error Indicators and Warnings
If on entry
, explanatory error messages are output on the current error message unit (as defined by X04AAF
Errors or warnings detected by the routine:
For estimates of the accuracy of the significance
, see G01ECF
approximation is acceptable unless
The time taken by G08AEF is approximately proportional to the product .
, the Sign test (see G08AAF
) or Wilcoxon test (see G08AGF
) is more appropriate.
This example is taken from page 169 of Siegel (1956)
. The data relates to training scores of three matched samples of
rats, trained under three different patterns of reinforcement.
9.1 Program Text
Program Text (g08aefe.f90)
9.2 Program Data
Program Data (g08aefe.d)
9.3 Program Results
Program Results (g08aefe.r)