NAG Library Chapter Introduction

g22 – Linear Model Specification

Note: please be advised that this chapter contains functions classed as ‘experimental’. Please see Section 3.1.1 in How to Use the NAG Library and its Documentation for further information

 Contents

1
Scope of the Chapter

The functions 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 functions 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 functions. For portability reasons these structures are not referred to directly, but through void 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 nag_blgm_handle_free (g22zac). 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 D denote a data matrix with n observations on md independent variables, denoted V1, V2, , Vmd . Let y denote a vector of n observations on a dependent variable.
A linear model, M, as the term is used in this chapter, expresses a relationship between the independent variables, Vj, and the dependent variable. This relationship can be expressed as a series of additive terms T1+ T2+ , with each term, Tt, representing either a single independent variable Vj, called the main effect of Vj, 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 Functions

3.1
G22 Handles

Once any G22 handle is no longer required the associated memory should be released by calling nag_blgm_handle_free (g22zac).
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 function that creates the G22 handle. Other optional arguments are common across all G22 handles. These are described in the documentation for nag_blgm_optset (g22zmc) and nag_blgm_optget (g22znc).

3.2
Specifying a Linear Model

Prior to specifying a linear model the data matrix, D, must be described. This is done using nag_blgm_lm_describe_data (g22ybc). The linear model, M, 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 nag_blgm_lm_formula (g22yac) and the documentation for that function describes the syntax of the formula.
In many of the functions in the NAG Library, for example the regression functions in Chapter g02, a linear model is specified directly via the design matrix, X. The design matrix is defined by the data matrix, D and the linear model, M and its construction usually requires the use of dummy variables. nag_blgm_lm_design_matrix (g22ycc) constructs the design matrix from the formula supplied to nag_blgm_lm_formula (g22yac).
The utility function nag_blgm_lm_submodel (g22ydc) can be used to obtain labels for the parameters of the model as well as a variety of information required by some of the functions in Chapter g02.

4
Functionality Index

Linear model, 
    construct design matrix nag_blgm_lm_design_matrix (g22ycc)
    data description nag_blgm_lm_describe_data (g22ybc)
    nested model nag_blgm_lm_submodel (g22ydc)
    specification from formula string nag_blgm_lm_formula (g22yac)
Service functions, 
    destroy a G22 handle nag_blgm_handle_free (g22zac)
    general option getting function nag_blgm_optget (g22znc)
    general option setting function nag_blgm_optset (g22zmc)

5
Auxiliary Functions Associated with Library Function Arguments

None.

6
Functions Withdrawn or Scheduled for Withdrawal

None.

7
References

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