The routine may be called by the names g04bcf or nagf_anova_rowcol.
3Description
In a row and column design the experimental material can be characterised by a two-way classification, nominally called rows and columns. Each experimental unit can be considered as being located in a particular row and column. It is assumed that all rows are of the same length and all columns are of the same length. Sets of equal numbers of rows/columns can be grouped together to form replicates, sometimes known as squares or rectangles, as appropriate.
If for a replicate, the number of rows, the number of columns and the number of treatments are equal and every treatment occurs once in each row and each column then the design is a Latin square. If this is not the case the treatments will be non-orthogonal to rows and columns. For example in the case of a lattice square each treatment occurs only once in each square.
For a row and column design, with $t$ treatments in $r$ rows and $c$ columns and $b$ replicates or squares with $n=brc$ observations the linear model is:
for $i=1,2\dots ,b$, $j=1,2,\dots ,r$, $k=1,2\dots ,c$ and $l=1,2,\dots ,t$, where ${\beta}_{i}$ is the effect of the $i$th replicate, ${\rho}_{j}$ is the effect of the $j$th row, ${\gamma}_{k}$ is the effect of the $k$th column and the $ijk\left(l\right)$ notation indicates that the $l$th treatment is applied to the unit in row $j$, column $k$ of replicate $i$.
To compute the analysis of variance for a row and column design the mean is computed and subtracted from the observations to give, ${y}_{ijk\left(l\right)}^{\prime}={y}_{ijk\left(l\right)}-\hat{\mu}$. Since the replicates, rows and columns are orthogonal the estimated effects, ignoring treatment effects, ${\hat{\beta}}_{i}$, ${\hat{\rho}}_{j}$, ${\hat{\gamma}}_{k}$, can be computed using the appropriate means of the ${y}_{ijk\left(l\right)}^{\prime}$, and the unadjusted sum of squares computed as the appropriate sum of squared totals for the ${y}_{ijk\left(l\right)}^{\prime}$ divided by number of units per total. The observations adjusted for replicates, rows and columns can then be computed by subtracting the estimated effects from ${y}_{ijk\left(l\right)}^{\prime}$ to give ${y}_{ijk\left(l\right)}^{\prime \prime}$.
In the case of a Latin square design the treatments are orthogonal to replicates, rows and columns and so the treatment effects, ${\hat{\tau}}_{l}$, can be estimated as the treatment means of the adjusted observations, ${y}_{ijk\left(l\right)}^{\prime \prime}$. The treatment sum of squares is computed as the sum of squared treatment totals of the ${y}_{ij\left(l\right)}^{\prime \prime}$ divided by the number of times each treatment is replicated. Finally the residuals, and hence the residual sum of squares, are given by ${r}_{ij\left(l\right)}={y}_{ij\left(l\right)}^{\prime \prime}-{\hat{\tau}}_{l}$.
For a design which is not orthogonal, for example a lattice square or an incomplete Latin square, the treatment effects adjusted for replicates, rows and columns need to be computed. The adjusted treatment effects are found as the solution to the equations:
where $q$ is the vector of the treatment totals of the observations adjusted for replicates, rows and columns, ${y}_{ijk\left(l\right)}^{\prime \prime}$, $R$ is a diagonal matrix with ${R}_{ll}$ equal to the number of times the $l$th treatment is replicated, and ${N}_{b}$ is the $t\times b$ incidence matrix, with ${N}_{l,i}$ equal to the number of times treatment $l$ occurs in replicate $i$, with ${N}_{r}$ and ${N}_{c}$ being similarly defined for rows and columns. The solution to the equations can be written as:
$$\hat{\tau}=\Omega q$$
where, $\Omega $ is a generalized inverse of $A$. The solution is found from the eigenvalue decomposition of $A$. The residuals are first calculated by subtracting the estimated adjusted treatment effects from the adjusted observations to give ${r}_{ij\left(l\right)}^{\prime}={y}_{ij\left(l\right)}^{\prime \prime}-{\hat{\tau}}_{l}$. However, since only the unadjusted replicate, row and column effects have been removed and they are not orthogonal to treatments, the replicate, row and column means of the ${r}_{ij\left(l\right)}^{\prime}$ have to be subtracted to give the correct residuals, ${r}_{ij\left(l\right)}$ and residual sum of squares.
Given the sums of squares, the mean squares are computed as the sums of squares divided by the degrees of freedom. The degrees of freedom for the unadjusted replicates, rows and columns are $b-1$, $r-1$ and $c-1$ respectively and for the Latin square 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 $\Omega $. The $F$-statistic given by the ratio of the treatment mean square to the residual mean square tests the hypothesis:
from which the appropriate standard errors of the difference between treatment effects or the difference between adjusted means can be calculated.
The analysis of a row-column design can be considered as consisting of different strata: the replicate stratum, the rows within replicate and the columns within replicate strata and the units stratum. In the Latin square design all the information on the treatment effects is given at the units stratum. In other designs there may be a loss of information due to the non-orthogonality of treatments and replicates, rows and columns and information on treatments may be available in higher strata. The efficiency of the estimation at the units stratum is given by the (canonical) efficiency factors, these are the nonzero eigenvalues of the matrix, $A$, 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 information on some treatment comparisons can only be obtained from higher strata.
4References
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
5Arguments
1: $\mathbf{nrep}$ – IntegerInput
On entry: $b$, the number of replicates.
Constraint:
${\mathbf{nrep}}\ge 1$.
2: $\mathbf{nrow}$ – IntegerInput
On entry: $r$, the number of rows per replicate.
Constraint:
${\mathbf{nrow}}\ge 2$.
3: $\mathbf{ncol}$ – IntegerInput
On entry: $c$, the number of columns per replicate.
Constraint:
${\mathbf{ncol}}\ge 2$.
4: $\mathbf{y}\left({\mathbf{nrep}}\times {\mathbf{nrow}}\times {\mathbf{ncol}}\right)$ – Real (Kind=nag_wp) arrayInput
On entry: the $n=brc$ observations ordered by columns within rows within replicates. That is
${\mathbf{y}}\left(rc(\mathit{i}-1)+r(\mathit{j}-1)+\mathit{k}\right)$ contains the observation from the $\mathit{k}$th column of the $\mathit{j}$th row of the $\mathit{i}$th replicate, for $\mathit{i}=1,2,\dots ,b$, $\mathit{j}=1,2,\dots ,r$ and $\mathit{k}=1,2,\dots ,c$.
5: $\mathbf{nt}$ – IntegerInput
On entry: the number of treatments. If only replicates, rows and columns are required in the analysis then set ${\mathbf{nt}}=1$.
Note: the dimension of the array it
must be at least
${\mathbf{nrep}}\times {\mathbf{nrow}}\times {\mathbf{ncol}}$ if ${\mathbf{nt}}>1$, and at least $1$ otherwise.
On entry: if ${\mathbf{nt}}>1$,
${\mathbf{it}}\left(\mathit{i}\right)$ indicates which of the nt treatments unit $\mathit{i}$ received, for $\mathit{i}=1,2,\dots ,n$.
Constraint:
if ${\mathbf{nt}}\ge 2$, $1\le {\mathbf{it}}\left(\mathit{i}\right)\le {\mathbf{nt}}$, for $\mathit{i}=1,2,\dots ,n$.
7: $\mathbf{gmean}$ – Real (Kind=nag_wp)Output
On exit: the grand mean, $\hat{\mu}$.
8: $\mathbf{tmean}\left({\mathbf{nt}}\right)$ – Real (Kind=nag_wp) arrayOutput
On exit: if ${\mathbf{nt}}\ge 2$,
${\mathbf{tmean}}\left(\mathit{l}\right)$ contains the (adjusted) mean for the $\mathit{l}$th treatment, ${\hat{\mu}}^{*}+{\hat{\tau}}_{\mathit{l}}$, for $\mathit{l}=1,2,\dots ,t$, where ${\hat{\mu}}^{*}$ is the mean of the treatment adjusted observations ${y}_{ijk\left(l\right)}-{\hat{\tau}}_{l}$. Otherwise tmean is not referenced.
9: $\mathbf{tabl}({\mathbf{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 replicates, row 2 for rows, row 3 for columns, row 4 for treatments (if ${\mathbf{nt}}>1$), row 5 for residual and row 6 for total. Mean squares are computed for all but the total row, $F$-statistics and significance are computed for treatments, replicates, rows and columns. Any unfilled cells are set to zero.
10: $\mathbf{ldtabl}$ – IntegerInput
On entry: the first dimension of the array tabl as declared in the (sub)program from which g04bcf is called.
Constraint:
${\mathbf{ldtabl}}\ge 6$.
11: $\mathbf{c}({\mathbf{ldc}},{\mathbf{nt}})$ – Real (Kind=nag_wp) arrayOutput
On exit: 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., ${\mathbf{c}}(\mathit{i},\mathit{j})$ contains the covariance of treatment $\mathit{i}$ and $\mathit{j}$ if $\mathit{j}\ge \mathit{i}$ and the standard error of the difference between treatment $\mathit{i}$ and $\mathit{j}$ if $\mathit{j}<\mathit{i}$, for $\mathit{i}=1,2,\dots ,t$ and $\mathit{j}=1,2,\dots ,t$.
12: $\mathbf{ldc}$ – IntegerInput
On entry: the first dimension of the array c as declared in the (sub)program from which g04bcf is called.
On exit: if ${\mathbf{nt}}>1$, the treatment replications,
${R}_{\mathit{l}\mathit{l}}$, for $\mathit{l}=1,2,\dots ,{\mathbf{nt}}$. Otherwise irep is not referenced.
14: $\mathbf{rpmean}\left({\mathbf{nrep}}\right)$ – Real (Kind=nag_wp) arrayOutput
On exit: if ${\mathbf{nrep}}>1$,
${\mathbf{rpmean}}\left(\mathit{i}\right)$ contains the mean for the $\mathit{i}$th replicate, $\hat{\mu}+{\hat{\beta}}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,b$. Otherwise rpmean is not referenced.
15: $\mathbf{rmean}\left({\mathbf{nrep}}\times {\mathbf{nrow}}\right)$ – Real (Kind=nag_wp) arrayOutput
On exit: ${\mathbf{rmean}}\left(\mathit{j}\right)$ contains the mean for the $\mathit{j}$th row, $\hat{\mu}+{\hat{\rho}}_{i}$, for $\mathit{j}=1,2,\dots ,r$.
16: $\mathbf{cmean}\left({\mathbf{nrep}}\times {\mathbf{ncol}}\right)$ – Real (Kind=nag_wp) arrayOutput
On exit: ${\mathbf{cmean}}\left(\mathit{k}\right)$ contains the mean for the $\mathit{k}$th column, $\hat{\mu}+{\hat{\gamma}}_{\mathit{k}}$, for $\mathit{k}=1,2,\dots ,c$.
17: $\mathbf{r}\left({\mathbf{nrep}}\times {\mathbf{nrow}}\times {\mathbf{ncol}}\right)$ – Real (Kind=nag_wp) arrayOutput
On exit: the residuals,
${r}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
18: $\mathbf{ef}\left({\mathbf{nt}}\right)$ – Real (Kind=nag_wp) arrayOutput
On exit: if ${\mathbf{nt}}\ge 2$, the canonical efficiency factors. Otherwise ef is not referenced.
19: $\mathbf{tol}$ – Real (Kind=nag_wp)Input
On entry: the tolerance value used to check for zero eigenvalues of the matrix $\Omega $. If ${\mathbf{tol}}=0.0$ a default value of $0.00001$ is used.
Constraint:
${\mathbf{tol}}\ge 0.0$.
20: $\mathbf{irdf}$ – IntegerInput
On entry: an adjustment to the degrees of freedom for the residual and total.
${\mathbf{irdf}}\ge 1$
The degrees of freedom for the total is set to $n-{\mathbf{irdf}}$ and the residual degrees of freedom adjusted accordingly.
${\mathbf{irdf}}=0$
The total degrees of freedom for the total is set to $n-1$, as usual.
Constraint:
${\mathbf{irdf}}\ge 0$.
21: $\mathbf{wk}\left(3\times {\mathbf{nt}}\right)$ – Real (Kind=nag_wp) arrayWorkspace
22: $\mathbf{ifail}$ – IntegerInput/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $-1$ is recommended since useful values can be provided in some output arguments even when ${\mathbf{ifail}}\ne {\mathbf{0}}$ on exit. When the value $-\mathbf{1}$ 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).
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).
Errors or warnings detected by the routine:
Note: in some cases g04bcf may return useful information.
${\mathbf{ifail}}=1$
On entry, ${\mathbf{irdf}}=\u27e8\mathit{\text{value}}\u27e9$.
Constraint: ${\mathbf{irdf}}\ge 0$.
On entry, ${\mathbf{ldc}}=\u27e8\mathit{\text{value}}\u27e9$ and ${\mathbf{nt}}=\u27e8\mathit{\text{value}}\u27e9$.
Constraint: ${\mathbf{ldc}}\ge {\mathbf{nt}}$.
On entry, ${\mathbf{ldtabl}}=\u27e8\mathit{\text{value}}\u27e9$.
Constraint: ${\mathbf{ldtabl}}\ge 6$.
On entry, ${\mathbf{ncol}}=\u27e8\mathit{\text{value}}\u27e9$.
Constraint: ${\mathbf{ncol}}\ge 2$.
On entry, ${\mathbf{nrep}}=\u27e8\mathit{\text{value}}\u27e9$.
Constraint: ${\mathbf{nrep}}\ge 1$.
On entry, ${\mathbf{nrow}}=\u27e8\mathit{\text{value}}\u27e9$.
Constraint: ${\mathbf{nrow}}\ge 2$.
On entry, ${\mathbf{nt}}=\u27e8\mathit{\text{value}}\u27e9$.
Constraint: ${\mathbf{nt}}\ge 1$.
On entry, ${\mathbf{tol}}=\u27e8\mathit{\text{value}}\u27e9$.
Constraint: ${\mathbf{tol}}\ge 0.0$.
${\mathbf{ifail}}=2$
On entry, at least one treatment is not present. Treatment $\u27e8\mathit{\text{value}}\u27e9$ does not appear in it.
On entry, $i=\u27e8\mathit{\text{value}}\u27e9$, ${\mathbf{it}}\left(i\right)=\u27e8\mathit{\text{value}}\u27e9$ and ${\mathbf{nt}}=\u27e8\mathit{\text{value}}\u27e9$.
Constraint: $1\le {\mathbf{it}}\left(i\right)\le {\mathbf{nt}}$.
A computed standard error is zero. This is due to rounding errors and is an unlikely error exit.
The computation of the eigenvalues has failed to converge. This is an unlikely error exit.
${\mathbf{ifail}}=5$
The treatments are totally confounded with blocks. 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.
${\mathbf{ifail}}=6$
The residual degrees of freedom is 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 ${s}^{2}$.
The residual mean square is 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 ${s}^{2}$.
${\mathbf{ifail}}=7$
The design is disconnected. The standard errors may not valid. The design may be nested.
${\mathbf{ifail}}=-99$
An unexpected error has been triggered by this routine. Please
contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.
7Accuracy
The algorithm used in g04bcf, described in Section 3, achieves greater accuracy than the traditional algorithms based on the subtraction of sums of squares.
8Parallelism and Performance
g04bcf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g04bcf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.
9Further 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 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, g02cbforg02daf. 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 replicates, rows and columns only.
10Example
The data for a $5\times 5$ Latin square is input and the ANOVA and treatment means computed and printed. Since the design is orthogonal only one standard error need be printed