PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_anova_random (g04bb)
Purpose
nag_anova_random (g04bb) computes the analysis of variance and treatment means and standard errors for a randomized block or completely randomized design.
Syntax
[
gmean,
bmean,
tmean,
tabl,
c,
irep,
r,
ef,
ifail] = g04bb(
y,
iblock,
nt,
it,
tol,
irdf, 'n',
n)
[
gmean,
bmean,
tmean,
tabl,
c,
irep,
r,
ef,
ifail] = nag_anova_random(
y,
iblock,
nt,
it,
tol,
irdf, 'n',
n)
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
treatments and
plots per treatment, the linear model is
where
is the
th observation for the
th treatment,
is the overall mean,
is the effect of the
th treatment and
is the random error term. For a randomized block design, with
treatments and
blocks of
plots, the linear model is
where
is the effect of the
th block and the
notation indicates that the
th treatment is applied to the
th plot in the
th 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 . The estimated treatment effects, are then computed as the treatment means of the mean adjusted observations, , and the treatment sum of squares can be computed from the sum of squares of the treatment totals of the divided by the number of observations per treatment total, . The final residuals are computed as , 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 . The estimated block effects, ignoring treatment effects, , are then computed using the block means of the and the unadjusted sum of squares computed as the sum of squared block totals for the divided by number of plots per block, . The block adjusted observations are then computed as . 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, . The treatment sum of squares is computed as the sum of squared treatment totals of the divided by the number of replicates to the treatments, . Finally the residuals, and hence the residual sum of squares, are given by .
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
where
is the vector of the treatment totals for block adjusted observations,
,
is a diagonal matrix with
equal to the number of times the
th treatment is replicated, and
is the
by
incidence matrix, with
equal to the number of times treatment
occurs in block
. The solution to the equations can be written as
where
is a generalized inverse of
. The solution is found from the eigenvalue decomposition of
. The residuals are first calculated by subtracting the estimated treatment effects from the block adjusted observations to give
. However, since only the unadjusted block effects have been removed and blocks and treatments are not orthogonal, the block means of the
have to be subtracted to give the correct residuals,
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
, for the completely randomized and the complete block designs the degrees of freedom for the treatments is
. In the general case the degrees of freedom for treatments is the rank of the matrix
. The
-statistic given by the ratio of the treatment mean square to the residual mean square tests the hypothesis
The standard errors for the difference in treatment effects, or treatment means, for the completely randomized or the complete block designs, are given by:
where
is the residual mean square and
in the complete block design. In the general case the variances of the treatment effects are given by
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
, 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.
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
Parameters
Compulsory Input Parameters
- 1:
– double array
-
The observations in the order as described by
iblock and
nt.
- 2:
– int64int32nag_int scalar
-
Indicates the block structure.
- There are no blocks, i.e., it is a completely randomized design.
- There are iblock blocks and the data should be input by blocks, i.e., y must contain the observations for block followed by the observations for block , etc.
- There are blocks and the data is input in parallel with respect to blocks, i.e., must contain the first observation for block , must contain the first observation for block must contain the first observation for block must contain the second observation for block , etc.
Constraint:
, or .
- 3:
– int64int32nag_int scalar
-
The number of treatments. If only blocks are required in the analysis then set .
Constraints:
- if , ;
- otherwise .
- 4:
– int64int32nag_int array
-
The dimension of the array
it
must be at least
if
, and at least
otherwise
indicates which of the
nt treatments plot
received, for
.
If
,
it is not referenced.
Constraint:
, for .
- 5:
– double scalar
-
The tolerance value used to check for zero eigenvalues of the matrix . If a default value of is used.
Constraint:
.
- 6:
– int64int32nag_int scalar
-
An adjustment to the degrees of freedom for the residual and total.
- The degrees of freedom for the total is set to and the residual degrees of freedom adjusted accordingly.
- The total degrees of freedom for the total is set to , as usual.
Constraint:
.
Optional Input Parameters
- 1:
– int64int32nag_int scalar
-
Default:
the dimension of the array
y.
The number of observations.
Constraint:
and if
,
n must be a multiple of
.
Output Parameters
- 1:
– double scalar
-
The grand mean, .
- 2:
– double array
-
If ,
contains the mean for the th block, , for .
- 3:
– double array
-
If ,
contains the (adjusted) mean for the th treatment, , for , where is the mean of the treatment adjusted observations, .
- 4:
– double array
-
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 -statistic and column 5 the significance level of the -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; -statistics and significance are computed for Treatments and Blocks, if present. Any unfilled cells are set to zero.
- 5:
– double array
-
If
, 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.,
contains the covariance of treatment
and
if
and the standard error of the difference between treatment
and
if
, for
and
.
- 6:
– int64int32nag_int array
-
If , the treatment replications,
, for .
- 7:
– double array
-
The residuals,
, for .
- 8:
– double array
-
If , the canonical efficiency factors.
- 9:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Note: nag_anova_random (g04bb) may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the function:
Cases prefixed with W are classified as warnings and
do not generate an error of type NAG:error_n. See nag_issue_warnings.
-
-
On entry, | , |
or | , |
or | and , |
or | , |
or | , |
or | , |
or | . |
-
-
On entry, | and n is not a multiple of . |
-
-
On entry, | or for some when , |
or | no value of for some , when . |
-
-
On entry, | the values of y are constant. |
-
-
A computed standard error is zero due to rounding errors, or the eigenvalue computation failed to converge. Both are unlikely error exits.
- W
-
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.
- W
-
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
or
.
- W
-
The design is disconnected; the standard errors may not be valid. The design may be nested.
-
An unexpected error has been triggered by this routine. Please
contact
NAG.
-
Your licence key may have expired or may not have been installed correctly.
-
Dynamic memory allocation failed.
Accuracy
The algorithm used by
nag_anova_random (g04bb), described in
Description, achieves greater accuracy than the traditional algorithms based on the subtraction of sums of squares.
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
nag_anova_random (g04bb) or
nag_anova_rowcol (g04bc). The residuals from the preliminary analysis are then input to
nag_anova_random (g04bb). 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,
nag_correg_linregs_noconst (g02cb) or
nag_correg_linregm_fit (g02da). The results from those functions 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.
Example
The data, given by
John and Quenouille (1977), are for a balanced incomplete block design with
blocks and
treatments and with
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.
Open in the MATLAB editor:
g04bb_example
function g04bb_example
fprintf('g04bb example results\n\n');
y = [1; 5; 4; 5; 10; 6; 2; 9; 3; 4; 8;
6; 2; 4; 7; 6; 7; 5; 5; 7; 2; 7;
2; 4; 8; 4; 2; 10; 8; 7];
iblock = int64(10);
nt = int64(6);
it = [int64(1); 2; 3; 1; 2; 4; 1; 3; 5; 1;
4; 6; 1; 5; 6; 2; 3; 6; 2; 4;
5; 2; 5; 6; 3; 4; 5; 3; 4; 6];
tol = 5e-06;
irdf = int64(0);
[gmean, bmean, tmean, table, c, irep, r, ef, ifail] = ...
g04bb( ...
y, iblock, nt, it, tol, irdf);
fprintf('ANOVA table\n\n');
fprintf(' Source df SS MS F Prob\n\n');
fmt5 = '%s%5.0f%12.2f%12.2f%12.2f%11.4f\n';
fmt3 = '%s%5.0f%12.2f%12.2f\n';
fmt2 = '%s%5.0f%12.2f\n';
fprintf(fmt5, 'Blocks ', table(1,1:5));
fprintf(fmt5, 'Treatments ', table(2,1:5));
fprintf(fmt3, 'Residual ', table(3,1:3));
fprintf(fmt2, 'Total ', table(4,1:2));
fprintf('\nEfficiency Factors\n\n');
for j = 1:8:nt
fprintf('%8.4f', ef(j:min(j+7,nt)));
fprintf('\n');
end
fprintf('\n Grand Mean %10.2f\n\n', gmean);
fprintf('Treatment Means\n\n');
for j = 1:8:nt
fprintf('%8.4f', tmean(j:min(j+7,nt)));
fprintf('\n');
end
fprintf('\n');
[ifail] = x04ca( ...
'Lower', 'B', c, ...
'Standard errors of differences between means');
g04bb example results
ANOVA table
Source df SS MS F Prob
Blocks 9 60.00 6.67 4.79 0.0039
Treatments 5 101.78 20.36 14.62 0.0000
Residual 15 20.89 1.39
Total 29 182.67
Efficiency Factors
0.0000 0.8000 0.8000 0.8000 0.8000 0.8000
Grand Mean 5.33
Treatment Means
2.5000 7.2500 8.0833 5.9167 2.9167 5.3333
Standard errors of differences between means
1 2 3 4 5 6
1
2 0.8344
3 0.8344 0.8344
4 0.8344 0.8344 0.8344
5 0.8344 0.8344 0.8344 0.8344
6 0.8344 0.8344 0.8344 0.8344 0.8344
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015