NAG Library Routine Document
G04DBF
1 Purpose
G04DBF computes simultaneous confidence intervals for the differences between means. It is intended for use after
G04BBF or
G04BCF.
2 Specification
SUBROUTINE G04DBF ( 
TYP, NT, TMEAN, RDF, C, LDC, CLEVEL, CIL, CIU, ISIG, IFAIL) 
INTEGER 
NT, LDC, ISIG(NT*(NT1)/2), IFAIL 
REAL (KIND=nag_wp) 
TMEAN(NT), RDF, C(LDC,NT), CLEVEL, CIL(NT*(NT1)/2), CIU(NT*(NT1)/2) 
CHARACTER(1) 
TYP 

3 Description
In the computation of analysis of a designed experiment the first stage is to compute the basic analysis of variance table, the estimate of the error variance (the residual or error mean square), ${\hat{\sigma}}^{2}$, the residual degrees of freedom, $\nu $, and the (variance ratio) $F$statistic for the $t$ treatments. The second stage of the analysis is to compare the treatment means. If the treatments have no structure, for example the treatments are different varieties, rather than being structured, for example a set of different temperatures, then a multiple comparison procedure can be used.
A multiple comparison procedure looks at all possible pairs of means and either computes confidence intervals for the difference in means or performs a suitable test on the difference. If there are $t$ treatments then there are $t\left(t1\right)/2$ comparisons to be considered. In tests the type $1$ error or significance level is the probability that the result is considered to be significant when there is no difference in the means. If the usual $t$test is used with, say, a $6\%$ significance level then the type $1$ error for all $k=t\left(t1\right)/2$ tests will be much higher. If the tests were independent then if each test is carried out at the $100\alpha $ percent level then the overall type $1$ error would be ${\alpha}^{*}=1{\left(1\alpha \right)}^{k}\simeq k\alpha $. In order to provide an overall protection the individual tests, or confidence intervals, would have to be carried out at a value of $\alpha $ such that ${\alpha}^{*}$ is the required significance level, e.g., five percent.
The
$100\left(1\alpha \right)$ percent confidence interval for the difference in two treatment means,
${\hat{\tau}}_{i}$ and
${\hat{\tau}}_{j}$ is given by
where
$se\left(\right)$ denotes the standard error of the difference in means and
${T}_{\left(\alpha ,\nu ,t\right)}^{*}$ is an appropriate percentage point from a distribution. There are several possible choices for
${T}_{\left(\alpha ,\nu ,t\right)}^{*}$. These are:
(a) 
$\frac{1}{2}{q}_{\left(1\alpha ,\nu ,t\right)}$, the studentized range statistic, see G01FMF. It is the appropriate statistic to compare the largest mean with the smallest mean. This is known as Tukey–Kramer method. 
(b) 
${t}_{\left(\alpha /k,\nu \right)}$, this is the Bonferroni method. 
(c) 
${t}_{\left({\alpha}_{0},\nu \right)}$, where ${\alpha}_{0}=1{\left(1\alpha \right)}^{1/k}$, this is known as the Dunn–Sidak method. 
(d) 
${t}_{\left(\alpha ,\nu \right)}$, this is known as Fisher's LSD (least significant difference) method. It should only be used if the overall $F$test is significant, the number of treatment comparisons is small and were planned before the analysis. 
(e) 
$\sqrt{\left(k1\right){F}_{1\alpha ,k1,\nu}}$ where ${F}_{1\alpha ,k1,\nu}$ is the deviate corresponding to a lower tail probability of $1\alpha $ from an $F$distribution with $k1$ and $\nu $ degrees of freedom. This is Scheffe's method. 
In cases
(b),
(c) and
(d),
${t}_{\left(\alpha ,\nu \right)}$ denotes the
$\alpha $ two tail significance level for the Student's
$t$distribution with
$\nu $ degrees of freedom, see
G01FBF.
The Scheffe method is the most conservative, followed closely by the Dunn–Sidak and Tukey–Kramer methods.
To compute a test for the difference between two means the statistic,
is compared with the appropriate value of
${T}_{\left(\alpha ,\nu ,t\right)}^{*}$.
4 References
Kotz S and Johnson N L (ed.) (1985a) Multiple range and associated test procedures Encyclopedia of Statistical Sciences 5 Wiley, New York
Kotz S and Johnson N L (ed.) (1985b) Multiple comparison Encyclopedia of Statistical Sciences 5 Wiley, New York
Winer B J (1970) Statistical Principles in Experimental Design McGraw–Hill
5 Arguments
 1: $\mathrm{TYP}$ – CHARACTER(1)Input

On entry: indicates which method is to be used.
 ${\mathbf{TYP}}=\text{'T'}$
 The Tukey–Kramer method is used.
 ${\mathbf{TYP}}=\text{'B'}$
 The Bonferroni method is used.
 ${\mathbf{TYP}}=\text{'D'}$
 The Dunn–Sidak method is used.
 ${\mathbf{TYP}}=\text{'L'}$
 The Fisher LSD method is used.
 ${\mathbf{TYP}}=\text{'S'}$
 The Scheffe's method is used.
Constraint:
${\mathbf{TYP}}=\text{'T'}$, $\text{'B'}$, $\text{'D'}$, $\text{'L'}$ or $\text{'S'}$.
 2: $\mathrm{NT}$ – INTEGERInput

On entry: $t$, the number of treatment means.
Constraint:
${\mathbf{NT}}\ge 2$.
 3: $\mathrm{TMEAN}\left({\mathbf{NT}}\right)$ – REAL (KIND=nag_wp) arrayInput

On entry: the treatment means,
${\hat{\tau}}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,t$.
 4: $\mathrm{RDF}$ – REAL (KIND=nag_wp)Input

On entry: $\nu $, the residual degrees of freedom.
Constraint:
${\mathbf{RDF}}\ge 1.0$.
 5: $\mathrm{C}\left({\mathbf{LDC}},{\mathbf{NT}}\right)$ – REAL (KIND=nag_wp) arrayInput

On entry: the strictly lower triangular part of
C must contain the standard errors of the differences between the means as returned by
G04BBF and
G04BCF. That is
${\mathbf{C}}\left(i,j\right)$,
$i>j$, contains the standard error of the difference between the
$i$th and
$j$th mean in
TMEAN.
Constraint:
${\mathbf{C}}\left(\mathit{i},\mathit{j}\right)>0.0$, for $\mathit{i}=2,3,\dots ,t$ and $\mathit{j}=1,2,\dots ,\mathit{i}1$.
 6: $\mathrm{LDC}$ – INTEGERInput

On entry: the first dimension of the array
C as declared in the (sub)program from which G04DBF is called.
Constraint:
${\mathbf{LDC}}\ge {\mathbf{NT}}$.
 7: $\mathrm{CLEVEL}$ – REAL (KIND=nag_wp)Input

On entry: the required confidence level for the computed intervals, ($1\alpha $).
Constraint:
$0.0<{\mathbf{CLEVEL}}<1.0$.
 8: $\mathrm{CIL}\left({\mathbf{NT}}\times \left({\mathbf{NT}}1\right)/2\right)$ – REAL (KIND=nag_wp) arrayOutput

On exit: the
$\left(\left(\mathit{i}1\right)\left(\mathit{i}2\right)/2+\mathit{j}\right)$th element contains the lower limit to the confidence interval for the difference between
$\mathit{i}$th and
$\mathit{j}$th means in
TMEAN, for
$\mathit{i}=2,3,\dots ,t$ and
$\mathit{j}=1,2,\dots ,\mathit{i}1$.
 9: $\mathrm{CIU}\left({\mathbf{NT}}\times \left({\mathbf{NT}}1\right)/2\right)$ – REAL (KIND=nag_wp) arrayOutput

On exit: the
$\left(\left(\mathit{i}1\right)\left(\mathit{i}2\right)/2+\mathit{j}\right)$th element contains the upper limit to the confidence interval for the difference between
$\mathit{i}$th and
$\mathit{j}$th means in
TMEAN, for
$\mathit{i}=2,3,\dots ,t$ and
$\mathit{j}=1,2,\dots ,\mathit{i}1$.
 10: $\mathrm{ISIG}\left({\mathbf{NT}}\times \left({\mathbf{NT}}1\right)/2\right)$ – INTEGER arrayOutput

On exit: the
$\left(\left(\mathit{i}1\right)\left(\mathit{i}2\right)/2+\mathit{j}\right)$th element indicates if the difference between
$\mathit{i}$th and
$\mathit{j}$th means in
TMEAN is significant, for
$\mathit{i}=2,3,\dots ,t$ and
$\mathit{j}=1,2,\dots ,\mathit{i}1$. If the difference is significant then the returned value is
$1$; otherwise the returned value is
$0$.
 11: $\mathrm{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, if you are not familiar with this argument, the recommended value is
$0$.
When the value $\mathbf{1}\text{ or}\mathbf{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).
6 Error 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).
Errors or warnings detected by the routine:
 ${\mathbf{IFAIL}}=1$

On entry,  ${\mathbf{NT}}<2$, 
or  ${\mathbf{LDC}}<{\mathbf{NT}}$, 
or  ${\mathbf{RDF}}<1.0$, 
or  ${\mathbf{CLEVEL}}\le 0.0$, 
or  ${\mathbf{CLEVEL}}\ge 1.0$, 
or  ${\mathbf{TYP}}\ne \text{'T'}$, $\text{'B'}$, $\text{'D'}$, $\text{'L'}$ or $\text{'S'}$. 
 ${\mathbf{IFAIL}}=2$

On entry,  ${\mathbf{C}}\left(i,j\right)\le 0.0$ for some $i,j$, $i=2,3,\dots ,t$ and $j=1,2,\dots ,i1$. 
 ${\mathbf{IFAIL}}=3$

There has been a failure in the computation of the studentized range statistic. This is an unlikely error. Try using a small value of
CLEVEL.
 ${\mathbf{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.
 ${\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.
7 Accuracy
For the accuracy of the percentage point statistics see
G01FBF and
G01FMF.
8 Parallelism and Performance
G04DBF is not threaded in any implementation.
If the treatments have a structure then the use of linear contrasts as computed by
G04DAF may be more appropriate.
An alternative approach to one used in G04DBF is the sequential testing of the Student–Newman–Keuls procedure. This, in effect, uses the Tukey–Kramer method but first ordering the treatment means and examining only subsets of the treatment means in which the largest and smallest are significantly different. At each stage the third argument of the Studentized range statistic is the number of means in the subset rather than the total number of means.
10 Example
In the example taken from
Winer (1970) a completely randomized design with unequal treatment replication is analysed using
G04BBF and then confidence intervals are computed by G04DBF using the Tukey–Kramer method.
10.1 Program Text
Program Text (g04dbfe.f90)
10.2 Program Data
Program Data (g04dbfe.d)
10.3 Program Results
Program Results (g04dbfe.r)