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_hier2 (g04ag)

Purpose

nag_anova_hier2 (g04ag) 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.

Syntax

[ngp, gbar, sgbar, gm, ss, idf, f, fp, ifail] = g04ag(y, lsub, nobs, 'n', n, 'k', k, 'l', l)
[ngp, gbar, sgbar, gm, ss, idf, f, fp, ifail] = nag_anova_hier2(y, lsub, nobs, 'n', n, 'k', k, 'l', l)

Description

In a two-way hierarchical classification, there are kk (22) treatment groups, the iith of which is subdivided into lili treatment subgroups. The jjth subgroup of group ii contains nijnij observations, which may be denoted by
y1ij,y2ij,,ynijij.
y1ij,y2ij,,ynijij.
The general observation is denoted by ymijymij, being the mmth observation in subgroup jj of group ii, for 1ik1ik, 1jli1jli, 1mnij1mnij.
The following quantities are computed
(i) The subgroup means
y . ij = (m = 1nijymij)/(nij)
y-.ij=m=1nijymijnij
(ii) The group means
y . i . = (j = 1lim = 1nijymij)/(j = 1linij)
y-.i.=j= 1lim= 1nijymij j= 1linij
(iii) The grand mean
y = (i = 1kj = 1lim = 1nijymij)/(i = 1kj = 1linij)
y-=i=1kj=1lim=1nijymij i=1kj=1linij
(iv) The number of observations in each group
li
ni . = nij
j = 1
ni.= j= 1 li nij
(v) Sums of squares
Between groups
k
= SSg = ni . (y . i . y)2
i = 1
Between subgroups within groups
kli
= SSsg = nij(y . ijy . i . )2
i = 1j = 1
Residual (within subgroups)
klinij
= SSres = (ymijy . ij)2 = SStotSSgSSsg
i = 1j = 1m = 1
Corrected total
klinij
= SStot = (ymijy)2
i = 1j = 1m = 1
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: k1k-1
Subgroups within groups: lkl-k
Residual: nln-l
Total: n1n-1
where
  • l = i = 1klil=i=1kli,
  • n = i = 1kni . n=i=1kni.
(vii) FF ratios. These are the ratios of the group and subgroup mean squares to the residual mean square.
Groups F1 = (Between groups sum of squares / (k1))/(Residual sum of squares / (nl)) = (SSg / (k1))/(SSres / (nl)) 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 / (lk))/(Residual sum of squares / (nl)) = (SSsg / (lk))/(SSres / (nl)) F2= Between subgroups (within group) sum of squares/(l-k) Residual sum of squares/(n-l) = SSsg/(l-k) SSres/(n-l)
If either FF ratio exceeds 9999.09999.0, the value 9999.09999.0 is assigned instead.
(viii) f significances. The probability of obtaining a value from the appropriate FF-distribution which exceeds the computed mean square ratio.
Groups p1 = Prob (F (k1) , (nl) > F1) p 1 = Prob ( F ( k - 1 ) , ( n - l ) > F 1 )  
Subgroups p2 = Prob (F (lk) , (nl) > F2) p 2 = Prob ( F ( l - k ) , ( n - l ) > F 2 )  
where Fν1,ν2Fν1,ν2 denotes the central FF-distribution with degrees of freedom ν1ν1 and ν2ν2.
If any Fi = 9999.0Fi=9999.0, then pipi is set to zero, i = 1,2i=1,2.

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

Parameters

Compulsory Input Parameters

1:     y(n) – double array
The elements of y must contain the observations ymijymij in the following order:
y111,y211,,yn1111,y112,y212,,yn1212,,y11l1,,
y111,y211,,yn1111,y112,y212,,yn1212,,y11l1,,
yn1l11l1,, y1ij,,ynijij,,y1klk,, ynklkklk.
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:     lsub(k) – int64int32nag_int array
k, the dimension of the array, must satisfy the constraint k2k2.
The number of subgroups within group ii, lili, for i = 1,2,,ki=1,2,,k.
Constraint: lsub(i) > 0lsubi>0, for i = 1,2,,ki=1,2,,k.
3:     nobs(l) – int64int32nag_int array
l, the dimension of the array, must satisfy the constraint l = i = 1klsub(i)l=i=1klsubi.
The numbers of observations in each subgroup, nijnij, in the following order:
n11,n12,,n1l1,n21,,n2l2,,nk1,,nklk
n11,n12,,n1l1,n21,,n2l2,,nk1,,nklk
Constraint: n = i = 1kj = 1linijn=i=1kj=1linij, that is n = i = 1lnobs(i)n=i=1lnobsi and nobs(i) > 0nobsi>0, for i = 1,2,,li=1,2,,l.

Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The dimension of the array y.
nn, the total number of observations.
2:     k – int64int32nag_int scalar
Default: The dimension of the array lsub.
kk, the number of groups.
Constraint: k2k2.
3:     l – int64int32nag_int scalar
Default: The dimension of the array nobs.
ll, the total number of subgroups.
Constraint: l = i = 1klsub(i)l=i=1klsubi.

Input Parameters Omitted from the MATLAB Interface

None.

Output Parameters

1:     ngp(k) – int64int32nag_int array
The total number of observations in group ii, ni . ni., for i = 1,2,,ki=1,2,,k.
2:     gbar(k) – double array
The mean for group ii, y . i . y-.i., for i = 1,2,,ki=1,2,,k.
3:     sgbar(l) – double array
The subgroup means, y . ijy-.ij, in the following order:
y.11,y.12,,y.1l1,y.21,y.22,,y.2l2,,y . k1,y . k2,,y . klk.
y-.11,y-.12,,y-.1l1,y-.21,y-.22,,y-.2l2,,y-.k1,y-.k2,,y-.klk.
4:     gm – double scalar
The grand mean, yy-.
5:     ss(44) – double array
Contains the sums of squares for the analysis of variance, as follows;
  • ss(1) = ss1= Between group sum of squares, ssgssg,
  • ss(2) = ss2= Between subgroup within groups sum of squares, sssgsssg,
  • ss(3) = ss3= Residual sum of squares, ssresssres,
  • ss(4) = ss4= Corrected total sum of squares, sstotsstot.
6:     idf(44) – int64int32nag_int array
Contains the degrees of freedom attributable to each sum of squares in the analysis of variance, as follows:
  • idf(1) = idf1= Degrees of freedom for between group sum of squares,
  • idf(2) = idf2= Degrees of freedom for between subgroup within groups sum of squares,
  • idf(3) = idf3= Degrees of freedom for residual sum of squares,
  • idf(4) = idf4= Degrees of freedom for corrected total sum of squares.
7:     f(22) – double array
Contains the mean square ratios, F1F1 and F2F2, for the between groups variation, and the between subgroups within groups variation, with respect to the residual, respectively.
8:     fp(22) – double array
Contains the significances of the mean square ratios, p1p1 and p2p2 respectively.
9:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and 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,k1k1.
  ifail = 2ifail=2
On entry,lsub(i)0lsubi0, for some i = 1,2,,ki=1,2,,k.
  ifail = 3ifail=3
On entry,li = 1klsub(i)li=1klsubi
  ifail = 4ifail=4
On entry,nobs(i)0nobsi0, for some i = 1,2,,li=1,2,,l.
  ifail = 5ifail=5
On entry,ni = 1lnobs(i)ni=1lnobsi.
W ifail = 6ifail=6
The total corrected sum of squares is zero, indicating 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.
W ifail = 7ifail=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.

Accuracy

The computations are believed to be stable.

Further Comments

The time taken by nag_anova_hier2 (g04ag) increases approximately linearly with the total number of observations, nn.

Example

function nag_anova_hier2_example
y = [2.1;
     2.4;
     2;
     2;
     2;
     2.4;
     2.1;
     2.2;
     2.4;
     2.2;
     2.6;
     2.4;
     2.4;
     2.5;
     1.9;
     1.7;
     2.1;
     1.5;
     2;
     1.9;
     1.7;
     1.9;
     1.9;
     1.9;
     2;
     2.1;
     2.3];
lsub = [int64(5);3];
nobs = [int64(5);3;3;3;2;3;5;3];
[ngp, gbar, sgbar, gm, ss, idf, f, fp, ifail] = nag_anova_hier2(y, lsub, nobs)
 

ngp =

                   16
                   11


gbar =

    2.2062
    1.9364


sgbar =

    2.1000
    2.2333
    2.4000
    2.4333
    1.8000
    1.8667
    1.8600
    2.1333


gm =

    2.0963


ss =

    0.4748
    0.8162
    0.5587
    1.8496


idf =

                    1
                    6
                   19
                   26


f =

   16.1477
    4.6262


fp =

    0.0007
    0.0047


ifail =

                    0


function g04ag_example
y = [2.1;
     2.4;
     2;
     2;
     2;
     2.4;
     2.1;
     2.2;
     2.4;
     2.2;
     2.6;
     2.4;
     2.4;
     2.5;
     1.9;
     1.7;
     2.1;
     1.5;
     2;
     1.9;
     1.7;
     1.9;
     1.9;
     1.9;
     2;
     2.1;
     2.3];
lsub = [int64(5);3];
nobs = [int64(5);3;3;3;2;3;5;3];
[ngp, gbar, sgbar, gm, ss, idf, f, fp, ifail] = g04ag(y, lsub, nobs)
 

ngp =

                   16
                   11


gbar =

    2.2062
    1.9364


sgbar =

    2.1000
    2.2333
    2.4000
    2.4333
    1.8000
    1.8667
    1.8600
    2.1333


gm =

    2.0963


ss =

    0.4748
    0.8162
    0.5587
    1.8496


idf =

                    1
                    6
                   19
                   26


f =

   16.1477
    4.6262


fp =

    0.0007
    0.0047


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