NAG Library Function Document

nag_blgm_lm_submodel (g22ydc)

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

 Contents

    1  Purpose
    7  Accuracy

1
Purpose

nag_blgm_lm_submodel (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>
#include <nagg22.h>
void  nag_blgm_lm_submodel (void *hform, void *hxdesc, Nag_IncludeIntercept *intcpt, Integer *ip, Integer lisx, Integer isx[], Integer lplab, const char *plab[], Integer lenlab, Integer lvinfo, Integer vinfo[], NagError *fail)

3
Description

nag_blgm_lm_submodel (g22ydc) is a utility function for use with nag_blgm_lm_formula (g22yac), nag_blgm_lm_describe_data (g22ybc) and nag_blgm_lm_design_matrix (g22ycc). It can be used to construct labels for the columns for an n×mx design matrix, X, created by nag_blgm_lm_design_matrix (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 nag_regsn_mult_linear (g02dac) or nag_glm_normal (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 nag_blgm_lm_formula (g22yac), D a data matrix as described by nag_blgm_lm_describe_data (g22ybc) and X be the corresponding design matrix constructed by nag_blgm_lm_design_matrix (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:     hform void *Input
On entry: a G22 handle to the internal data structure containing a description of the required (sub)model MS, as returned in hform by nag_blgm_lm_formula (g22yac).
2:     hxdesc void *Input
On entry: a G22 handle to the internal data structure containing a description of the design matrix, D, as returned in hxdesc by nag_blgm_lm_design_matrix (g22ycc).
3:     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.
4:     ip Integer *Output
On exit: p, the number of parameters in the model specified in hform, including the intercept if one is present.
If lisx0, if intcpt=Nag_NoIntercept, p=i=1mxisx[i-1], otherwise p=i=1mxisx[i-1]+1.
5:     lisx IntegerInput
On entry: length of isx.
Constraint: lisx=0 or lisxmx, where mx is the number of columns in the design matrix X.
6:     isx[lisx] IntegerOutput
On exit: if lisx0, an array indicating which columns of the design matrix form the model specified in hform.
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.
7:     lplab IntegerInput
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.
8:     plab[lplab] const 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.
9:     lenlab IntegerInput
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.
10:   lvinfo IntegerInput
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 mxt1+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.
11:   vinfo[lvinfo] IntegerOutput
On exit: if lvinfo0, information encoding a description of the parameters in the model.
The encoding information can be extracted as follows:
(i) Set k=1.
(ii) Iterate j from 1 to p.
1. Set b=vinfo[k-1].
2. Increment k.
3. Iterate i from 1 to b.
(a) Set vi=vinfo[k-1].
(b) Set li=vinfo[k].
(c) Set ci=vinfo[k+1].
(d) Increment k by 3.
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 nag_blgm_lm_design_matrix (g22ycc), are identified by the integers one to six respectively.
If lvinfo=0, vinfo is not referenced and may be NULL.
12:   fail NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

6
Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
NE_BAD_PARAM
On entry, argument value had an illegal value.
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 nag_blgm_lm_formula (g22yac).
hxdesc has not been initialized or is corrupt.
hxdesc is not a G22 handle as generated by nag_blgm_lm_design_matrix (g22ycc).
NE_INT
On entry, lenlab=value.
Constraint: lenlab1.
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 2.7.6 in How to Use the NAG Library and its Documentation for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 2.7.5 in How to Use the NAG Library and its Documentation 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_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

nag_blgm_lm_submodel (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 nag_regsn_mult_linear (g02dac). The linear regression model is defined via a text string which is parsed using nag_blgm_lm_formula (g22yac) and the design matrix associated with the model is generated using nag_blgm_lm_design_matrix (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 Section 10 in nag_blgm_lm_describe_data (g22ybc).
See also the examples for nag_blgm_lm_formula (g22yac) and nag_blgm_lm_design_matrix (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)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017