nag_friedman_test (g08aec) (PDF version)
g08 Chapter Contents
g08 Chapter Introduction
NAG Library Manual

NAG Library Function Document

nag_friedman_test (g08aec)

 Contents

    1  Purpose
    7  Accuracy

1  Purpose

nag_friedman_test (g08aec) performs the Friedman two-way analysis of variance by ranks on k  related samples of size n .

2  Specification

#include <nag.h>
#include <nagg08.h>
void  nag_friedman_test (Integer k, Integer n, const double x[], Integer tdx, double *fr, double *p, NagError *fail)

3  Description

The Friedman test investigates the score differences between k  matched samples of size n , the scores in the i th sample being denoted by:
x i1 , x i2 , , x in .  
(Thus the sample scores may be regarded as a two-way table with k  rows and n  columns.) The hypothesis under test, H 0 , often called the null hypothesis, is that the samples come from the same population, and this is to be tested against the alternative hypothesis H 1  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, r ij  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 t i = j=1 n r ij , for i=1,2,,k.
(c) The Friedman test statistic FR  is computed, where
FR = 12 nk k+1 i=1 k t i - 1 2 n k+1 2 .  
nag_friedman_test (g08aec) returns the value of FR , and also an approximation, p , to the significance of this value. ( FR  approximately follows a χ k-1 2  distribution, so large values of FR  imply rejection of H 0 ). H 0  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., n of Siegel (1956)); for k=2  the Sign test (see nag_sign_test (g08aac)) or Wilcoxon test (see nag_wilcoxon_test (g08agc)) is in any case more appropriate.

4  References

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

5  Arguments

1:     k IntegerInput
On entry: k, the number of samples.
Constraint: k2.
2:     n IntegerInput
On entry: the size of each sample, n .
Constraint: n1 .
3:     x[k×tdx] const doubleInput
On entry: x[i-1×tdx+j-1]  must be set to the value, x ij , of observation j  in sample i , for i=1,2,,k and j=1,2,,n.
4:     tdx IntegerInput
On entry: the stride separating matrix column elements in the array x.
Constraint: tdxn .
5:     fr double *Output
On exit: the value of the Friedman test statistic, FR .
6:     p double *Output
On exit: the approximate significance, p , of the Friedman test statistic.
7:     fail NagError *Input/Output
The NAG error argument (see Section 2.7 in How to Use the NAG Library and its Documentation).

6  Error Indicators and Warnings

NE_2_INT_ARG_LT
On entry, tdx=value  while n=value . These arguments must satisfy tdxn .
NE_ALLOC_FAIL
Dynamic memory allocation failed.
NE_INT_ARG_LE
On entry, k=value.
Constraint: k2.
NE_INT_ARG_LT
On entry, n=value.
Constraint: n1.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.

7  Accuracy

For estimates of the accuracy of the significance p , see nag_prob_chi_sq (g01ecc). 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

nag_friedman_test (g08aec) is not threaded in any implementation.

9  Further Comments

The time taken by nag_friedman_test (g08aec) is approximately proportional to the product nk .
If k=2 , the Sign test (see nag_sign_test (g08aac)) or Wilcoxon test (see nag_wilcoxon_test (g08agc)) is more appropriate.

10  Example

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

10.1  Program Text

Program Text (g08aece.c)

10.2  Program Data

Program Data (g08aece.d)

10.3  Program Results

Program Results (g08aece.r)


nag_friedman_test (g08aec) (PDF version)
g08 Chapter Contents
g08 Chapter Introduction
NAG Library Manual

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