naginterfaces.library.blgm.lm_submodel¶
- naginterfaces.library.blgm.lm_submodel(what, hform, hxdesc, lisx, lplab, lvinfo, lenlab=210)[source]¶
lm_submodel
produces labels for the columns of a design matrix, model parameters and a vector of column inclusion flags suitable for use with functions in submodulecorreg
. Thus allowing for submodels to be fit using the same design matrix.For full information please refer to the NAG Library document for g22yd
https://www.nag.com/numeric/nl/nagdoc_28.5/flhtml/g22/g22ydf.html
- Parameters
- whatstr
Controls what labels are to be produced:
Labels for a submodel are required. The submodel must be supplied in .
Labels for the design matrix .
If was returned by
correg.lmm_init
in then is the design matrix associated with the fixed parameters.Labels for the design matrix .
If was returned by
correg.lmm_init
in then is the part of the design matrix associated with the random parameters.Labels for the variance components.
- hformHandle
A G22 handle to the internal data structure containing a description of the required submodel , as returned in by
lm_formula()
. If is not referenced and need not be set.- hxdescHandle
A G22 handle to the internal data structure containing a description of the design matrix, .
- lisxint
Length of .
- lplabint
The length of .
As , if labels are required, using will always be sufficient.
- lvinfoint
The length of .
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 , 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 , or are too small and , = 102 is returned and the required sizes for these arrays are returned in , and respectively.
- lenlabint, optional
Length of the strings allocated in . At most characters will be written into each element of .
- Returns
- intcptstr
If , in order to fit the model to using , any analysis function 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.
- ipint
, the number of parameters in the (sub)model, including the intercept if one is present. If , then the submodel is the one specified in otherwise the model is the one used when defining the design matrix described in .
If , if , , otherwise .
- isxNone or int, ndarray, shape
If , an array indicating which columns of the design matrix from the model specified in are to be used.
The th column of the design matrix, , should not be included in the analysis.
The th column of the design matrix, , should be included in the analysis.
If , is not referenced.
- plabNone or str, ndarray, shape
If , the names associated with the parameters in the model.
If , the labels in are also the labels for the columns of design matrix used in the analysis.
If , columns to are the corresponding column labels.
If a mean effect is present in , the corresponding label is always in .
If , is not referenced.
- vinfoNone or int, ndarray, shape
If , information encoding a description of the parameters in the model.
The encoding information can be extracted as follows:
Set .
Iterate from to .
Set .
Increment .
Iterate from to .
Set .
Set .
Set .
Increment by .
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
lm_design_matrix()
, are identified by the integers one to six respectively.
If , is not referenced.
- Raises
- NagValueError
- (errno )
On entry, was an illegal value.
- (errno )
Supplied value of is not valid for the G22 handle supplied in .
- (errno )
has not been initialized or is corrupt.
- (errno )
is not a G22 handle as generated by
lm_formula()
.- (errno )
A variable name used when creating is not present in .
Variable name: .
- (errno )
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.
- (errno )
The model and the design matrix are not consistent. The model includes a term not present in the design matrix.
Term: .
- (errno )
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.
- (errno )
has not been initialized or is corrupt.
- (errno )
is not a G22 handle as generated by
lm_design_matrix()
.- (errno )
On entry, and .
Constraint: or .
- (errno )
On entry, and .
Constraint: or .
- (errno )
On entry, is too short to hold the parameter labels. Long labels will be truncated.
The longest parameter label is .
- (errno )
On entry, is too small.
.
Constraint: or .
- Warns
- NagAlgorithmicWarning
- (errno )
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 will be ignored.
- (errno )
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.
- (errno )
has not passed through the model fitting function.
- (errno )
On entry, one or more of , or are nonzero, but too small.
Minimum values are zero, or , and respectively.
The minimum values are returned in the first three elements of .
- Notes
lm_submodel
is a utility function for use withlm_formula()
,lm_describe_data()
andlm_design_matrix()
. It can be used to construct labels for the columns for an design matrix, , created bylm_design_matrix()
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 should be included or excluded from the analyses (see for example in
correg.linregm_fit
orcorreg.glm_normal
). This allows nested models to be fit without having to reconstructed the design matrix for each analysis.Let denote a model constructed by
lm_formula()
, a data matrix as described bylm_describe_data()
and be the corresponding design matrix constructed bylm_design_matrix()
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 .