# NAG Library Routine Document

## 1Purpose

g01emf returns the probability associated with the lower tail of the distribution of the Studentized range statistic, via the routine name.

## 2Specification

Fortran Interface
 Function g01emf ( q, v, ir,
 Real (Kind=nag_wp) :: g01emf Integer, Intent (In) :: ir Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: q, v
#include nagmk26.h
 double g01emf_ (const double *q, const double *v, const Integer *ir, Integer *ifail)

## 3Description

The externally Studentized range, $q$, for a sample, ${x}_{1},{x}_{2},\dots ,{x}_{r}$, is defined as:
 $q = max⁡xi - min⁡xi σ^e ,$
where ${\stackrel{^}{\sigma }}_{e}$ is an independent estimate of the standard error of the ${x}_{i}$'s. The most common use of this statistic is in the testing of means from a balanced design. In this case for a set of group means, ${\stackrel{-}{T}}_{1},{\stackrel{-}{T}}_{2},\dots ,{\stackrel{-}{T}}_{r}$, the Studentized range statistic is defined to be the difference between the largest and smallest means, ${\stackrel{-}{T}}_{\mathrm{largest}}$ and ${\stackrel{-}{T}}_{\mathrm{smallest}}$, divided by the square root of the mean-square experimental error, $M{S}_{\mathrm{error}}$, over the number of observations in each group, $n$, i.e.,
 $q=T-largest-T-smallest MSerror/n .$
The Studentized range statistic can be used as part of a multiple comparisons procedure such as the Newman–Keuls procedure or Duncan's multiple range test (see Montgomery (1984) and Winer (1970)).
For a Studentized range statistic the probability integral, $P\left(q;v,r\right)$, for $v$ degrees of freedom and $r$ groups can be written as:
 $Pq;v,r=C∫0∞xv-1e-vx2/2 r∫-∞∞ϕyΦy-Φy-qx r-1dydx,$
where
 $C=vv/2Γ v/22v/2- 1 , ϕ y=12π e-y2/2 and Φ y=∫-∞yϕ t dt.$
The above two-dimensional integral is evaluated using d01daf with the upper and lower limits computed to give stated accuracy (see Section 7).
If the degrees of freedom $v$ are greater than $2000$ the probability integral can be approximated by its asymptotic form:
 $Pq;r=r∫-∞∞ϕyΦy-Φy-q r-1dy.$
This integral is evaluated using d01amf.

## 4References

Abramowitz M and Stegun I A (1972) Handbook of Mathematical Functions (3rd Edition) Dover Publications
Lund R E and Lund J R (1983) Algorithm AS 190: probabilities and upper quartiles for the studentized range Appl. Statist. 32(2) 204–210
Montgomery D C (1984) Design and Analysis of Experiments Wiley
Winer B J (1970) Statistical Principles in Experimental Design McGraw–Hill

## 5Arguments

1:     $\mathbf{q}$ – Real (Kind=nag_wp)Input
On entry: $q$, the Studentized range statistic.
Constraint: ${\mathbf{q}}>0.0$.
2:     $\mathbf{v}$ – Real (Kind=nag_wp)Input
On entry: $v$, the number of degrees of freedom for the experimental error.
Constraint: ${\mathbf{v}}\ge 1.0$.
3:     $\mathbf{ir}$ – IntegerInput
On entry: $r$, the number of groups.
Constraint: ${\mathbf{ir}}\ge 2$.
4:     $\mathbf{ifail}$ – IntegerInput/Output
On entry: ifail must be set to $0$, $-1\text{​ 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\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, because for this routine the values of the output arguments may be useful even if ${\mathbf{ifail}}\ne {\mathbf{0}}$ on exit, the recommended value is $-1$. When the value $-\mathbf{1}\text{​ or ​}1$ is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).
If on exit ${\mathbf{ifail}}={\mathbf{1}}$, then g01emf returns to $0.0$.

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-1$, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Note: g01emf may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
${\mathbf{ifail}}=1$
On entry, ${\mathbf{ir}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ir}}\ge 2$.
On entry, ${\mathbf{q}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{q}}>0.0$.
On entry, ${\mathbf{v}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{v}}\ge 1.0$.
${\mathbf{ifail}}=2$
There is some doubt as to whether full accuracy has been achieved. The returned value should be a reasonable estimate of the true value.
${\mathbf{ifail}}=-99$
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{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.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

## 7Accuracy

The returned value will have absolute accuracy to at least four decimal places (usually five), unless ${\mathbf{ifail}}={\mathbf{2}}$. When ${\mathbf{ifail}}={\mathbf{2}}$ it is usual that the returned value will be a good estimate of the true value.

## 8Parallelism and Performance

g01emf is not threaded in any implementation.

None.

## 10Example

The lower tail probabilities for the distribution of the Studentized range statistic are computed and printed for a range of values of $q$, $\nu$ and $r$.

### 10.1Program Text

Program Text (g01emfe.f90)

### 10.2Program Data

Program Data (g01emfe.d)

### 10.3Program Results

Program Results (g01emfe.r)

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