NAG Library Routine Document

g04agf (hier2)

1
Purpose

g04agf performs an analysis of variance for a two-way hierarchical classification with subgroups of possibly unequal size, and also computes the treatment group and subgroup means. A fixed effects model is assumed.

2
Specification

Fortran Interface
Subroutine g04agf ( y, n, k, lsub, nobs, l, ngp, gbar, sgbar, gm, ss, idf, f, fp, ifail)
Integer, Intent (In):: n, k, lsub(k), nobs(l), l
Integer, Intent (Inout):: ifail
Integer, Intent (Out):: ngp(k), idf(4)
Real (Kind=nag_wp), Intent (In):: y(n)
Real (Kind=nag_wp), Intent (Out):: gbar(k), sgbar(l), gm, ss(4), f(2), fp(2)
C Header Interface
#include <nagmk26.h>
void  g04agf_ (const double y[], const Integer *n, const Integer *k, const Integer lsub[], const Integer nobs[], const Integer *l, Integer ngp[], double gbar[], double sgbar[], double *gm, double ss[], Integer idf[], double f[], double fp[], Integer *ifail)

3
Description

In a two-way hierarchical classification, there are k (2) treatment groups, the ith of which is subdivided into li treatment subgroups. The jth subgroup of group i contains nij observations, which may be denoted by
y1ij,y2ij,,ynijij.  
The general observation is denoted by ymij, being the mth observation in subgroup j of group i, for 1ik, 1jli, 1mnij.
The following quantities are computed
(i) The subgroup means
y-.ij=m=1nijymijnij  
(ii) The group means
y-.i.=j= 1lim= 1nijymij j= 1linij  
(iii) The grand mean
y-=i=1kj=1lim=1nijymij i=1kj=1linij  
(iv) The number of observations in each group
ni.= j= 1 li nij  
(v) Sums of squares
Between groups =SSg = i=1 k ni. y-.i.-y- 2 Between subgroups within groups =SSsg= i=1 k j=1 li nij y.ij-y-.i. 2 Residual (within subgroups) =SSres= i=1 k j=1 li m=1 nij ymij-y-.ij 2 =SStot-SSg-SSsg Corrected total =SStot= i=1 k j=1 li m=1 nij ymij-y- 2  
(vi) Degrees of freedom of variance components
Between groups: k-1
Subgroups within groups: l-k
Residual: n-l
Total: n-1
where
  • l=i=1kli,
  • n=i=1kni.
(vii) F ratios. These are the ratios of the group and subgroup mean squares to the residual mean square.
Groups F1= Between groups sum of squares/k-1 Residual sum of squares/n-l = SSg/k-1 SSres/n-l
Subgroups F2= Between subgroups (within group) sum of squares/l-k Residual sum of squares/n-l = SSsg/l-k SSres/n-l
If either F ratio exceeds 9999.0, the value 9999.0 is assigned instead.
(viii) f significances. The probability of obtaining a value from the appropriate F-distribution which exceeds the computed mean square ratio.
Groups p 1 = Prob F k - 1 , n - l > F 1  
Subgroups p 2 = Prob F l - k , n - l > F 2  
where Fν1,ν2 denotes the central F-distribution with degrees of freedom ν1 and ν2.
If any Fi=9999.0, then pi is set to zero, i=1,2.

4
References

Kendall M G and Stuart A (1976) The Advanced Theory of Statistics (Volume 3) (3rd Edition) Griffin
Moore P G, Shirley E A and Edwards D E (1972) Standard Statistical Calculations Pitman

5
Arguments

1:     yn – Real (Kind=nag_wp) arrayInput
On entry: the elements of y must contain the observations ymij in the following order:
y111,y211,,yn1111,y112,y212,,yn1212,,y11l1,,  
yn1l11l1,, y1ij,,ynijij,,y1klk,, ynklkklk.  
In words, the ordering is by group, and within each group is by subgroup, the members of each subgroup being in consecutive locations in y.
2:     n – IntegerInput
On entry: n, the total number of observations.
3:     k – IntegerInput
On entry: k, the number of groups.
Constraint: k2.
4:     lsubk – Integer arrayInput
On entry: the number of subgroups within group i, li, for i=1,2,,k.
Constraint: lsubi>0, for i=1,2,,k.
5:     nobsl – Integer arrayInput
On entry: the numbers of observations in each subgroup, nij, in the following order:
n11,n12,,n1l1,n21,,n2l2,,nk1,,nklk  
Constraint: n=i=1kj=1linij, that is n=i=1lnobsi and nobsi>0, for i=1,2,,l.
6:     l – IntegerInput
On entry: l, the total number of subgroups.
Constraint: l=i=1klsubi.
7:     ngpk – Integer arrayOutput
On exit: the total number of observations in group i, ni., for i=1,2,,k.
8:     gbark – Real (Kind=nag_wp) arrayOutput
On exit: the mean for group i, y-.i., for i=1,2,,k.
9:     sgbarl – Real (Kind=nag_wp) arrayOutput
On exit: the subgroup means, y-.ij, in the following order:
y-.11,y-.12,,y-.1l1,y-.21,y-.22,,y-.2l2,,y-.k1,y-.k2,,y-.klk.  
10:   gm – Real (Kind=nag_wp)Output
On exit: the grand mean, y-.
11:   ss4 – Real (Kind=nag_wp) arrayOutput
On exit: contains the sums of squares for the analysis of variance, as follows;
  • ss1= Between group sum of squares, ssg,
  • ss2= Between subgroup within groups sum of squares, sssg,
  • ss3= Residual sum of squares, ssres,
  • ss4= Corrected total sum of squares, sstot.
12:   idf4 – Integer arrayOutput
On exit: contains the degrees of freedom attributable to each sum of squares in the analysis of variance, as follows:
  • idf1= Degrees of freedom for between group sum of squares,
  • idf2= Degrees of freedom for between subgroup within groups sum of squares,
  • idf3= Degrees of freedom for residual sum of squares,
  • idf4= Degrees of freedom for corrected total sum of squares.
13:   f2 – Real (Kind=nag_wp) arrayOutput
On exit: contains the mean square ratios, F1 and F2, for the between groups variation, and the between subgroups within groups variation, with respect to the residual, respectively.
14:   fp2 – Real (Kind=nag_wp) arrayOutput
On exit: contains the significances of the mean square ratios, p1 and p2 respectively.
15:   ifail – IntegerInput/Output
On entry: ifail must be set to 0, -1 or 1. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1 or 1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, if you are not familiar with this argument, the recommended value is 0. When the value -1 or 1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6
Error Indicators and Warnings

If on entry 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:
ifail=1
On entry, k=value.
Constraint: k>1.
ifail=2
On entry, i=value and lsubi=value.
Constraint: lsubi>0.
ifail=3
On entry, ilsubi=value and l=value.
Constraint: ilsubi=l.
ifail=4
On entry, i=value and nobsi=value.
Constraint: nobsi>0.
ifail=5
On entry, inobsi=value and n=value.
Constraint: inobsi=n.
ifail=6
The total corrected sum of squares is zero. This indicates that all the data values are equal, the means returned are therefore all equal, and the sums of squares are zero. No assignments are made to idf, f, and fp.
ifail=7
The residual sum of squares is zero. This arises when either each subgroup contains exactly one observation, or the observations within each subgroup are equal. The means, sums of squares, and degrees of freedom are computed, but no assignments are made to f and fp.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
ifail=-399
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
ifail=-999
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

7
Accuracy

The computations are believed to be stable.

8
Parallelism and Performance

g04agf is not threaded in any implementation.

9
Further Comments

The time taken by g04agf increases approximately linearly with the total number of observations, n.

10
Example

This example has two groups, the first of which consists of five subgroups, and the second of three subgroups. The numbers of observations in each subgroup are not equal. The data represent the percentage stretch in the length of samples of sack kraft drawn from consignments (subgroups) received over two years (groups). For details see Moore et al. (1972).

10.1
Program Text

Program Text (g04agfe.f90)

10.2
Program Data

Program Data (g04agfe.d)

10.3
Program Results

Program Results (g04agfe.r)