NAG CL Interface
g04eac (dummyvars)

Settings help

CL Name Style:


1 Purpose

g04eac computes orthogonal polynomial or dummy variables for a factor or classification variable.

2 Specification

#include <nag.h>
void  g04eac (Nag_DummyType type, Integer n, Integer levels, const Integer factor[], double x[], Integer tdx, const double v[], double num_reps[], NagError *fail)
The function may be called by the names: g04eac, nag_anova_dummyvars or nag_dummy_vars.

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. g04eac computes dummy variables that can then be used in the fitting of the general linear model using g02dac.
If the factor of length n has k levels then the simplest representation is to define k dummy variables, X j such that X j = 1 if the factor is at level j and 0 otherwise, for j=1,2,,k. 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, k-1 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 X j = 1 if the factor is at level j and 0 otherwise, for j=2,3,,k. Alternatively, the last level can be used as the reference level.
A second way of defining the k-1 dummy variables is to use a Helmert matrix in which levels 2 , 3 , , k are compared with the average effect of the previous levels. For example if k=4 then the contrasts would be:
1 −1 −1 −1 2 1 −1 −1 3 0 2 −1 4 0 0 3  
Thus variable j , for j=1,2,,k-1, is given by where r j is the number of replicates of level j .
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 k-1 orthogonal polynomials representing the linear, quadratic, etc. effects of the underlying variable. The orthogonal polynomial is computed using Forsythe's algorithm (see Forsythe (1957) and 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 (±1) representations are retained except that in the Helmert representation the code of level j+1 in dummy variable j 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: type Nag_DummyType Input
On entry: the type of dummy variable to be computed.
type=Nag_Poly
An orthogonal Polynomial representation is computed.
type=Nag_Helmert
A Helmert matrix representation is computed.
type=Nag_FirstLevel
The contrasts relative to the First level are computed.
type=Nag_LastLevel
The contrasts relative to the Last level are computed.
type=Nag_AllLevels
A complete set of dummy variables is computed.
Constraint: type=Nag_Poly, Nag_Helmert, Nag_FirstLevel, Nag_LastLevel or Nag_AllLevels.
2: n Integer Input
On entry: the number of observations for which the dummy variables are to be computed, n .
Constraint: nlevels .
3: levels Integer Input
On entry: the number of levels of the factor, k .
Constraint: levels2 .
4: factor[n] const Integer Input
On entry: the n values of the factor.
Constraint: 1 factor[i-1] levels , for i=1,2,,n.
5: x[n×tdx] double Output
Note: the (i,j)th element of the matrix X is stored in x[(i-1)×tdx+j-1].
On exit: the n × k * matrix of dummy variables, where k * = k - 1 if type=Nag_Poly, Nag_Helmert, Nag_FirstLevel or Nag_LastLevel and k * = k if type=Nag_AllLevels.
6: tdx Integer Input
On entry: the stride separating matrix column elements in the array x.
Constraints:
  • if type=Nag_Poly, Nag_Helmert, Nag_FirstLevel or Nag_LastLevel, tdx levels - 1 ;
  • if type=Nag_AllLevels, tdxlevels .
7: v[dim] const double Input
Note: the dimension, dim, of the array v must be at least
  • levels when type=Nag_Poly;
  • 1 otherwise.
On entry: if type=Nag_Poly, the k distinct values of the underlying variable for which the orthogonal polynomial is to be computed. If typeNag_Poly, v is not referenced.
Constraint: if type=Nag_Poly, then the k values of v must be distinct.
8: num_reps[levels] double Output
On exit: num_reps[i-1] contains the number of replications for each level of the factor, r i , for i=1,2,,k.
9: fail NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

6 Error Indicators and Warnings

NE_2_INT_ARG_LT
On entry, n = value while levels = value . These arguments must satisfy nlevels .
On entry, tdx = value while levels = value . These arguments must satisfy tdxlevels .
On entry, tdx = value while levels - 1 = value . These arguments must satisfy tdx levels - 1 .
NE_ALLOC_FAIL
Dynamic memory allocation failed.
NE_ARRAY_CONS
The contents of array v are not valid.
Constraint: all values of v must be distinct.
NE_BAD_PARAM
On entry, argument type had an illegal value.
NE_G04EA_LEVELS
All levels are not represented in array factor.
NE_G04EA_ORTHO_POLY
An orthogonal polynomial has all values zero. This will be due to some values of v being close together. This can only occur if type=Nag_Poly.
NE_INT_ARG_LT
On entry, levels must not be less than 2: levels = value .
NE_INT_ARRAY_CONS
On entry, factor[0] = value .
Constraint: 1 factor[0] levels .
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.

7 Accuracy

The computations are stable.

8 Parallelism and Performance

Background information to multithreading can be found in the Multithreading documentation.
g04eac is not threaded in any implementation.

9 Further Comments

Other functions 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. g04eac is used to compute the required dummy variables and the model is then fitted by g02dac.

10.1 Program Text

Program Text (g04eace.c)

10.2 Program Data

Program Data (g04eace.d)

10.3 Program Results

Program Results (g04eace.r)