Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

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${\stackrel{^}{\sigma }}^{2}$, and the (variance ratio) F$F$-statistic for the t$t$ treatments. If this F$F$-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 18$18$, 20$20$ and 22$22$, and an uncontrolled temperature (denoted by N$\mathrm{N}$) 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${\stackrel{^}{\tau }}_{i}$, i = 1,2,,t$i=1,2,\dots ,t$, and let the j$j$th contrast be defined by λij${\lambda }_{ij}$, i = 1,2,,t$i=1,2,\dots ,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 ni${n}_{i}$ is the number of observations for the i$i$th treatment. Such a contrast has one degree of freedom so that the appropriate F$F$-statistic is SSj / σ̂2${\mathrm{SS}}_{j}/{\stackrel{^}{\sigma }}^{2}$.
The two contrasts λij${\lambda }_{ij}$ and λij${\lambda }_{i{j}^{\prime }}$ are orthogonal if i = 1tλijλij = 0$\sum _{i=1}^{t}{\lambda }_{ij}{\lambda }_{i{j}^{\prime }}=0$ and the contrast λij${\lambda }_{ij}$ is orthogonal to the overall mean if i = 1tλij = 0$\sum _{i=1}^{t}{\lambda }_{ij}=0$. In practice these sums will be tested against a small quantity, ε$\epsilon$. 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 F$F$-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 * ${\tau }_{\mathit{i}}^{*}$, for i = 1,2,,t$\mathit{i}=1,2,\dots ,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 nt2${\mathbf{nt}}\ge 2$.
The treatment means, τ̂i${\stackrel{^}{\tau }}_{\mathit{i}}$, for i = 1,2,,t$\mathit{i}=1,2,\dots ,t$.
2:     irep(nt) – int64int32nag_int array
nt, the dimension of the array, must satisfy the constraint nt2${\mathbf{nt}}\ge 2$.
The replication for each treatment mean, ni${n}_{\mathit{i}}$, for i = 1,2,,t$\mathit{i}=1,2,\dots ,t$.
3:     rms – double scalar
The residual mean square, σ̂2${\stackrel{^}{\sigma }}^{2}$.
Constraint: rms > 0.0${\mathbf{rms}}>0.0$.
4:     rdf – double scalar
The residual degrees of freedom.
Constraint: rdf1.0${\mathbf{rdf}}\ge 1.0$.
5:     ct(ldct,nc) – double array
ldct, the first dimension of the array, must satisfy the constraint ldctnt$\mathit{ldct}\ge {\mathbf{nt}}$.
The columns of ct must contain the nc contrasts, that is ct(i,j)${\mathbf{ct}}\left(\mathit{i},\mathit{j}\right)$ must contain λij${\lambda }_{\mathit{i}\mathit{j}}$, for i = 1,2,,t$\mathit{i}=1,2,\dots ,t$ and j = 1,2,,nc$\mathit{j}=1,2,\dots ,{\mathbf{nc}}$.
6:     tabl(ldtabl, : $:$) – double array
The first dimension of the array tabl must be at least nc${\mathbf{nc}}$
The second dimension of the array must be at least 5$5$
The elements of tabl that are not referenced as described below remain unchanged.
7:     tol – double scalar
The tolerance, ε$\epsilon$ used to check if the contrasts are orthogonal and if they are orthogonal to the mean. If tol0.0${\mathbf{tol}}\le 0.0$ the value machine precision is used.
8:     usetx – logical scalar
If usetx = true${\mathbf{usetx}}=\mathbf{true}$ the means τi * ${\tau }_{i}^{*}$ are provided in tx and the formula (2) is used instead of formula (1).
If usetx = false${\mathbf{usetx}}=\mathbf{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 nt2${\mathbf{nt}}\ge 2$.
If usetx = true${\mathbf{usetx}}=\mathbf{true}$ tx must contain the means τi * ${\tau }_{\mathit{i}}^{*}$, for i = 1,2,,t$\mathit{i}=1,2,\dots ,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.)
t$t$, the number of treatment means.
Constraint: nt2${\mathbf{nt}}\ge 2$.
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: nc1${\mathbf{nc}}\ge 1$.

ldct ldtabl

Output Parameters

1:     est(nc) – double array
The estimates of the contrast, Λj${\Lambda }_{\mathit{j}}$, for j = 1,2,,nc$\mathit{j}=1,2,\dots ,{\mathbf{nc}}$.
2:     tabl(ldtabl, : $:$) – double array
The first dimension of the array tabl will be nc${\mathbf{nc}}$
The second dimension of the array will be 5$5$
ldtablnc$\mathit{ldtabl}\ge {\mathbf{nc}}$.
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 F$F$-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
${\mathrm{ifail}}={\mathbf{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 = 1${\mathbf{ifail}}=1$
 On entry, nc < 1${\mathbf{nc}}<1$, or nt < 2${\mathbf{nt}}<2$, or ldct < nt$\mathit{ldct}<{\mathbf{nt}}$, or ldtabl < nc$\mathit{ldtabl}<{\mathbf{nc}}$, or rms ≤ 0.0${\mathbf{rms}}\le 0.0$, or rdf < 1.0${\mathbf{rdf}}<1.0$.
W ifail = 2${\mathbf{ifail}}=2$
 On entry, a contrast is not orthogonal to the mean, or at least two contrasts are not orthogonal.
If ${\mathbf{ifail}}={\mathbf{2}}$ full results are returned but they should be interpreted with care.

Accuracy

The computations are stable.

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

```