PDF version (NAG web site
, 64-bit version, 64-bit version)
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
(
) treatment groups, the
th of which is subdivided into
treatment subgroups. The
th subgroup of group
contains
observations, which may be denoted by
The general observation is denoted by
, being the
th observation in subgroup
of group
, for
,
,
.
The following quantities are computed
(i) |
The subgroup means
|
(ii) |
The group means
|
(iii) |
The grand mean
|
(iv) |
The number of observations in each group
|
(v) |
Sums of squares
|
(vi) |
Degrees of freedom of variance components
Between groups: |
|
Subgroups within groups: |
|
Residual: |
|
Total: |
|
where
|
(vii) |
ratios. These are the ratios of the group and subgroup mean squares to the residual mean square.
Groups |
|
Subgroups |
|
If either ratio exceeds , the value is assigned instead. |
(viii) |
f significances. The probability of obtaining a value from the appropriate -distribution which exceeds the computed mean square ratio.
Groups |
|
Subgroups |
|
where denotes the central -distribution with degrees of freedom and .
If any , then is set to zero, . |
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:
– double array
-
The elements of
y must contain the observations
in the following order:
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:
– int64int32nag_int array
-
The number of subgroups within group
, , for .
Constraint:
, for .
- 3:
– int64int32nag_int array
-
The numbers of observations in each subgroup,
, in the following order:
Constraint:
, that is and , for .
Optional Input Parameters
- 1:
– int64int32nag_int scalar
-
Default:
the dimension of the array
y.
, the total number of observations.
- 2:
– int64int32nag_int scalar
-
Default:
the dimension of the array
lsub.
, the number of groups.
Constraint:
.
- 3:
– int64int32nag_int scalar
-
Default:
the dimension of the array
nobs.
, the total number of subgroups.
Constraint:
.
Output Parameters
- 1:
– int64int32nag_int array
-
The total number of observations in group
, , for .
- 2:
– double array
-
The mean for group
, , for .
- 3:
– double array
-
The subgroup means,
, in the following order:
- 4:
– double scalar
-
The grand mean, .
- 5:
– double array
-
Contains the sums of squares for the analysis of variance, as follows;
- Between group sum of squares, ,
- Between subgroup within groups sum of squares, ,
- Residual sum of squares, ,
- Corrected total sum of squares, .
- 6:
– int64int32nag_int array
-
Contains the degrees of freedom attributable to each sum of squares in the analysis of variance, as follows:
- Degrees of freedom for between group sum of squares,
- Degrees of freedom for between subgroup within groups sum of squares,
- Degrees of freedom for residual sum of squares,
- Degrees of freedom for corrected total sum of squares.
- 7:
– double array
-
Contains the mean square ratios, and , for the between groups variation, and the between subgroups within groups variation, with respect to the residual, respectively.
- 8:
– double array
-
Contains the significances of the mean square ratios, and respectively.
- 9:
– int64int32nag_int scalar
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.
-
-
-
-
On entry, | , for some . |
-
-
-
-
On entry, | , for some . |
-
-
- W
-
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
-
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.
-
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 believed to be stable.
Further Comments
The time taken by nag_anova_hier2 (g04ag) increases approximately linearly with the total number of observations, .
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).
Open in the MATLAB editor:
g04ag_example
function g04ag_example
fprintf('g04ag example results\n\n');
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];
k = 2;
lsub = [int64(5); 3];
nobs = [int64(5); 3; 3; 3; 2; 3;5;3];
n = sum(nobs);
fprintf('Data values\n\n Group Subgroup Observations\n');
nsub = 0;
nlo = 1;
for i = 1:k
for j = 1:lsub(i)
nsub = nsub + 1;
nhi = nlo + nobs(nsub) - 1;
fprintf('%5d%9d ', i, j);
fprintf('%4.1f',y(nlo:nhi));
fprintf('\n');
nlo = nhi + 1;
end
end
[ngp, gbar, sgbar, gm, ss, idf, f, fp, ifail] = ...
g04ag(y, lsub, nobs);
fprintf('\nSubgroup means\n\n');
fprintf(' Group Subgroup Mean\n');
ii = 0;
for i = 1:k
for j = 1:lsub(i)
ii = ii + 1;
fprintf('%6d%8d%10.2f\n', i, j, sgbar(ii));
end
end
fprintf('\n');
fprintf('%s%5.2f%s%2d%s\n', ' Group 1 mean =', gbar(1), ...
' (', ngp(1), ' observations)');
fprintf('%s%5.2f%s%2d%s\n', ' Group 2 mean =', gbar(2), ...
' (', ngp(2), ' observations)');
fprintf('%s%5.2f%s%2d%s\n', ' Grand mean =', gm, ...
' (', n, ' observations)');
fprintf('\nAnalysis of variance table\n\n');
fprintf(' Source SS DF F ratio Sig\n\n');
fprintf('%s%6.3f%5d%7.2f%8.3f\n', 'Between groups ', ...
ss(1), idf(1), f(1), fp(1));
fprintf('%s%6.3f%5d%7.2f%8.3f\n', 'Between subgroups ', ...
ss(2), idf(2), f(2), fp(2));
fprintf('%s%6.3f%5d\n', 'Residual ', ss(3), idf(3));
fprintf('\n%s%6.3f%5d\n', 'Total ', ss(4), idf(4));
g04ag example results
Data values
Group Subgroup Observations
1 1 2.1 2.4 2.0 2.0 2.0
1 2 2.4 2.1 2.2
1 3 2.4 2.2 2.6
1 4 2.4 2.4 2.5
1 5 1.9 1.7
2 1 2.1 1.5 2.0
2 2 1.9 1.7 1.9 1.9 1.9
2 3 2.0 2.1 2.3
Subgroup means
Group Subgroup Mean
1 1 2.10
1 2 2.23
1 3 2.40
1 4 2.43
1 5 1.80
2 1 1.87
2 2 1.86
2 3 2.13
Group 1 mean = 2.21 (16 observations)
Group 2 mean = 1.94 (11 observations)
Grand mean = 2.10 (27 observations)
Analysis of variance table
Source SS DF F ratio Sig
Between groups 0.475 1 16.15 0.001
Between subgroups 0.816 6 4.63 0.005
Residual 0.559 19
Total 1.850 26
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015