PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_anova_dummyvars (g04ea)
Purpose
nag_anova_dummyvars (g04ea) computes orthogonal polynomial or dummy variables for a factor or classification variable.
Syntax
Description
In the analysis of an experimental design using a general linear model the factors or classification variables that specify the design have to be coded as dummy variables.
nag_anova_dummyvars (g04ea) computes dummy variables that can then be used in the fitting of the general linear model using
nag_correg_linregm_fit (g02da).
If the factor of length has levels then the simplest representation is to define dummy variables, such that if the factor is at level and otherwise for . However, there is usually a mean included in the model and the sum of the dummy variables will be aliased with the mean. To avoid the extra redundant argument dummy variables can be defined as the contrasts between one level of the factor, the reference level, and the remaining levels. If the reference level is the first level then the dummy variables can be defined as if the factor is at level and otherwise, for . Alternatively, the last level can be used as the reference level.
A second way of defining the
dummy variables is to use a Helmert matrix in which levels
are compared with the average effect of the previous levels. For example if
then the contrasts would be:
Thus variable
, for
is given by
- if factor is at level less than
- if factor is at level
- if factor is at level greater than
where
is the number of replicates of level
If the factor can be considered as a set of values from an underlying continuous variable then the factor can be represented by a set of
orthogonal polynomials representing the linear, quadratic etc. effects of the underlying variable. The orthogonal polynomial is computed using Forsythe's algorithm (
Forsythe (1957), see also
Cooper (1968)). The values of the underlying continuous variable represented by the factor levels have to be supplied to the function.
The orthogonal polynomials are standardized so that the sum of squares for each dummy variable is one. For the other methods integer () representations are retained except that in the Helmert representation the code of level in dummy variable will be a fraction.
References
Cooper B E (1968) Algorithm AS 10. The use of orthogonal polynomials Appl. Statist. 17 283–287
Forsythe G E (1957) Generation and use of orthogonal polynomials for data fitting with a digital computer J. Soc. Indust. Appl. Math. 5 74–88
Parameters
Compulsory Input Parameters
- 1:
– string (length ≥ 1)
-
The type of dummy variable to be computed.
- If , an orthogonal Polynomial representation is computed.
- If , a Helmert matrix representation is computed.
- If , the contrasts relative to the First level are computed.
- If , the contrasts relative to the Last level are computed.
- If , a Complete set of dummy variables is computed.
Constraint:
, , , or .
- 2:
– int64int32nag_int scalar
-
, the number of levels of the factor.
Constraint:
.
- 3:
– int64int32nag_int array
-
The values of the factor.
Constraint:
, for .
- 4:
– double array
-
The dimension of the array
v
must be at least
if
, and at least
otherwise
If
, the
distinct values of the underlying variable for which the orthogonal polynomial is to be computed.
If
,
v is not referenced.
Constraint:
if
, the
values of
v must be distinct.
Optional Input Parameters
- 1:
– int64int32nag_int scalar
-
Default:
the dimension of the array
ifact.
, the number of observations for which the dummy variables are to be computed.
Constraint:
.
Output Parameters
- 1:
– double array
-
The first dimension of the array
x will be
.
The second dimension of the array
x will be
if
,
,
or
and at least
if
.
The by matrix of dummy variables, where if , , or and if .
- 2:
– double array
-
The number of replications for each level of the factor,
, for .
- 3:
– 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, | , |
or | , |
or | , |
or | , , , or . |
-
-
On entry, | a value of ifact is not in the range , for , |
or | and not all values of v are distinct, |
or | not all levels are represented in ifact. |
- W
-
An orthogonal polynomial has all values zero. This will be due to some values of
v being very close together. Note this can only occur if
.
-
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 stable.
Further Comments
Other functions for fitting polynomials can be found in
Chapter E02.
Example
Data are read in from an experiment with four treatments and three observations per treatment with the treatment coded as a factor.
nag_anova_dummyvars (g04ea) is used to compute the required dummy variables and the model is then fitted by
nag_correg_linregm_fit (g02da).
Open in the MATLAB editor:
g04ea_example
function g04ea_example
fprintf('g04ea example results\n\n');
typ = 'C';
n1 = int64(1);
levels = 4*n1;
ifact = [ n1; 4; 2; 3; 4; 2;
4; 1; 3; 1; 3; 2];
y = [ 33.63 39.62 38.18 41.46 38.02 35.83 ...
35.99 36.58 42.92 37.80 40.43 37.89];
v = [0];
[x, rep, ifail] = g04ea( ...
typ, levels, ifact, v);
m = levels;
isx = ones(m,1,'int64');
mean_p = 'M';
ip = int64(m+1);
[rss, idf, b, se, covar, res, h, q, svd, irank, p, wk, ifail] = ...
g02da(mean_p, x, isx, ip, y);
if svd
fprintf('Model not of full rank, rank = %4d\n\n', irank);
end
fprintf('Residual sum of squares = %12.3e\n', rss);
fprintf('Degrees of freedom = %4d\n', idf);
fprintf('\nVariable Parameter estimate Standard error\n\n');
ivar = double([1:ip]');
fprintf('%6d%20.4e%17.4e\n',[ivar b se]');
g04ea example results
Model not of full rank, rank = 4
Residual sum of squares = 2.223e+01
Degrees of freedom = 8
Variable Parameter estimate Standard error
1 3.0557e+01 3.8494e-01
2 5.4467e+00 8.3896e-01
3 6.7433e+00 8.3896e-01
4 1.1047e+01 8.3896e-01
5 7.3200e+00 8.3896e-01
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015