NAG CL Interface
g02jfc (lmm_init)
1
Purpose
g02jfc preprocesses a dataset prior to fitting a linear mixed effects regression model via
g02jhc.
2
Specification
void |
g02jfc (void **hlmm,
void *hddesc,
void *hfixed,
Integer nrndm,
void * hrndm[],
Integer n,
const double y[],
const double wt[],
const double dat[],
Integer pddat,
Integer sddat,
Integer *fnlsv,
Integer *nff,
Integer *rnlsv,
Integer *nrf,
Integer *nvpr,
double rcomm[],
Integer lrcomm,
Integer icomm[],
Integer licomm,
NagError *fail) |
|
The function may be called by the names: g02jfc or nag_correg_lmm_init.
3
Description
g02jfc must be called prior to fitting a linear mixed effects regression model via
g02jhc.
The model is of the form:
where |
is a vector of observations on the dependent variable, |
|
is an by design matrix of fixed independent variables, |
|
is a vector of unknown fixed effects, |
|
is an by design matrix of random independent variables, |
|
is a vector of length of unknown random effects, |
|
is a vector of length of unknown random errors. |
Both
and
are assumed to have a Gaussian distribution with expectation zero and variance/covariance matrix defined by
where
,
is the
identity matrix and
is a diagonal matrix. It is assumed that the random variables,
, can be subdivided into
groups with each group being identically distributed with expectation zero and variance
. The diagonal elements of matrix
therefore take one of the values
, depending on which group the associated random variable belongs to.
The model therefore contains three sets of unknowns: the fixed effects , the random effects and a vector of variance components , where
.
Case weights can be incorporated into the model by replacing and with and respectively where is a diagonal weight matrix.
The design matrices,
and
, are constructed from an
data matrix,
, a description of the fixed independent variables,
, and a description of the random independent variables,
. See
Section 11 for further details.
4
References
Rao C R (1972) Estimation of variance and covariance components in a linear model J. Am. Stat. Assoc. 67 112–115
Wolfinger R, Tobias R and Sall J (1994) Computing Gaussian likelihoods and their derivatives for general linear mixed models SIAM Sci. Statist. Comput. 15 1294–1310
5
Arguments
-
1:
– void **
Input/Output
-
On entry: must be set to
NULL or, alternatively, an existing G22 handle may be supplied in which case
g02jfc will destroy the supplied G22 handle as if
g22zac had been called.
On exit: holds a G22 handle to the internal data structure containing a description of the model. You
must not change the G22 handle other than through the functions in
Chapters G02 or
G22.
-
2:
– void *
Input
-
On entry: a G22 handle to the internal data structure containing a description of the data matrix,
, as returned in
hddesc by
g22ybc.
-
3:
– void *
Input
-
On entry: a G22 handle to the internal data structure containing a description of the fixed part of the model
as returned in
hform by
g22yac.
If
hfixed is
NULL then the model is assumed to not have a fixed part.
-
4:
– Integer
Input
-
On entry: the number of elements used to describe the random part of the model.
Constraint:
.
-
5:
– void *
Input
-
On entry: a series of G22 handles to internal data structures containing a description of the random part of the model
as returned in
hform by
g22yac. If
,
hrndm is not referenced and may be
NULL.
-
6:
– Integer
Input
-
On entry: , the number of observations in the dataset, .
Constraint:
, where
is the value supplied in
nobs when
hddesc was created.
-
7:
– const double
Input
-
On entry: , the vector of observations on the dependent variable.
Constraint:
for at least one .
-
8:
– const double
Input
-
On entry: optionally, the diagonal elements of the weight matrix
.
If , the th observation is not included in the model and the effective number of observations is the number of observations with nonzero weights.
If weights are not provided then
wt must be set to
NULL, and the effective number of observations is
.
Constraint:
if , , for
-
9:
– const double
Input
-
Note: the th element of the matrix is stored in .
On entry: the data matrix,
. By default,
, the
th value for the
th variable, for
and
, should be supplied in
.
If the optional parameter
, described in
g22ybc, is set to
,
should be supplied in
.
If either , or , for a variable used in the model, is NaN (Not A Number) then that value is treated as missing and the whole observation is excluded from the analysis.
-
10:
– Integer
Input
-
On entry: the stride separating matrix row elements in the array
dat.
Constraints:
- if the optional parameter , described in g22ybc, is set to , ;
- otherwise .
-
11:
– Integer
Input
-
On entry: the secondary dimension of
dat.
Constraints:
- if the optional parameter , described in g22ybc, is set to , ;
- otherwise .
-
12:
– Integer *
Output
-
On exit: the number of levels for the overall subject variable in . If there is no overall subject variable, .
-
13:
– Integer *
Output
-
On exit: the number of fixed effects estimated in each of the
fnlsv subject blocks. The number of columns,
, in the design matrix
is given by
.
-
14:
– Integer *
Output
-
On exit: the number of levels for the overall subject variable in . If there is no overall subject variable, .
-
15:
– Integer *
Output
-
On exit: the number of random effects estimated in each of the
rnlsv subject blocks. The number of columns,
, in the design matrix
is given by
.
-
16:
– Integer *
Output
-
On exit:
, the number of variance components being estimated (excluding the overall variance,
).
This is defined by the number of terms in the random part of the model,
(see
Section 11 for details).
-
17:
– double
Communication Array
-
On exit: a communication array as required by the functions
g02jgc or
g02jhc.
-
18:
– Integer
Input
-
On entry: the dimension of the array
rcomm.
-
19:
– Integer
Communication Array
-
On exit: a communication array as required by the functions
g02jgc or
g02jhc.
If
licomm or
lrcomm are too small and
, then
NE_ARRAY_SIZE and
holds the minimum required value for
licomm and
holds the minimum required value for
lrcomm.
-
20:
– Integer
Input
-
On entry: the dimension of the array
icomm.
-
21:
– NagError *
Input/Output
-
The NAG error argument (see
Section 7 in the Introduction to the NAG Library CL Interface).
6
Error Indicators and Warnings
- NE_ALLOC_FAIL
-
Dynamic memory allocation failed.
See
Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
- NE_ARRAY_SIZE
-
On entry,
and
.
Constraint:
and
.
icomm is not large enough to hold the minimum array sizes.
On entry, and .
Constraint: .
On entry, and .
Constraint: .
On entry, and .
Constraint: .
On entry, and .
Constraint: .
- NE_BAD_PARAM
-
On entry, argument had an illegal value.
- NE_FIELD_UNKNOWN
-
A variable name used when creating
hfixed is not present in
hddesc.
Variable name:
.
A variable name used when creating
hrndm is not present in
hddesc.
Variable name:
.
- NE_HANDLE
-
hddesc has not been initialized or is corrupt.
hddesc is not a G22 handle as generated by
g22ybc.
hfixed has not been initialized or is corrupt.
hfixed is not a G22 handle as generated by
g22yac.
.
has not been initialized or is corrupt.
.
is not a G22 handle as generated by
g22yac.
On entry,
hlmm is not
NULL or a recognised G22 handle.
- NE_INT
-
On entry, .
Constraint: .
On entry,
and
.
Constraint:
, where
is the value supplied in
nobs when
hddesc was created.
On entry, no observations due to zero weights or missing values.
On entry, .
Constraint: .
- 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 7.5 in the Introduction to the NAG Library CL Interface for further information.
- NE_NO_LICENCE
-
Your licence key may have expired or may not have been installed correctly.
See
Section 8 in the Introduction to the NAG Library CL Interface for further information.
- NE_REAL_ARRAY
-
On entry, column
of the data matrix,
, is not consistent with information supplied in
hddesc,
.
On entry, and .
Constraint: .
- NE_ZERO_VARS
-
No model has been specified.
- NW_ARRAY_SIZE
-
On entry,
and
.
Constraint:
and
.
The minimum array sizes for
licomm and
lrcomm are held in the first two elements of
icomm repectively.
- NW_POTENTIAL_PROBLEM
-
Column of the data matrix, , required rounding more than expected when being treated as a categorical variable, .
All output is returned using the rounded value(s).
The fixed part of the model contains categorical variables, but no intercept or main effects terms have been requested.
7
Accuracy
Not applicable.
8
Parallelism and Performance
g02jfc makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
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.
None.
10
Example
This example fits a random effects model with three random submodels and two fixed effects to a simulated dataset with
observations and
variables. The model is fit using maximum likelihood (ML). Standard labels for the parameter estimates and variance components are obtained from
g22ydc. See
Section 10 in
g02jhc for an example of how to construct custom labels.
10.1
Program Text
10.2
Program Data
10.3
Program Results
11
Algorithmic Details
11.1
Fixed Effects Design Matrix,
The fixed effects design matrix,
, is constructed from the data matrix
and
, as encoded in
hfixed. Details of the construction are described in
Section 3 in
g22yac and
Section 3 in
g22ycc.
It is possible to store the cross-product matrix,
in a block diagonal form if
contains an overall subject effect,
. In this context
is defined as a main effect or interaction term that is contained in all other terms. For example, if
simplifies to
, then
. If it is advantageous to do so,
g02jfc will make use of this block diagonal structure and
fnlsv will be set to the number of levels in
, otherwise
.
11.2
Random Effects Design Matrix,
The random effects design matrix,
, is constructed from the data matrix
and
which is made up of
nrndm submodels,
, where
is encoded in
. Each submodel is made up of two parts, the random effects and a subject term. The random effects are specified as described in
Section 3 in
g22yac and the subject term is specified via the
g22yac optional parameter
. The design matrix
is constructed as described in
Section 3 in
g22ycc using a model constructed from the
nrndm submodels. As an example, if there were
submodels:
-1+V07+V08+V09 / SUBJECT = V13
-1+V05+V06 / SUBJECT = V11.V12
V03+V04 / SUBJECT = V10.V11.V12
then
would be constructed as if
g22ycc was called using the model
It should be noted that unless specified otherwise (by the inclusion of
-1) a submodel will contain an intercept. This results in a term corresponding to the subject term being included in the combined model (
V10.V11.V12 in this instance).
The above model expands out further to:
Each term in the expanded model corresponds to a variance component, so in this case,
.
When constructing
all contrast information specified when the submodels are constructed in calls to
g22yac is ignored and dummy variables are used throughout.
It is possible to store the cross-product matrix,
in a block diagonal form if
contains an overall subject effect,
. In this context
is defined as a main effect or interaction term that is contained in all other subject terms. For example, if the random effects model is constructed from
submodels with subject terms
,
and
, then
and
rnlsv will be set to the number of levels in
, otherwise
.
12
Optional Parameters
As well as the optional parameters common to all G22 handles described in
g22zmc and
g22znc, a number of additional optional parameters can be specified for a G22 handle holding the description of a linear mixed model, as returned by
g02jfc in
hlmm.
Each writeable optional parameter has an associated default value; to set any of them to a non-default value, use
g22zmc. The value of any optional parameter can be queried using
g22znc.
Most of the optional parameters described in this section are related to the behaviour
g02jhc when fitting the model. These descriptions should therefore be read in conjunction with the documentation for that function.
The remainder of this section can be skipped if you wish to use the default values for all optional parameters.
The following is a list of the optional parameters available. A full description of each optional parameter is provided in
Section 12.1.
12.1
Description of the Optional Parameters
For each option, we give a summary line, a description of the optional parameter and details of constraints.
The summary line contains:
- a parameter value,
where the letters , and denote options that take character, integer and real values respectively;
- the default value.
Keywords and character values are case and white space insensitive.
Gamma Lower Bound | | Default |
A lower bound for the elements of , where .
Gamma Upper Bound | | Default |
An upper bound for the elements of , where .
Initial Distance | | Default |
The initial distance from the solution.
- When , g02jhc passes to the solver as
stepmx.
- When , this option is ignored.
Initial Value Strategy | | Default |
Controls how
g02jhc will choose the initial values for the variance components,
, if not supplied.
- The MIVQUE0 estimates of the variance components based on the likelihood specified by are used.
- The MIVQUE0 estimates based on the maximum likelihood are used, irrespective of the value of .
See
Rao (1972) for a description of the minimum variance quadratic unbiased estimators (MIVQUE0).
By default, for small problems, and for large problems .
Constraint:
or .
defines whether
g02jhc will use the restricted maximum likelihood (REML) or the maximum likelihood (ML) when fitting the model.
Constraint:
or .
Linear Minimization Accuracy | | Default |
The accuracy of the linear minimizations.
- When , g02jhc passes to the solver as
eta.
- When , this option is ignored.
Line Search Tolerance | | Default |
The line search tolerance.
- When , this option is ignored.
- When , g02jhc passes to the solver as
.
Optional parameter enables printing of each optional parameter specification as it is supplied. suppresses this printing.
Major Iteration Limit | | Default |
The number of major iterations.
- When , g02jhc passes to the solver as
maxcal.
In this case, the default value used is .
- When , g02jhc passes to the solver as
.
In this case, the default value used is , where is the number of variance components being estimated (excluding the overall variance, ).
Major Print Level | | Default |
The frequency that monitoring information is output to
.
- When , g02jhc passes to the solver as
iprint.
In this case, the default value used is and hence no monitoring information will be output.
- When , g02jhc passes to the solver as
.
In this case, the default value used is and hence no monitoring information will be output.
Maximum Number of Threads | | Default |
Controls the maximum number of threads used by
g02jhc in a multithreaded library. By default, the maximum number of available threads are used.
In a library that is not multithreaded, this option has no effect.
Constraint:
.
Minor Iteration Limit | | Default |
The number of minor iterations.
- When , this option is ignored.
- When , g02jhc passes to the solver as
.
In this case, the default value used is , where is the number of variance components being estimated (excluding the overall variance, ).
Minor Print Level | | Default |
The frequency that additional monitoring information is output to
.
- When , this option is ignored.
- When , g02jhc passes to the solver as
.
The default value of means that no additional monitoring information will be output.
Optimality Tolerance | | Default |
The optimality tolerance.
- When , this option is ignored.
- When , g02jhc passes to the solver as
.
Parallelisation Strategy | | Default |
If
then
controls how
g02jhc is parallelised in a multithreaded library.
- g02jhc will attempt to parallelise operations involving , even if .
- g02jhc will only attempt to parallelise operations involving , if .
By default,
, however, for some models / datasets, this may be slower than using
when
.
In a library that is not multithreaded, this option has no effect.
Constraint:
or .
Solution Accuracy | | Default |
The accuracy to which the solution is required.
- When , g02jhc passes to the solver as
xtol.
- When , this option is ignored.
Controls which solver
g02jhc will use when fitting the model. By default,
is used for small problems and
, otherwise.
If
, then the solver used is the one implemented in
e04lbc and if
, then the solver used is the one implemented in
e04ucc.
Constraint:
or .
Sweep Tolerance | | Default |
The sweep tolerance used by
g02jhc when performing the sweep operation
Wolfinger et al. (1994). The default value used is
, where
.
Unit Number | | Default
|
The monitoring Nag_FileID number (as returned from
x04acc,
stdout as the default) to which
g02jhc will send any monitoring information.