NAG Library Routine Document
G02JDF
1 Purpose
G02JDF fits a multi-level linear mixed effects regression model using restricted maximum likelihood (REML). Prior to calling G02JDF the initialization routine
G02JCF must be called.
2 Specification
SUBROUTINE G02JDF ( |
LVPR, VPR, NVPR, GAMMA, EFFN, RNKX, NCOV, LNLIKE, LB, ID, LDID, B, SE, CZZ, LDCZZ, CXX, LDCXX, CXZ, LDCXZ, RCOMM, ICOMM, IOPT, LIOPT, ROPT, LROPT, IFAIL) |
INTEGER |
LVPR, VPR(LVPR), NVPR, EFFN, RNKX, NCOV, LB, ID(LDID,LB), LDID, LDCZZ, LDCXX, LDCXZ, ICOMM(*), IOPT(LIOPT), LIOPT, LROPT, IFAIL |
REAL (KIND=nag_wp) |
GAMMA(NVPR+1), LNLIKE, B(LB), SE(LB), CZZ(LDCZZ,*), CXX(LDCXX,*), CXZ(LDCXZ,*), RCOMM(*), ROPT(LROPT) |
|
3 Description
G02JDF fits a model of the form:
where |
is a vector of observations on the dependent variable, |
|
is a known by design matrix for the fixed independent variables, |
|
is a vector of length of unknown fixed effects, |
|
is a known by design matrix for the random independent variables, |
|
is a vector of length of unknown random effects, |
and |
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
. Rather than working directly with
, G02JDF uses an iterative process to estimate
. Due to the iterative nature of the estimation a set of initial values,
, for
is required. G02JDF allows these initial values either to be supplied by you or calculated from the data using the minimum variance quadratic unbiased estimators (MIVQUE0) suggested by
Rao (1972).
G02JDF fits the model by maximizing the restricted log-likelihood function:
where
Once the final estimates for
have been obtained, the value of
is given by
Case weights, , can be incorporated into the model by replacing and with and respectively, for a diagonal weight matrix .
The log-likelihood,
, is calculated using the sweep algorithm detailed in
Wolfinger et al. (1994).
4 References
Goodnight J H (1979) A tutorial on the SWEEP operator The American Statistician 33(3) 149–158
Harville D A (1977) Maximum likelihood approaches to variance component estimation and to related problems JASA 72 320–340
Rao C R (1972) Estimation of variance and covariance components in a linear model J. Am. Stat. Assoc. 67 112–115
Stroup W W (1989) Predictable functions and prediction space in the mixed model procedure Applications of Mixed Models in Agriculture and Related Disciplines Southern Cooperative Series Bulletin No. 343 39–48
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 Parameters
Note: prior to calling G02JDF the initialization routine
G02JCF must be called, therefore this documention should be read in conjunction with the document for
G02JCF.
In particular some parameter names and conventions described in that document are also relevant here, but their definition has not been repeated. Specifically,
RNDM,
WEIGHT,
N,
NFF,
NRF,
NLSV,
LEVELS,
FIXED,
DAT,
LICOMM and
LRCOMM should be interpreted identically in both routines.
- 1: LVPR – INTEGERInput
On entry: the sum of the number of random parameters and the random intercept flags specified in the call to
G02JCF.
Constraint:
.
- 2: VPR(LVPR) – INTEGER arrayInput
On entry: a vector of flags indicating the mapping between the random variables specified in
RNDM and the variance components,
. See
Section 8 for more details.
Constraint:
, for .
- 3: NVPR – INTEGERInput
On entry: , the number of variance components being estimated (excluding the overall variance, ).
Constraint:
.
- 4: GAMMA() – REAL (KIND=nag_wp) arrayInput/Output
On entry: holds the initial values of the variance components,
, with
the initial value for
, for
.
If
, the remaining elements of
GAMMA are ignored and the initial values for the variance components are estimated from the data using MIVQUE0.
On exit: , for , holds the final estimate of and holds the final estimate for .
Constraint:
, for .
- 5: EFFN – INTEGEROutput
On exit: effective number of observations. If there are no weights (i.e., ), or all weights are nonzero, then .
- 6: RNKX – INTEGEROutput
On exit: the rank of the design matrix, , for the fixed effects.
- 7: NCOV – INTEGEROutput
On exit: number of variance components not estimated to be zero. If none of the variance components are estimated to be zero, then .
- 8: LNLIKE – REAL (KIND=nag_wp)Output
On exit:
where
is the log of the restricted maximum likelihood calculated at
, the estimated variance components returned in
GAMMA.
- 9: LB – INTEGERInput
On entry: the dimension of the arrays
B and
SE and the second dimension of the array
ID as declared in the (sub)program from which G02JDF is called.
Constraint:
.
- 10: ID(LDID,LB) – INTEGER arrayOutput
On exit: an array describing the parameter estimates returned in
B. The first
columns of
ID describe the parameter estimates for the random effects and the last
NFF columns the parameter estimates for the fixed effects.
A print routine for decoding the parameter estimates given in
B using information from
ID is supplied with the example program for this routine.
For fixed effects:
- for
- if contains the parameter estimate for the intercept then
- if contains the parameter estimate for the th level of the th fixed variable, that is the vector of values held in the th column of DAT when then
- if the th variable is continuous or binary, that is , then ;
- any remaining rows of the th column of ID are set to .
For random effects:
- let
- denote the number of random variables in the th random statement, that is ;
- denote the th random variable from the th random statement, that is the vector of values held in the th column of DAT when ;
- denote the number of subject variables in the th random statement, that is ;
- denote the th subject variable from the th random statement, that is the vector of values held in the th column of DAT when ;
- denote the number of levels for , that is ;
- then
- for , if contains the parameter estimate for the th level of when
, for and , i.e., is a valid value for the th subject variable, then
- if the parameter being estimated is for the intercept then ;
- if the th variable is continuous, or binary, that is , then ;
- the remaining rows of the th column of ID are set to .
In some situations, certain combinations of variables are never observed. In such circumstances all elements of the
th row of
ID are set to
.
- 11: LDID – INTEGERInput
On entry: the first dimension of the array
ID as declared in the (sub)program from which G02JDF is called.
Constraint:
, i.e.,
maximum number of subject variables (see
G02JCF).
- 12: B(LB) – REAL (KIND=nag_wp) arrayOutput
On exit: the parameter estimates, with the first
elements of
containing the parameter estimates for the random effects,
, and the remaining
NFF elements containing the parameter estimates for the fixed effects,
. The order of these estimates are described by the
ID parameter.
- 13: SE(LB) – REAL (KIND=nag_wp) arrayOutput
On exit: the standard errors of the parameter estimates given in
B.
- 14: CZZ(LDCZZ,) – REAL (KIND=nag_wp) arrayOutput
-
Note: the second dimension of the array
CZZ
must be at least
(see
G02JCF).
On exit: if
, then
CZZ holds the lower triangular portion of the matrix
, where
and
are the estimates of
and
respectively. If
then
CZZ holds this matrix in compressed form, with the first
NRF columns holding the part of the matrix corresponding to the first level of the overall subject variable, the next
NRF columns the part corresponding to the second level of the overall subject variable etc.
- 15: LDCZZ – INTEGERInput
On entry: the first dimension of the array
CZZ as declared in the (sub)program from which G02JDF is called.
Constraint:
.
- 16: CXX(LDCXX,) – REAL (KIND=nag_wp) arrayOutput
-
Note: the second dimension of the array
CXX
must be at least
(see
G02JCF).
On exit:
CXX holds the lower triangular portion of the matrix
, where
is the estimated value of
.
- 17: LDCXX – INTEGERInput
On entry: the first dimension of the array
CXX as declared in the (sub)program from which G02JDF is called.
Constraint:
.
- 18: CXZ(LDCXZ,) – REAL (KIND=nag_wp) arrayOutput
-
Note: the second dimension of the array
CXZ
must be at least
(see
G02JCF).
On exit: if
, then
CXZ holds the matrix
, where
and
are the estimates of
and
respectively. If
then
CXZ holds this matrix in compressed form, with the first
NRF columns holding the part of the matrix corresponding to the first level of the overall subject variable, the next
NRF columns the part corresponding to the second level of the overall subject variable etc.
- 19: LDCXZ – INTEGERInput
On entry: the first dimension of the array
CXZ as declared in the (sub)program from which G02JDF is called.
Constraint:
.
- 20: RCOMM() – REAL (KIND=nag_wp) arrayCommunication Array
-
Note: the dimension of the array
RCOMM
must be at least
(see
G02JCF).
On entry: communication array initialized by a call to
G02JCF.
- 21: ICOMM() – INTEGER arrayCommunication Array
-
Note: the dimension of the array
ICOMM
must be at least
(see
G02JCF).
On entry: communication array initialized by a call to
G02JCF.
- 22: IOPT(LIOPT) – INTEGER arrayInput
On entry: optional parameters passed to the optimization routine.
By default G02JDF fits the specified model using a modified Newton optimization algorithm as implemented in
E04LBF.
In some cases, where the calculation of the derivatives is computationally expensive it may be more efficient to use a sequential QP algorithm. The sequential QP algorithm as implemented in
E04UCA
can be chosen by setting
. If
or
then
E04LBF
will be used.
Different optional parameters are available depending on the optimization routine used. In all cases, using a value of
will cause the default value to be used. In addition only the first
LIOPT values of
IOPT are used, so for example, if only the first element of
IOPT needs changing and default values for all other optional parameters are sufficient
LIOPT can be set to
.
E04LBF
is being used
|
Description | Equivalent
E04LBF parameter |
Default Value |
| Number of iterations |
MAXCAL
| |
| Unit number for monitoring information | n/a | As returned by X04ABF |
| Print optional parameters ( print) | n/a | (no printing performed) |
| Frequency that monitoring information is printed |
IPRINT
| |
| Optimizer used | n/a | n/a |
If requested, monitoring information is displayed in a similar format to that given by
E04LBF.
E04UCA
is being used
|
Description | Equivalent
E04UCA parameter |
Default Value |
| Number of iterations |
Major Iteration Limit
| |
| Unit number for monitoring information | n/a | As returned by X04ABF |
| Print optional parameters ( print, otherwise no print) |
List/Nolist
| (no printing performed) |
| Frequency that monitoring information is printed |
Major Print Level
| |
| Optimizer used | n/a | n/a |
| Number of minor iterations |
Minor Iteration Limit
| |
| Frequency that additional monitoring information is printed |
Minor Print Level
| |
- 23: LIOPT – INTEGERInput
On entry: length of the options array
IOPT. If
then
IOPT is not referenced and default values are used for all optional parameters.
- 24: ROPT(LROPT) – REAL (KIND=nag_wp) arrayInput
On entry: optional parameters passed to the optimization routine.
Different optional parameters are available depending on the optimization routine used. In all cases, using a value of
will cause the default value to be used. In addition only the first
LROPT values of
ROPT are used, so for example, if only the first element of
ROPT needs changing and default values for all other optional parameters are sufficient
LROPT can be set to
.
E04LBF
is being used
|
Description | Equivalent
E04LBF parameter |
Default Value |
| Sweep tolerance | n/a | |
| Accuracy of linear minimizations |
ETA
| |
| Accuracy to which solution is required |
XTOL
| |
| Initial distance from solution |
STEPMX
| |
E04UCA
is being used
|
Description | Equivalent
E04UCA parameter |
Default Value |
| Sweep tolerance | n/a | |
| Lower bound for | n/a | |
| Upper bound for | n/a | |
| Line search tolerance |
Line Search Tolerance
| |
| Optimality tolerance |
Optimality Tolerance
| |
where
is the
machine precision returned by
X02AJF and
denotes the
diagonal element of
.
- 25: LROPT – INTEGERInput
On entry: length of the options array
ROPT. If
then
ROPT is not referenced and default values are used for all optional parameters.
- 26: IFAIL – INTEGERInput/Output
On entry:
IFAIL must be set to
,
. If you are unfamiliar with this parameter you should refer to
Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is
.
When the value is used it is essential to test the value of IFAIL on exit.
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
6 Error Indicators and Warnings
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
Errors or warnings detected by the routine:
On entry,
LVPR is too small.
On entry, or .
On entry, | , |
or | . |
On entry, and .
On entry,
LB is too small.
On entry,
LDID is too small.
On entry,
LDCZZ is too small.
On entry,
LDCXX is too small.
On entry,
LDCXZ is too small.
On entry,
ICOMM has not been initialized.
Optimal solution found, but requested accuracy not achieved.
Too many major iterations.
Current point cannot be improved upon.
At least one negative estimate for gamma was obtained. All negative estimates have been set to zero.
7 Accuracy
Not applicable.
The parameter
VPR gives the mapping between the random variables and the variance components. In most cases
, for
. However, in some cases it might be necessary to associate more than one random variable with a single variance component, for example, when the columns of
DAT hold dummy variables.
Consider a dataset with three variables:
where the first column corresponds to a categorical variable with three levels, the next to a categorical variable with two levels and the last column to a continuous variable. So in a call to
G02JCF
also assume a model with no fixed effects, no random intercept, no nesting and all three variables being included as random effects, then
Each of the three columns in
DAT therefore correspond to a single variable and hence there are three variance components, one for each random variable included in the model, so
This is the recommended way of supplying the data to G02JDF, however it is possible to reformat the above dataset by replacing each of the categorical variables with a series of dummy variables, one for each level. The dataset then becomes
where each column only has one level
Again a model with no fixed effects, no random intercept, no nesting and all variables being included as random effects is required, so
With the data entered in this manner, the first three columns of
DAT correspond to a single variable (the first column of the original dataset) as do the next two columns (the second column of the original dataset). Therefore
VPR must reflect this
In most situations it is more efficient to supply the data to
G02JCF in terms of categorical variables rather than transform them into dummy variables.
9 Example
This example fits a random effects model with three levels of nesting to a simulated dataset with observations and variables.
9.1 Program Text
Program Text (g02jdfe.f90)
9.2 Program Data
Program Data (g02jdfe.d)
9.3 Program Results
Program Results (g02jdfe.r)