PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_anova_contrasts (g04da)
Purpose
nag_anova_contrasts (g04da) computes sum of squares for a user-defined contrast between means.
Syntax
[
est,
tabl,
ifail] = g04da(
tmean,
irep,
rms,
rdf,
ct,
tabl,
tol,
usetx,
tx, 'nt',
nt, 'nc',
nc)
[
est,
tabl,
ifail] = nag_anova_contrasts(
tmean,
irep,
rms,
rdf,
ct,
tabl,
tol,
usetx,
tx, 'nt',
nt, 'nc',
nc)
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).
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
Parameters
Compulsory Input Parameters
- 1:
– double array
-
The treatment means,
, for .
- 2:
– int64int32nag_int array
-
The replication for each treatment mean,
, for .
- 3:
– double scalar
-
The residual mean square, .
Constraint:
.
- 4:
– double scalar
-
The residual degrees of freedom.
Constraint:
.
- 5:
– double array
-
ldct, the first dimension of the array, must satisfy the constraint
.
The columns of
ct must contain the
nc contrasts, that is
must contain
, for
and
.
- 6:
– double array
-
The first dimension of the array
tabl must be at least
.
The second dimension of the array
tabl must be at least
.
The elements of
tabl that are not referenced as described below remain unchanged.
- 7:
– double scalar
-
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.
- 8:
– logical scalar
-
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.
- 9:
– double array
-
If
tx must contain the means
, for
.
Optional Input Parameters
- 1:
– int64int32nag_int scalar
-
Default:
the dimension of the arrays
irep,
tmean,
tx and the first dimension of the array
ct. (An error is raised if these dimensions are not equal.)
, the number of treatment means.
Constraint:
.
- 2:
– int64int32nag_int scalar
-
Default:
the first dimension of the array
tabl and the second dimension of the array
ct. (An error is raised if these dimensions are not equal.)
The number of contrasts.
Constraint:
.
Output Parameters
- 1:
– double array
-
The estimates of the contrast,
, for .
- 2:
– double array
-
The first dimension of the array
tabl will be
.
The second dimension of the array
tabl will be
.
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.
- 3:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Note: nag_anova_contrasts (g04da) 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 | , |
or | , |
or | , |
or | . |
- W
-
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.
-
Your licence key may have expired or may not have been installed correctly.
-
Dynamic memory allocation failed.
Accuracy
The computations are stable.
Further Comments
If the treatments have a factorial structure
nag_anova_factorial (g04ca) should be used and if the treatments have no structure the means can be compared using
nag_anova_confidence (g04db).
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
nag_correg_coeffs_pearson_miss_case (g02bb). Two contrasts are analysed, one comparing the control with use of sulphur, the other comparing spring with autumn application.
Open in the MATLAB editor:
g04da_example
function g04da_example
fprintf('g04da example results\n\n');
n1 = int64(1);
iblock = n1;
y = [12 10 24 29 30 18 32 26 9 9 ...
16 4 30 7 21 9 16 10 18 18 ...
18 24 12 19 10 4 4 5 17 7 ...
16 17];
it = [n1 1 1 1 1 1 1 1 2 2 ...
2 2 3 3 3 3 4 4 4 4 ...
5 5 5 5 6 6 6 6 7 7 ...
7 7];
nt = 7*n1;
nc = 2*n1;
ct = [6, 0;
-1, 1;
-1, -1;
-1, 1;
-1, -1;
-1, 1;
-1, -1];
names = {'Cntl v S '; 'Spring v A '};
tol = 0;
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.1f%12.1f%12.3f%11.4f\n';
fmt3 = '%s%5.0f%12.1f%12.1f\n';
fmt2 = '%s%5.0f%12.1f\n\n';
if iblock > 1
fprintf(fmt5, 'Blocks ', table(1,1:5));
end
fprintf(fmt5, 'Treatments ', table(2,1:5));
fprintf(fmt3, 'Residual ', table(3,1:3));
fprintf(fmt2, 'Total ', table(4,1:2));
rms = table(3,3);
rdf = table(3,1);
usetx = false;
tx = zeros(nt, 1);
table = zeros(nc,5);
[est, table, ifail] = g04da( ...
tmean, irep, rms, rdf, ct, table, tol, usetx, tx);
fprintf('Orthogonal Contrasts\n\n');
for i = 1:nc
fprintf(fmt5, names{i}, table(i,1:5));
end
g04da example results
ANOVA table
Source df SS MS F Prob
Treatments 6 972.3 162.1 3.608 0.0103
Residual 25 1122.9 44.9
Total 31 2095.2
Orthogonal Contrasts
Cntl v S 1 518.0 518.0 11.533 0.0023
Spring v A 1 228.2 228.2 5.080 0.0332
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015