NAG Library Routine Document

g08aef (test_friedman)

1
Purpose

g08aef performs the Friedman two-way analysis of variance by ranks on k related samples of size n.

2
Specification

Fortran Interface
Subroutine g08aef ( x, ldx, k, n, w1, w2, fr, p, ifail)
Integer, Intent (In):: ldx, k, n
Integer, Intent (Inout):: ifail
Real (Kind=nag_wp), Intent (In):: x(ldx,n)
Real (Kind=nag_wp), Intent (Out):: w1(k), w2(k), fr, p
C Header Interface
#include <nagmk26.h>
void  g08aef_ (const double x[], const Integer *ldx, const Integer *k, const Integer *n, double w1[], double w2[], double *fr, double *p, Integer *ifail)

3
Description

The Friedman test investigates the score differences between k matched samples of size n, the scores in the ith sample being denoted by
xi1,xi2,,xin.  
(Thus the sample scores may be regarded as a two-way table with k rows and n columns.) The hypothesis under test, H0, often called the null hypothesis, is that the samples come from the same population, and this is to be tested against the alternative hypothesis H1 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
(a) The scores in each column are ranked, rij denoting the rank within column j of the observation in row i. Average ranks are assigned to tied scores.
(b) The ranks are summed over each row to give rank sums ti=j=1nrij, for i=1,2,,k.
(c) The Friedman test statistic F is computed, where
F=12nkk+1 i=1kti-12nk+12.  
g08aef returns the value of F, and also an approximation, p, to the significance of this value. (F approximately follows a χk-12 distribution, so large values of F imply rejection of H0). H0 is rejected by a test of chosen size α if p<α. The approximation p is acceptable unless k=4 and n<5, or k=3 and n<10, or k=2 and n<20; for k=3​ or ​4, tables should be consulted (e.g., Siegel (1956)); for k=2 the Sign test (see g08aaf) or Wilcoxon test (see g08agf) is in any case more appropriate.

4
References

Siegel S (1956) Non-parametric Statistics for the Behavioral Sciences McGraw–Hill

5
Arguments

1:     xldxn – Real (Kind=nag_wp) arrayInput
On entry: xij must be set to the value, xij, of observation j in sample i, for i=1,2,,k and j=1,2,,n.
2:     ldx – IntegerInput
On entry: the first dimension of the array x as declared in the (sub)program from which g08aef is called.
Constraint: ldxk.
3:     k – IntegerInput
On entry: k, the number of samples.
Constraint: k2.
4:     n – IntegerInput
On entry: n, the size of each sample.
Constraint: n1.
5:     w1k – Real (Kind=nag_wp) arrayWorkspace
6:     w2k – Real (Kind=nag_wp) arrayWorkspace
7:     fr – Real (Kind=nag_wp)Output
On exit: the value of the Friedman test statistic, F.
8:     p – Real (Kind=nag_wp)Output
On exit: the approximate significance, p, of the Friedman test statistic.
9:     ifail – IntegerInput/Output
On entry: ifail must be set to 0, -1 or 1. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation 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 argument, 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=value.
Constraint: n1.
ifail=2
On entry, ldx=value and k=value.
Constraint: ldxk.
ifail=3
On entry, k=value.
Constraint: k2.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
ifail=-399
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
ifail=-999
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

7
Accuracy

For estimates of the accuracy of the significance p, see g01ecf. The χ2 approximation is acceptable unless k=4 and n<5, or k=3 and n<10, or k=2 and n<20.

8
Parallelism and Performance

g08aef is not threaded in any implementation.

9
Further Comments

The time taken by g08aef is approximately proportional to the product nk.
If k=2, the Sign test (see g08aaf) or Wilcoxon test (see g08agf) is more appropriate.

10
Example

This example is taken from page 169 of Siegel (1956). The data relates to training scores of three matched samples of 18 rats, trained under three different patterns of reinforcement.

10.1
Program Text

Program Text (g08aefe.f90)

10.2
Program Data

Program Data (g08aefe.d)

10.3
Program Results

Program Results (g08aefe.r)