NAG CL Interface
g22ydc (lm_​submodel)

Note: please be advised that this function is classed as ‘experimental’ and its interface may be developed further in the future. Please see Section 4 in How to Use the NAG Library for further information.
Settings help

CL Name Style:


1 Purpose

g22ydc produces labels for the columns of a design matrix, model parameters and a vector of column inclusion flags suitable for use with functions in Chapter G02. Thus allowing for submodels to be fit using the same design matrix.

2 Specification

#include <nag.h>
void  g22ydc (Nag_DesignMatrixReturn what, void *hform, void *hxdesc, Nag_IncludeIntercept intcpt, Integer *ip, Integer lisx, Integer isx[], Integer lplab, char *plab[], Integer lenlab, Integer lvinfo, Integer vinfo[], NagError *fail)
The function may be called by the names: g22ydc or nag_blgm_lm_submodel.

3 Description

g22ydc is a utility function for use with g22yac, g22ybc and g22ycc. It can be used to construct labels for the columns for an n×mx design matrix, X, created by g22ycc and return additional input vectors and flags required by a number of NAG Library model fitting functions.
Many of the analysis functions that require a design matrix to be supplied allow submodels to be defined through the use of a vector of ones or zeros indicating whether a column of X should be included or excluded from the analyses (see for example sx in g02dac or g02gac). This allows nested models to be fit without having to reconstructed the design matrix for each analysis.
Let M denote a model constructed by g22yac, D a data matrix as described by g22ybc and X be the corresponding design matrix constructed by g22ycc from M and D. A different model, MS is a submodel of M if each term in MS, including the mean effect (intercept term) is also present in M.
If MS is a submodel of M, you can fit MS to D using a design matrix whose columns are a subset of the columns of X.

4 References

None.

5 Arguments

1: what Nag_DesignMatrixReturn Input
On entry: controls what labels are to be produced:
what=Nag_SubModelX
Labels for a submodel are required. The submodel must be supplied in hform.
what=Nag_X
Labels for the design matrix X.
If hxdesc was returned by g02jfc in hlmm then X is the design matrix associated with the fixed parameters.
what=Nag_Z
Labels for the design matrix Z.
If hxdesc was returned by g02jfc in hlmm then Z is the part of the design matrix associated with the random parameters.
what=Nag_VarianceComponent
Labels for the variance components.
Constraints:
  • if hxdesc was returned by g02jfc in hlmm, what=Nag_X, Nag_Z or Nag_VarianceComponent;
  • otherwise what=Nag_SubModelX or Nag_X.
2: hform void * Input
On entry: a G22 handle to the internal data structure containing a description of the required submodel MS, as returned in hform by g22yac. If whatNag_SubModelX hform is not referenced and need not be set.
3: hxdesc void * Input
On entry: a G22 handle to the internal data structure containing a description of the design matrix, D.
Constraint: a G22 handle as returned by g22ycc in hxdesc or by g02jfc and g02jgc in hlmm..
4: intcpt Nag_IncludeIntercept  Output
On exit: if intcpt=Nag_Intercept, in order to fit the model MS to D using X, any analysis function should include an implicit mean effect (intercept term).
intcpt=Nag_NoIntercept, if MS does not include a mean effect or the mean effect has been explicitly included in the design matrix.
5: ip Integer * Output
On exit: p, the number of parameters in the (sub)model, including the intercept if one is present. If what=Nag_SubModelX, then the submodel is the one specified in hform otherwise the model is the one used when defining the design matrix described in hxdesc.
If lisx0, if intcpt=Nag_NoIntercept, p=i=1mxisx[i-1], otherwise p=i=1mxisx[i-1]+1.
6: lisx Integer Input
On entry: length of isx.
Constraint: lisx=0 or lisxmx, where mx is the number of columns in the design matrix X.
7: isx[lisx] Integer Output
On exit: if lisx0, an array indicating which columns of the design matrix from the model specified in hform are to be used.
isx[j-1]=0
The jth column of the design matrix, X, should not be included in the analysis.
isx[j-1]=1
The jth column of the design matrix, X, should be included in the analysis.
If lisx=0, isx is not referenced and may be NULL.
8: lplab Integer Input
On entry: the length of plab.
As pmx+1, if labels are required, using lplab=mx+1 will always be sufficient.
Constraint: lplab=0 or lplabp.
9: plab[lplab] char * Output
On exit: if lplab0, the names associated with the p parameters in the model.
If intcpt=Nag_NoIntercept, the labels in plab are also the labels for the columns of design matrix used in the analysis.
If intcpt=Nag_Intercept, columns plab[1] to plab[p-1] are the corresponding column labels.
If a mean effect is present in MS, the corresponding label is always in plab[0].
If lplab=0, plab is not referenced and may be NULL.
Note: each element of plab must be a string of length at least lenlab-1.
10: lenlab Integer Input
On entry: length of the strings allocated in plab. At most lenlab-1 non-null characters will be written into each element of plab.
Constraint: if plabis notNULL, lenlab1.
11: lvinfo Integer Input
On entry: the length of vinfo.
Let nT denote the number of terms in MS, nTt denote the number of variables in the tth term and mxt denote the number of columns of X corresponding to the tth term. The required size of vinfo, denoted a is given by:
a= t=1 nT mxt(1+3nTt).  
If the model includes a mean effect, a should be incremented by one.
The values nT, nTt and mxt are not trivial to calculate as they require the formula describing the model to be fully expanded and the contrast / dummy variable encoding to be known. Therefore, if lisx, lplab or lvinfo are too small and lvinfo3, fail.code= NW_ARRAY_SIZE is returned and the required sizes for these arrays are returned in vinfo[0], vinfo[1] and vinfo[2] respectively.
Constraint: lvinfo=0 or lvinfoa.
12: vinfo[lvinfo] Integer Output
On exit: if lvinfo0, information encoding a description of the parameters in the model.
The encoding information can be extracted as follows:
  1. (i)Set k=1.
  2. (ii)Iterate j from 1 to p.
    1. 1.Set b=vinfo[k-1].
    2. 2.Increment k.
    3. 3.Iterate i from 1 to b.
      1. (a)Set vi=vinfo[k-1].
      2. (b)Set li=vinfo[k].
      3. (c)Set ci=vinfo[k+1].
      4. (d)Increment k by 3.
    4. 4.The jth model parameter corresponds to the interaction between the b variables held in columns v1,v2,,vb of D. Therefore, b=1 indicates a main effect, b=2 a two-way interaction, etc..
      If b=0, the jth model parameter corresponds to the mean effect.
      If li=0, the corresponding variable vi is binary, ordinal or continuous. Otherwise, li is the level for the corresponding variable for model parameter j.
      ci is a numeric flag indicating the contrast used in the case of a categorical variable. With ci=0 indicating that dummy variables were used for variable vi in this term. The remaining six types of contrast; treatment contrasts (with respect to the first and last levels), sum contrasts (with respect to the first and last levels), Helmert contrasts and polynomial contrasts, as described in g22ycc, are identified by the integers one to six respectively.
If lvinfo=0, vinfo is not referenced and may be NULL.
13: 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_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
NE_BAD_PARAM
On entry, argument value had an illegal value.
NE_CONSTRAINT
Constraint: if plabis notNULL, lenlab1.
NE_FIELD_UNKNOWN
A variable name used when creating hform is not present in hxdesc.
Variable name: value.
NE_HANDLE
hform has not been initialized or is corrupt.
hform is not a G22 handle as generated by g22yac.
hxdesc has not been initialized or is corrupt.
hxdesc is not a G22 handle as generated by g22ycc.
NE_INT
On entry, lisx=value and mx=value.
Constraint: lisx=0 or lisxmx.
On entry, lplab=value and p=value.
Constraint: lplab=0 or lplabp.
On entry, lvinfo is too small.
lvinfo=value.
Constraint: lvinfo=0 or lvinfovalue.
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.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_INVALID_ENUM_RANGE
Supplied value of what is not valid for the G22 handle supplied in hxdesc.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.
NE_NOT_CONS
The model and the design matrix are not consistent.
Term: value.
This is likely due to the design matrix being constructed in the presence of either a mean effect or main effect that is not present in the model.
The model and the design matrix are not consistent. The design matrix was constructed in the presence of a mean effect and the model does not include a mean effect.
The model and the design matrix are not consistent. The model includes a term not present in the design matrix.
Term: value.
NW_ARRAY_SIZE
On entry, one or more of lisx, lplab or lvinfo are nonzero, but too small.
Minimum values are zero, or value, value and value respectively.
The minimum values are returned in the first three elements of vinfo.
NW_NOT_CONS
The model and the design matrix are not consistent. The model specifies different contrasts to those used when the design matrix was constructed. The contrasts specified in hform will be ignored.
NW_POTENTIAL_PROBLEM
hxdesc has not passed through the model fitting function. The information returned by this function may not be consistent with results returned from the model fitting function if the data has been updated after the creation of hxdesc.
The model may not be as expected.
This is due to the model not containing the categorical variable adjusted to account for no mean effect when the design matrix was constructed.
Check the value of ip is as expected. If it is not then you will need to call g22ycc to reconstruct the design matrix for the model of interest.
NW_TRUNCATED
On entry, plab is too short to hold the parameter labels. Long labels will be truncated.
The longest parameter label is value.

7 Accuracy

Not applicable.

8 Parallelism and Performance

g22ydc is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

9 Further Comments

None.

10 Example

This example performs a linear regression using g02dac. The linear regression model is defined via a text string which is parsed using g22yac and the design matrix associated with the model is generated using g22ycc. A submodel is then fit using the same design matrix.
Default parameter labels, as returned in plab are used for both models. An example of using the information returned in vinfo to construct more verbose parameter labels is given in g22ybc.
See also the examples for g22yac and g22ycc.

10.1 Program Text

Program Text (g22ydce.c)

10.2 Program Data

Program Data (g22ydce.d)

10.3 Program Results

Program Results (g22ydce.r)