NAG Library Routine Document
g04eaf
(dummyvars)
1
Purpose
g04eaf computes orthogonal polynomial or dummy variables for a factor or classification variable.
2
Specification
Fortran Interface
Integer, Intent (In) | :: |
n,
levels,
ifact(n),
ldx | Integer, Intent (Inout) | :: |
ifail | Real (Kind=nag_wp), Intent (In) | :: |
v(*) | Real (Kind=nag_wp), Intent (Inout) | :: |
x(ldx,*) | Real (Kind=nag_wp), Intent (Out) | :: |
rep(levels) | Character (1), Intent (In) | :: |
typ |
|
C Header Interface
#include nagmk26.h
void |
g04eaf_ (
const char *typ,
const Integer *n,
const Integer *levels,
const Integer ifact[],
double x[],
const Integer *ldx,
const double v[],
double rep[],
Integer *ifail,
const Charlen length_typ) |
|
3
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.
g04eaf computes dummy variables that can then be used in the fitting of the general linear model using
g02daf.
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 routine.
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.
4
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
5
Arguments
- 1: – Character(1)Input
-
On entry: 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: – IntegerInput
-
On entry: , the number of observations for which the dummy variables are to be computed.
Constraint:
.
- 3: – IntegerInput
-
On entry: , the number of levels of the factor.
Constraint:
.
- 4: – Integer arrayInput
-
On entry: the values of the factor.
Constraint:
, for .
- 5: – Real (Kind=nag_wp) arrayOutput
-
Note: the second dimension of the array
x
must be at least
if
,
,
or
and at least
if
.
On exit: the by matrix of dummy variables, where if , , or and if .
- 6: – IntegerInput
-
On entry: the first dimension of the array
x as declared in the (sub)program from which
g04eaf is called.
Constraint:
.
- 7: – Real (Kind=nag_wp) arrayInput
-
Note: the dimension of the array
v
must be at least
if
, and at least
otherwise.
On entry: 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.
- 8: – Real (Kind=nag_wp) arrayOutput
-
On exit: the number of replications for each level of the factor,
, for .
- 9: – IntegerInput/Output
-
On entry:
ifail must be set to
,
. 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
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this argument, the recommended value is
.
When the value is used it is essential to test the value of ifail on exit.
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
6
Error Indicators and Warnings
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
x04aaf).
Errors or warnings detected by the routine:
-
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. |
-
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.
See
Section 3.9 in How to Use the NAG Library and its Documentation for further information.
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.
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 stable.
8
Parallelism and Performance
g04eaf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g04eaf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the
X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the
Users' Note for your implementation for any additional implementation-specific information.
Other routines for fitting polynomials can be found in
Chapter E02.
10
Example
Data are read in from an experiment with four treatments and three observations per treatment with the treatment coded as a factor.
g04eaf is used to compute the required dummy variables and the model is then fitted by
g02daf.
10.1
Program Text
Program Text (g04eafe.f90)
10.2
Program Data
Program Data (g04eafe.d)
10.3
Program Results
Program Results (g04eafe.r)