G04BBF (PDF version)
G04 Chapter Contents
G04 Chapter Introduction
NAG Library Manual

NAG Library Routine Document

G04BBF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

G04BBF computes the analysis of variance and treatment means and standard errors for a randomized block or completely randomized design.

2  Specification

SUBROUTINE G04BBF ( N, Y, IBLOCK, NT, IT, GMEAN, BMEAN, TMEAN, TABL, LDTABL, C, LDC, IREP, R, EF, TOL, IRDF, WK, IFAIL)
INTEGER  N, IBLOCK, NT, IT(*), LDTABL, LDC, IREP(NT), IRDF, IFAIL
REAL (KIND=nag_wp)  Y(N), GMEAN, BMEAN(abs(IBLOCK)), TMEAN(NT), TABL(LDTABL,5), C(LDC,NT), R(N), EF(NT), TOL, WK(3*NT)

3  Description

In a completely randomized design, experimental material is divided into a number of units, or plots, to which a treatment can be applied. In a randomized block design the units are grouped into blocks so that the variation within blocks is less than the variation between blocks. If every treatment is applied to one plot in each block it is a complete block design. If there are fewer plots per block than treatments then the design will be an incomplete block design and may be balanced or partially balanced.
For a completely randomized design, with t treatments and nt plots per treatment, the linear model is
yij = μ + τj + eij ,   j=1,2,,t ​ and ​ i=1,2,,nj ,
where yij is the ith observation for the jth treatment, μ is the overall mean, τj is the effect of the jth treatment and eij is the random error term. For a randomized block design, with t treatments and b blocks of k plots, the linear model is
yijl = μ + βi + τl + eij ,   i=1,2,,b , ​ j=1,2,,k ​ and ​ l=1,2,,t ,
where βi is the effect of the ith block and the ijl notation indicates that the lth treatment is applied to the jth plot in the ith block.
The completely randomized design gives rise to a one-way analysis of variance. The treatments do not have to be equally replicated, i.e., do not have to occur the same number of times. First the overall mean, μ^, is computed and subtracted from the observations to give yij=yij-μ^. The estimated treatment effects, τ^j are then computed as the treatment means of the mean adjusted observations, yij, and the treatment sum of squares can be computed from the sum of squares of the treatment totals of the yij divided by the number of observations per treatment total, nj. The final residuals are computed as rij=yij-τ^j, and, from the residuals, the residual sum of squares is calculated.
For the randomized block design the mean is computed and subtracted from the observations to give yijl=yijl-μ^. The estimated block effects, ignoring treatment effects, β^i, are then computed using the block means of the yijl and the unadjusted sum of squares computed as the sum of squared block totals for the yijl divided by number of plots per block, k. The block adjusted observations are then computed as yijl =yijl=β^i. In the case of the complete block design, with the same replication for each treatment within each block, the blocks and treatments are orthogonal, and so the treatment effects are estimated as the treatment means of the block adjusted observations, yijl . The treatment sum of squares is computed as the sum of squared treatment totals of the yijl  divided by the number of replicates to the treatments, r=bk/t. Finally the residuals, and hence the residual sum of squares, are given by rijl=yijl -τ^l.
For a design without the same replication for each treatment within each block the treatments and the blocks will not be orthogonal, so the treatments adjusted for blocks need to be computed. The adjusted treatment effects are found as the solution to the equations
R-NNT/kτ^=q,
where q is the vector of the treatment totals for block adjusted observations, yijl , R is a diagonal matrix with Rll equal to the number of times the lth treatment is replicated, and N is the t by b incidence matrix, with Nlj equal to the number of times treatment l occurs in block j. The solution to the equations can be written as
τ^=Ωq
where Ω is a generalized inverse of R-NNT/k. The solution is found from the eigenvalue decomposition of R-NNT/k. The residuals are first calculated by subtracting the estimated treatment effects from the block adjusted observations to give rijl=yijl -τ^l. However, since only the unadjusted block effects have been removed and blocks and treatments are not orthogonal, the block means of the rijl have to be subtracted to give the correct residuals, rijl and residual sum of squares.
The mean squares are computed as the sum of squares divided by the degrees of freedom. The degrees of freedom for the unadjusted blocks is b-1, for the completely randomized and the complete block designs the degrees of freedom for the treatments is t-1. In the general case the degrees of freedom for treatments is the rank of the matrix Ω. The F-statistic given by the ratio of the treatment mean square to the residual mean square tests the hypothesis
H0:τ1=τ2==τt=0.
The standard errors for the difference in treatment effects, or treatment means, for the completely randomized or the complete block designs, are given by:
seτj-τj*=1nj+1nj* s2
where s2 is the residual mean square and nj=nj*=b in the complete block design. In the general case the variances of the treatment effects are given by
varτ=Ωs2
from which the appropriate standard errors of the difference between treatment effects or the difference between adjusted means can be calculated.
In the complete block design all the information on the treatment effects is given by the within block analysis. In other designs there may be a loss of information due to the non-orthogonality of treatments and blocks. The efficiency of the within block analysis in these cases is given by the (canonical) efficiency factors, these are the nonzero eigenvalues of the matrix R-NNT/k, divided by the number of replicates in the case of equal replication, or by the mean of the number of replicates in the unequally replicated case, see John (1987). If more than one eigenvalue is zero then the design is said to be disconnected and some treatments can only be compared using a between block analysis.

4  References

Cochran W G and Cox G M (1957) Experimental Designs Wiley
Davis O L (1978) The Design and Analysis of Industrial Experiments Longman
John J A (1987) Cyclic Designs Chapman and Hall
John J A and Quenouille M H (1977) Experiments: Design and Analysis Griffin
Searle S R (1971) Linear Models Wiley

5  Parameters

1:     N – INTEGERInput
On entry: the number of observations.
Constraint: N2 and if absIBLOCK2, N must be a multiple of absIBLOCK.
2:     Y(N) – REAL (KIND=nag_wp) arrayInput
On entry: the observations in the order as described by IBLOCK and NT.
3:     IBLOCK – INTEGERInput
On entry: indicates the block structure.
absIBLOCK1
There are no blocks, i.e., it is a completely randomized design.
IBLOCK2
There are IBLOCK blocks and the data should be input by blocks, i.e., Y must contain the observations for block 1 followed by the observations for block 2, etc.
IBLOCK-2
There are absIBLOCK blocks and the data is input in parallel with respect to blocks, i.e., Y1 must contain the first observation for block 1, Y2 must contain the first observation for block 2YabsIBLOCK must contain the first observation for block absIBLOCK,YabsIBLOCK+1 must contain the second observation for block 1, etc.
Constraint: IBLOCK=1, 2 or -2.
4:     NT – INTEGERInput
On entry: the number of treatments. If only blocks are required in the analysis then set NT=1.
Constraints:
  • if absIBLOCK2, NT1;
  • otherwise NT2.
5:     IT(*) – INTEGER arrayInput
Note: the dimension of the array IT must be at least N if NT2, and at least 1 otherwise.
On entry: ITi indicates which of the NT treatments plot i received, for i=1,2,,N.
If NT=1, IT is not referenced.
Constraint: 1ITiNT, for i=1,2,,N.
6:     GMEAN – REAL (KIND=nag_wp)Output
On exit: the grand mean, μ^.
7:     BMEAN(absIBLOCK) – REAL (KIND=nag_wp) arrayOutput
On exit: if absIBLOCK2, BMEANj contains the mean for the jth block, β^j, for j=1,2,,b.
8:     TMEAN(NT) – REAL (KIND=nag_wp) arrayOutput
On exit: if NT2, TMEANl contains the (adjusted) mean for the lth treatment, μ^*+τ^l, for l=1,2,,t, where μ^* is the mean of the treatment adjusted observations, yijl-τ^l.
9:     TABL(LDTABL,5) – REAL (KIND=nag_wp) arrayOutput
On exit: the analysis of variance table. Column 1 contains the degrees of freedom, column 2 the sum of squares, and where appropriate, column 3 the mean squares, column 4 the F-statistic and column 5 the significance level of the F-statistic. Row 1 is for Blocks, row 2 for Treatments, row 3 for Residual and row 4 for Total. Mean squares are computed for all but the Total row; F-statistics and significance are computed for Treatments and Blocks, if present. Any unfilled cells are set to zero.
10:   LDTABL – INTEGERInput
On entry: the first dimension of the array TABL as declared in the (sub)program from which G04BBF is called.
Constraint: LDTABL4.
11:   C(LDC,NT) – REAL (KIND=nag_wp) arrayOutput
On exit: if NT2, the upper triangular part of C contains the variance-covariance matrix of the treatment effects, the strictly lower triangular part contains the standard errors of the difference between two treatment effects (means), i.e., Cij contains the covariance of treatment i and j if ji and the standard error of the difference between treatment i and j if j<i, for i=1,2,,t and j=1,2,,t.
12:   LDC – INTEGERInput
On entry: the first dimension of the array C as declared in the (sub)program from which G04BBF is called.
Constraint: LDCNT.
13:   IREP(NT) – INTEGER arrayOutput
On exit: if NT2, the treatment replications, Rll, for l=1,2,,NT.
14:   R(N) – REAL (KIND=nag_wp) arrayOutput
On exit: the residuals, ri, for i=1,2,,N.
15:   EF(NT) – REAL (KIND=nag_wp) arrayOutput
On exit: if NT2, the canonical efficiency factors.
16:   TOL – REAL (KIND=nag_wp)Input
On entry: the tolerance value used to check for zero eigenvalues of the matrix Ω. If TOL=0.0 a default value of 10-5 is used.
Constraint: TOL0.0.
17:   IRDF – INTEGERInput
On entry: an adjustment to the degrees of freedom for the residual and total.
IRDF1
The degrees of freedom for the total is set to N-IRDF and the residual degrees of freedom adjusted accordingly.
IRDF=0
The total degrees of freedom for the total is set to N-1, as usual.
Constraint: IRDF0.
18:   WK(3×NT) – REAL (KIND=nag_wp) arrayWorkspace
19:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ or ​1. 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 -1​ 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 parameters may be useful even if IFAIL0 on exit, the recommended value is -1. 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).
Note: G04BBF may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
IFAIL=1
On entry,N<2,
orNT0,
orNT=1 and absIBLOCK1,
orLDTABL<4,
orLDC<NT,
orTOL<0.0,
orIRDF<0.
IFAIL=2
On entry,absIBLOCK2 and N is not a multiple of absIBLOCK.
IFAIL=3
On entry,ITi<1 or ITi>NT for some i when NT2,
orno value of IT=j for some j=1,2,,NT, when NT2.
IFAIL=4
On entry,the values of Y are constant.
IFAIL=5
A computed standard error is zero due to rounding errors, or the eigenvalue computation failed to converge. Both are unlikely error exits.
IFAIL=6
The treatments are totally confounded with blocks, so the treatment sum of squares and degrees of freedom are zero. The analysis of variance table is not computed, except for block and total sums of squares and degrees of freedom.
IFAIL=7
The residual degrees of freedom or the residual sum of squares are zero, columns 3, 4 and 5 of the analysis of variance table will not be computed and the matrix of standard errors and covariances, C, will not be scaled by s or s2.
IFAIL=8
The design is disconnected; the standard errors may not be valid. The design may be nested.

7  Accuracy

The algorithm used by G04BBF, described in Section 3, achieves greater accuracy than the traditional algorithms based on the subtraction of sums of squares.

8  Further Comments

To estimate missing values the Healy and Westmacott procedure or its derivatives may be used, see John and Quenouille (1977). This is an iterative procedure in which estimates of the missing values are adjusted by subtracting the corresponding values of the residuals. The new estimates are then used in the analysis of variance. This process is repeated until convergence. A suitable initial value may be the grand mean μ^. When using this procedure IRDF should be set to the number of missing values plus one to obtain the correct degrees of freedom for the residual sum of squares.
For designs such as Graeco–Latin squares one or more of the blocking factors has to be removed in a preliminary analysis before the final analysis using calls to G04BBF or G04BCF. The residuals from the preliminary analysis are then input to G04BBF. In these cases IRDF should be set to the difference between N and the residual degrees of freedom from preliminary analysis. Care should be taken when using this approach as there is no check on the orthogonality of the two analyses.
For analysis of covariance the residuals are obtained from an analysis of variance of both the response variable and the covariates. The residuals from the response variable are then regressed on the residuals from the covariates using, say, G02CBF or G02DAF. The results from those routines can be used to test for the significance of the covariates. To test the significance of the treatment effects after fitting the covariate, the residual sum of squares from the regression should be compared with the residual sum of squares obtained from the equivalent regression but using the residuals from fitting blocks only.

9  Example

The data, given by John and Quenouille (1977), are for a balanced incomplete block design with 10 blocks and 6 treatments and with 3 plots per block. The observations are the degree of pain experienced and the treatments are penicillin of different potency. The data is input and the analysis of variance table and treatment means are printed.

9.1  Program Text

Program Text (g04bbfe.f90)

9.2  Program Data

Program Data (g04bbfe.d)

9.3  Program Results

Program Results (g04bbfe.r)


G04BBF (PDF version)
G04 Chapter Contents
G04 Chapter Introduction
NAG Library Manual

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