hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

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), σ̂2σ^2, and the (variance ratio) FF-statistic for the tt treatments. If this FF-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 1818, 2020 and 2222, and an uncontrolled temperature (denoted by NN) then the following contrasts might be of interest.
18 20 22 N
(a) (1/3) (1/3) (1/3) 1
(b) 1 0 1 0
18 20 22 N (a) 13 13 13 -1 (b) -1 0 1 0
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 τ̂iτ^i, i = 1,2,,ti=1,2,,t, and let the jjth contrast be defined by λijλij, i = 1,2,,ti=1,2,,t, then the estimate of the contrast is simply:
t
Λj = τ̂iλij
i = 1
Λj=i=1tτ^iλij
and the sum of squares for the contrast is:
SSj = (Λj2)/(i = 1tλij2 / ni)
SSj=Λj2 i=1tλij2/ni
(1)
where nini is the number of observations for the iith treatment. Such a contrast has one degree of freedom so that the appropriate FF-statistic is SSj / σ̂2SSj/σ^2.
The two contrasts λijλij and λijλij are orthogonal if i = 1tλijλij = 0i=1tλijλij=0 and the contrast λijλij is orthogonal to the overall mean if i = 1tλij = 0i=1tλij=0. 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 FF-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:
SSj = (ΛjΛj * )/(i = 1tλij2 / ni)
SSj=ΛjΛj* i=1tλij2/ni
(2)
where
t
Λj * = τi * λij
i = 1
Λj*=i= 1tτi*λij
with τi * τi*, for i = 1,2,,ti=1,2,,t, 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) and Morgan (1993).

References

Cochran W G and Cox G M (1957) Experimental Designs Wiley
John J A (1987) Cyclic Designs Chapman and Hall
Morgan G W (1993) Analysis of variance using the NAG Fortran Library: Examples from Cochran and Cox NAG Technical Report TR 3/93 NAG Ltd, Oxford
Winer B J (1970) Statistical Principles in Experimental Design McGraw–Hill

Parameters

Compulsory Input Parameters

1:     tmean(nt) – double array
nt, the dimension of the array, must satisfy the constraint nt2nt2.
The treatment means, τ̂iτ^i, for i = 1,2,,ti=1,2,,t.
2:     irep(nt) – int64int32nag_int array
nt, the dimension of the array, must satisfy the constraint nt2nt2.
The replication for each treatment mean, nini, for i = 1,2,,ti=1,2,,t.
3:     rms – double scalar
The residual mean square, σ̂2σ^2.
Constraint: rms > 0.0rms>0.0.
4:     rdf – double scalar
The residual degrees of freedom.
Constraint: rdf1.0rdf1.0.
5:     ct(ldct,nc) – double array
ldct, the first dimension of the array, must satisfy the constraint ldctntldctnt.
The columns of ct must contain the nc contrasts, that is ct(i,j)ctij must contain λijλij, for i = 1,2,,ti=1,2,,t and j = 1,2,,ncj=1,2,,nc.
6:     tabl(ldtabl, : :) – double array
The first dimension of the array tabl must be at least ncnc
The second dimension of the array must be at least 55
The elements of tabl that are not referenced as described below remain unchanged.
7:     tol – double scalar
The tolerance, εε used to check if the contrasts are orthogonal and if they are orthogonal to the mean. If tol0.0tol0.0 the value machine precision is used.
8:     usetx – logical scalar
If usetx = trueusetx=true the means τi * τi* are provided in tx and the formula (2) is used instead of formula (1).
If usetx = falseusetx=false formula (1) is used and tx is not referenced.
9:     tx(nt) – double array
nt, the dimension of the array, must satisfy the constraint nt2nt2.
If usetx = trueusetx=true tx must contain the means τi * τi*, for i = 1,2,,ti=1,2,,t.

Optional Input Parameters

1:     nt – 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.)
tt, the number of treatment means.
Constraint: nt2nt2.
2:     nc – 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: nc1nc1.

Input Parameters Omitted from the MATLAB Interface

ldct ldtabl

Output Parameters

1:     est(nc) – double array
The estimates of the contrast, ΛjΛj, for j = 1,2,,ncj=1,2,,nc.
2:     tabl(ldtabl, : :) – double array
The first dimension of the array tabl will be ncnc
The second dimension of the array will be 55
ldtablncldtablnc.
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 FF-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:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 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.

  ifail = 1ifail=1
On entry,nc < 1nc<1,
ornt < 2nt<2,
orldct < ntldct<nt,
orldtabl < ncldtabl<nc,
orrms0.0rms0.0,
orrdf < 1.0rdf<1.0.
W ifail = 2ifail=2
On entry,a contrast is not orthogonal to the mean,
orat least two contrasts are not orthogonal.
If ifail = 2ifail=2 full results are returned but they should be interpreted with care.

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

function nag_anova_contrasts_example
tmean = [22.625;
     9.5;
     16.75;
     15.5;
     18.25;
     5.75;
     14.25];
irep = [int64(8);4;4;4;4;4;4];
rms = 44.915;
rdf = 25;
ct = [6, 0;
     -1, 1;
     -1, -1;
     -1, 1;
     -1, -1;
     -1, 1;
     -1, -1];
table = zeros(2, 5);
tol = 5e-06;
usetx = false;
tx = zeros(7, 1);
[est, tableOut, ifail] = nag_anova_contrasts(tmean, irep, rms, rdf, ct, table, tol, usetx, tx)
 

est =

   55.7500
  -18.5000


tableOut =

    1.0000  518.0104  518.0104   11.5331    0.0023
    1.0000  228.1667  228.1667    5.0800    0.0332


ifail =

                    0


function g04da_example
tmean = [22.625;
     9.5;
     16.75;
     15.5;
     18.25;
     5.75;
     14.25];
irep = [int64(8);4;4;4;4;4;4];
rms = 44.915;
rdf = 25;
ct = [6, 0;
     -1, 1;
     -1, -1;
     -1, 1;
     -1, -1;
     -1, 1;
     -1, -1];
table = zeros(2, 5);
tol = 5e-06;
usetx = false;
tx = zeros(7, 1);
[est, tableOut, ifail] = g04da(tmean, irep, rms, rdf, ct, table, tol, usetx, tx)
 

est =

   55.7500
  -18.5000


tableOut =

    1.0000  518.0104  518.0104   11.5331    0.0023
    1.0000  228.1667  228.1667    5.0800    0.0332


ifail =

                    0



PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013