|
NAG[g04eac] NAG[nag_dummy_vars] - Computes orthogonal polynomials or dummy variables for factor/classification variable
|
|
Calling Sequence
g04eac(dummy_type, factor, x, v, num_reps, 'n'=n, 'levels'=levels, 'tdx'=tdx, 'fail'=fail)
nag_dummy_vars(. . .)
Parameters
|
dummy_type - String;
|
|
|
On entry: the type of dummy variable to be computed.
|
|
An orthogonal Polynomial representation is computed.
|
|
A Helmert matrix representation is computed.
|
|
The contrasts relative to the First level are computed.
|
|
The contrasts relative to the Last level are computed.
|
|
A complete set of dummy variables is computed.
|
|
Constraint: "Nag_Poly", "Nag_Helmert", "Nag_FirstLevel", "Nag_LastLevel" or "Nag_AllLevels". .
|
|
|
factor - Vector(1..n, datatype=integer[kernelopts('wordsize')/8]);
|
|
|
On entry: the values of the factor.
|
|
Constraint: , for . .
|
|
|
x - Matrix(1..n, 1..tdx, datatype=float[8], order=C_order);
|
|
|
|
v - Vector(1.. , datatype=float[8]);
|
|
|
Constraint: if , then the values of v must be distinct .
|
|
|
num_reps - Vector(1..levels, datatype=float[8]);
|
|
|
|
'n'=n - integer; (optional)
|
|
|
Default value: the first dimension of the arrays factor, x.
|
|
On entry: the number of observations for which the dummy variables are to be computed, .
|
|
Constraint: . .
|
|
|
'levels'=levels - integer; (optional)
|
|
|
Default value: the first dimension of the array num_reps and the second dimension of the array num_repsthe array x.
|
|
On entry: the number of levels of the factor, .
|
|
Constraint: . .
|
|
|
'tdx'=tdx - integer; (optional)
|
|
|
On entry: the second dimension of the array x as declared in the function from which nag_dummy_vars (g04eac) is called.
|
|
if .
|
|
|
'fail'=fail - table; (optional)
|
|
|
The NAG error argument, see the documentation for NagError.
|
|
|
|
Description
|
|
|
Purpose
|
|
nag_dummy_vars (g04eac) computes orthogonal polynomial or dummy variables for a factor or classification variable.
|
|
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_dummy_vars (g04eac) computes dummy variables that can then be used in the fitting of the general linear model using g02dac (nag_regsn_mult_linear).
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 0 otherwise, ,..., . 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 0 otherwise, . 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 , 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 (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 representations are retained except that in the Helmert representation the code of level in dummy variable will be a fraction.
|
|
Error Indicators and Warnings
|
|
"NE_2_INT_ARG_LT"
On entry, while . These arguments must satisfy .
"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 dummy_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 .
"NE_INT_ARG_LT"
On entry, levels must not be less than 2: .
"NE_INT_ARRAY_CONS"
On entry, . Constraint: .
"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 consult NAG for assistance.
|
|
Accuracy
|
|
The computations are stable.
|
|
Further Comments
|
|
Other functions for fitting polynomials can be found in Chapter e02.
|
|
|
Examples
|
|
>
|
dummy_type := "Nag_AllLevels":
n := 12:
levels := 4:
tdx := 4:
factor_val := Vector([1, 4, 2, 3, 4, 2, 4, 1, 3, 1, 3, 2], datatype=integer[kernelopts('wordsize')/8]):
x := Matrix(12, 4, datatype=float[8], order='C_order'):
v := Vector([0], datatype=float[8]):
num_reps := Vector(4, datatype=float[8]):
NAG:-g04eac(dummy_type, factor_val, x, v, num_reps, 'n' = n, 'levels' = levels, 'tdx' = tdx):
|
|
|
See Also
|
|
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
g04 Chapter Introduction.
NAG Toolbox Overview.
NAG Web Site.
|
|