NAG Library Chapter Introduction
G22 (blgm)
Linear Model Specification
1
Scope of the Chapter
The routines in this chapter provide a mechanism for specifying a linear model using a text based modelling language and are intended to be used in conjunction with the model fitting routines from other chapters, for example
Chapter G02.
2
Background to the Problems
2.1
G22 Handles
Chapter G22 makes heavy use of data structures for passing information between routines. For portability reasons these structures are not referred to directly, but through C pointers. Throughout the documentation these pointers are referred to as G22 handles.
Once the G22 handle is no longer required the associated memory should be released by calling
g22zaf. It is always safe to release the memory associated with a G22 handle as no G22 handle will ever reference another.
2.2
Specifying a Linear Model
Let denote a data matrix with observations on independent variables, denoted . Let denote a vector of observations on a dependent variable.
A linear model, , as the term is used in this chapter, expresses a relationship between the independent variables, , and the dependent variable. This relationship can be expressed as a series of additive terms , with each term, , representing either a single independent variable , called the main effect of , or the interaction between two or more independent variables. An interaction term, denoted here using the operator, allows the effect of an independent variable on the dependent variable to depend on the value of one or more other independent variables.
3
Recommendations on Choice and Use of Available Routines
3.1
G22 Handles
Once any G22 handle is no longer required the associated memory should be released by calling
g22zaf.
All G22 handles have optional arguments associated with them. Some of these optional arguments are specific to a particular type of G22 handle and are described in the documentation of the routine that creates the G22 handle. Other optional arguments are common across all G22 handles. These are described in the documentation for
g22zmf and
g22znf which can be used to set and get an optional argument respectively.
3.2
Specifying a Linear Model
Prior to specifying a linear model the data matrix,
, must be described. This is done using
g22ybf. The linear model,
, can then be specified as a text string containing a formula. This allows the model to be specified via variable names and avoids the need to explicitly handle interaction terms. The linear model is specified using
g22yaf and the documentation for that routine describes the syntax of the formula.
In many of the routines in the NAG Library, for example the regression routines in
Chapter G02, a linear model is specified directly via the design matrix,
. The design matrix is defined by the data matrix,
and the linear model,
and its construction usually requires the use of dummy variables.
g22ycf constructs the design matrix from the formula supplied to
g22yaf.
The utility routine
g22ydf can be used to obtain labels for the parameters of the model as well as a variety of information required by some of the routines in
Chapter G02.
4
Functionality Index
construct design matrix | | g22ycf |
specification from formula string | | g22yaf |
general option getting routine | | g22znf |
general option setting routine | | g22zmf |
5
Auxiliary Routines Associated with Library Routine Arguments
None.
6
Routines Withdrawn or Scheduled for Withdrawal
None.
7
References
None.