NAG Library Routine Document
G04DAF
1 Purpose
G04DAF computes sum of squares for a user-defined contrast between means.
2 Specification
SUBROUTINE G04DAF ( |
NT, TMEAN, IREP, RMS, RDF, NC, CT, LDCT, EST, TABL, LDTABL, TOL, USETX, TX, IFAIL) |
INTEGER |
NT, IREP(NT), NC, LDCT, LDTABL, IFAIL |
REAL (KIND=nag_wp) |
TMEAN(NT), RMS, RDF, CT(LDCT,NC), EST(NC), TABL(LDTABL,*), TOL, TX(NT) |
LOGICAL |
USETX |
|
3 Description
In the analysis of designed experiments the first stage is to compute the basic analysis of variance table, the estimate of the error variance (the residual or error mean square), , and the (variance ratio) -statistic for the treatments. If this -test is significant then the second stage of the analysis is to explore which treatments are significantly different.
If there is a structure to the treatments then this may lead to hypotheses that can be defined before the analysis and tested using linear contrasts. For example, if the treatments were three different fixed temperatures, say
,
and
, and an uncontrolled temperature (denoted by
) then the following contrasts might be of interest.
The first represents the average difference between the controlled temperatures and the uncontrolled temperature. The second represents the linear effect of an increasing fixed temperature.
For a randomized complete block design or a completely randomized design, let the treatment means be
,
, and let the
th contrast be defined by
,
, then the estimate of the contrast is simply:
and the sum of squares for the contrast is:
where
is the number of observations for the
th treatment. Such a contrast has one degree of freedom so that the appropriate
-statistic is
.
The two contrasts and are orthogonal if and the contrast is orthogonal to the overall mean if . In practice these sums will be tested against a small quantity, . If each of a set of contrasts is orthogonal to the mean and they are all mutually orthogonal then the contrasts provide a partition of the treatment sum of squares into independent components. Hence the resulting -tests are independent.
If the treatments come from a design in which treatments are not orthogonal to blocks then the sum of squares for a contrast is given by:
where
with
, for
, being adjusted treatment means computed by first eliminating blocks then computing the treatment means from the block adjusted observations without taking into account the non-orthogonality between treatments and blocks. For further details see
John (1987).
4 References
Cochran W G and Cox G M (1957) Experimental Designs Wiley
John J A (1987) Cyclic Designs Chapman and Hall
Winer B J (1970) Statistical Principles in Experimental Design McGraw–Hill
5 Parameters
- 1: – INTEGERInput
-
On entry: , the number of treatment means.
Constraint:
.
- 2: – REAL (KIND=nag_wp) arrayInput
-
On entry: the treatment means,
, for .
- 3: – INTEGER arrayInput
-
On entry: the replication for each treatment mean,
, for .
- 4: – REAL (KIND=nag_wp)Input
-
On entry: the residual mean square, .
Constraint:
.
- 5: – REAL (KIND=nag_wp)Input
-
On entry: the residual degrees of freedom.
Constraint:
.
- 6: – INTEGERInput
-
On entry: the number of contrasts.
Constraint:
.
- 7: – REAL (KIND=nag_wp) arrayInput
-
On entry: the columns of
CT must contain the
NC contrasts, that is
must contain
, for
and
.
- 8: – INTEGERInput
-
On entry: the first dimension of the array
CT as declared in the (sub)program from which G04DAF is called.
Constraint:
.
- 9: – REAL (KIND=nag_wp) arrayOutput
-
On exit: the estimates of the contrast,
, for .
- 10: – REAL (KIND=nag_wp) arrayInput/Output
-
Note: the second dimension of the array
TABL
must be at least
.
On entry: the elements of
TABL that are not referenced as described below remain unchanged.
On exit: the rows of the analysis of variance table for the contrasts. For each row column 1 contains the degrees of freedom, column 2 contains the sum of squares, column 3 contains the mean square, column 4 the -statistic and column 5 the significance level for the contrast. Note that the degrees of freedom are always one and so the mean square equals the sum of squares.
- 11: – INTEGERInput
-
On entry: the first dimension of the array
TABL as declared in the (sub)program from which G04DAF is called.
Constraint:
.
- 12: – REAL (KIND=nag_wp)Input
-
On entry: the tolerance, used to check if the contrasts are orthogonal and if they are orthogonal to the mean. If the value machine precision is used.
- 13: – LOGICALInput
-
On entry: if
the means
are provided in
TX and the formula
(2) is used instead of formula
(1).
If
formula
(1) is used and
TX is not referenced.
- 14: – REAL (KIND=nag_wp) arrayInput
-
On entry: if
TX must contain the means
, for
.
- 15: – INTEGERInput/Output
-
On entry:
IFAIL 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, because for this routine the values of the output parameters may be useful even if
on exit, the recommended value is
.
When the value is used it is essential to test the value of IFAIL on exit.
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
or
, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
Note: G04DAF may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
-
On entry, | , |
or | , |
or | , |
or | , |
or | , |
or | . |
-
On entry, | a contrast is not orthogonal to the mean, |
or | at least two contrasts are not orthogonal. |
If full results are returned but they should be interpreted with care.
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 3.8 in the Essential Introduction for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 3.7 in the Essential Introduction for further information.
Dynamic memory allocation failed.
See
Section 3.6 in the Essential Introduction for further information.
7 Accuracy
The computations are stable.
8 Parallelism and Performance
Not applicable.
If the treatments have a factorial structure
G04CAF should be used and if the treatments have no structure the means can be compared using
G04DBF.
10 Example
The data is from a completely randomized experiment on potato scab with seven treatments representing amounts of sulphur applied, whether the application was in spring or autumn and a control treatment. The one-way anova is computed using
G02BBF. Two contrasts are analysed, one comparing the control with use of sulphur, the other comparing spring with autumn application.
10.1 Program Text
Program Text (g04dafe.f90)
10.2 Program Data
Program Data (g04dafe.d)
10.3 Program Results
Program Results (g04dafe.r)