Note: please be advised that this routine 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.
g22ydf produces labels for the columns of a design matrix, model parameters and a vector of column inclusion flags suitable for use with routines in Chapter G02. Thus allowing for submodels to be fit using the same design matrix.
The routine may be called by the names g22ydf or nagf_blgm_lm_submodel.
g22ydf is a utility routine for use with g22yaf,g22ybfandg22ycf. It can be used to construct labels for the columns for an design matrix, , created by g22ycf and return additional input vectors and flags required by a number of NAG Library model fitting routines.
Many of the analysis routines 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 should be included or excluded from the analyses (see for example isx in g02daforg02gaf). This allows nested models to be fit without having to reconstructed the design matrix for each analysis.
Let denote a model constructed by g22yaf, a data matrix as described by g22ybf and be the corresponding design matrix constructed by g22ycf from and . A different model, is a submodel of if each term in , including the mean effect (intercept term) is also present in .
If is a submodel of , you can fit to using a design matrix whose columns are a subset of the columns of .
1: – Character(*)Input
On entry: controls what labels are to be produced:
Labels for a submodel are required. The submodel must be supplied in hform.
Labels for the design matrix .
If hxdesc was returned by g02jff in hlmm then is the design matrix associated with the fixed parameters.
Labels for the design matrix .
If hxdesc was returned by g02jff in hlmm then is the part of the design matrix associated with the random parameters.
On exit: if , in order to fit the model to using , any analysis routine should include an implicit mean effect (intercept term).
, if does not include a mean effect or the mean effect has been explicitly included in the design matrix.
5: – IntegerOutput
On exit: , the number of parameters in the (sub)model, including the intercept if one is present. If , then the submodel is the one specified in hform otherwise the model is the one used when defining the design matrix described in hxdesc.
Let denote the number of terms in , denote the number of variables in the th term and denote the number of columns of corresponding to the th term. The required size of vinfo, denoted is given by:
If the model includes a mean effect, should be incremented by one.
The values , and 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 , is returned and the required sizes for these arrays are returned in , and respectively.
11: – Integer arrayOutput
On exit: if , information encoding a description of the parameters in the model.
The encoding information can be extracted as follows:
(ii)Iterate from to .
3.Iterate from to .
(d)Increment by .
4.The th model parameter corresponds to the interaction between the variables held in columns of . Therefore, indicates a main effect, a two-way interaction, etc..
If , the th model parameter corresponds to the mean effect.
If , the corresponding variable is binary, ordinal or continuous. Otherwise, is the level for the corresponding variable for model parameter .
is a numeric flag indicating the contrast used in the case of a categorical variable. With indicating that dummy variables were used for variable 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 g22ycf, are identified by the integers one to six respectively.
On entry: ifail must be set to , or to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of means that an error message is printed while a value of means that it is not.
If halting is not appropriate, the value or is recommended. If message printing is undesirable, then the value is recommended. Otherwise, the value is recommended. When the value or 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).
6Error 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, was an illegal value.
Supplied value of what is not valid for the G22 handle supplied in hxdesc.
A variable name used when creating hform is not present in hxdesc. Variable name: .
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: .
The model and the design matrix are not consistent. Term: . 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 model specifies different contrasts to those used when the design matrix was constructed. The contrasts specified in hform will be ignored.
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 g22ycf to reconstruct the design matrix for the model of interest.
hxdesc has not passed through the model fitting routine. The information returned by this routine may not be consistent with results returned from the model fitting routine if the data has been updated after the creation of hxdesc.
On entry, and . Constraint: or .
On entry, and . Constraint: or .
On entry, plab is too short to hold the parameter labels. Long labels will be truncated. The longest parameter label is .
On entry, one or more of lisx, lplab or lvinfo are nonzero, but too small. Minimum values are zero, or , and respectively. The minimum values are returned in the first three elements of vinfo.
An unexpected error has been triggered by this routine. Please
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.
8Parallelism and Performance
g22ydf 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 routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.
This example performs a linear regression using g02daf. The linear regression model is defined via a text string which is parsed using g22yaf and the design matrix associated with the model is generated using g22ycf. 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 g22ybf.