G02 Chapter Contents
G02 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG02JEF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

G02JEF fits a multi-level linear mixed effects regression model using maximum likelihood (ML). Prior to calling G02JEF the initialization routine G02JCF must be called.

## 2  Specification

 SUBROUTINE G02JEF ( 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

G02JEF fits a model of the form:
 $y=Xβ+Zν+ε$
 where $y$ is a vector of $n$ observations on the dependent variable, $X$ is a known $n$ by $p$ design matrix for the fixed independent variables, $\beta$ is a vector of length $p$ of unknown fixed effects, $Z$ is a known $n$ by $q$ design matrix for the random independent variables, $\nu$ is a vector of length $q$ of unknown random effects, and $\epsilon$ is a vector of length $n$ of unknown random errors.
Both $\nu$ and $\epsilon$ are assumed to have a Gaussian distribution with expectation zero and variance/covariance matrix defined by
 $Var ν ε = G 0 0 R$
where $R={\sigma }_{R}^{2}I$, $I$ is the $n×n$ identity matrix and $G$ is a diagonal matrix. It is assumed that the random variables, $Z$, can be subdivided into $g\le q$ groups with each group being identically distributed with expectation zero and variance ${\sigma }_{i}^{2}$. The diagonal elements of matrix $G$ therefore take one of the values $\left\{{\sigma }_{i}^{2}:i=1,2,\dots ,g\right\}$, depending on which group the associated random variable belongs to.
The model therefore contains three sets of unknowns: the fixed effects $\beta$, the random effects $\nu$ and a vector of $g+1$ variance components $\gamma$, where $\gamma =\left\{{\sigma }_{1}^{2},{\sigma }_{2}^{2},\dots ,{\sigma }_{g-1}^{2},{\sigma }_{g}^{2},{\sigma }_{R}^{2}\right\}$. Rather than working directly with $\gamma$, G02JEF uses an iterative process to estimate ${\gamma }^{*}=\left\{{\sigma }_{1}^{2}/{\sigma }_{R}^{2},{\sigma }_{2}^{2}/{\sigma }_{R}^{2},\dots ,{\sigma }_{g-1}^{2}/{\sigma }_{R}^{2},{\sigma }_{g}^{2}/{\sigma }_{R}^{2},1\right\}$. Due to the iterative nature of the estimation a set of initial values, ${\gamma }_{0}$, for ${\gamma }^{*}$ is required. G02JEF 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).
G02JEF fits the model by maximizing the log-likelihood function:
 $-2 l R = log V + n log rT V-1 r + log 2 π / n$
where
 $V = ZG ZT + R, r=y-Xb and b = XT V-1 X -1 XT V-1 y .$
Once the final estimates for ${\gamma }^{*}$ have been obtained, the value of ${\sigma }_{R}^{2}$ is given by
 $σR2 = rT V-1 r / n - p .$
Case weights, ${W}_{c}$, can be incorporated into the model by replacing ${X}^{\mathrm{T}}X$ and ${Z}^{\mathrm{T}}Z$ with ${X}^{\mathrm{T}}{W}_{c}X$ and ${Z}^{\mathrm{T}}{W}_{c}Z$ respectively, for a diagonal weight matrix ${W}_{c}$.
The log-likelihood, ${l}_{R}$, 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  Arguments

Note: prior to calling G02JEF the initialization routine G02JCF must be called, therefore this documention should be read in conjunction with the document for G02JCF.
In particular some argument 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:     $\mathrm{LVPR}$ – INTEGERInput
On entry: the sum of the number of random parameters and the random intercept flags specified in the call to G02JCF.
Constraint: ${\mathbf{LVPR}}={\sum }_{i}{\mathbf{RNDM}}\left(1,i\right)+{\mathbf{RNDM}}\left(2,i\right)$.
2:     $\mathrm{VPR}\left({\mathbf{LVPR}}\right)$ – INTEGER arrayInput
On entry: a vector of flags indicating the mapping between the random variables specified in RNDM and the variance components, ${\sigma }_{i}^{2}$. See Section 9 for more details.
Constraint: $1\le {\mathbf{VPR}}\left(\mathit{i}\right)\le {\mathbf{NVPR}}$, for $\mathit{i}=1,2,\dots ,{\mathbf{LVPR}}$.
3:     $\mathrm{NVPR}$ – INTEGERInput
On entry: $g$, the number of variance components being estimated (excluding the overall variance, ${\sigma }_{R}^{2}$).
Constraint: $1\le {\mathbf{NVPR}}\le {\mathbf{LVPR}}$.
4:     $\mathrm{GAMMA}\left({\mathbf{NVPR}}+1\right)$ – REAL (KIND=nag_wp) arrayInput/Output
On entry: holds the initial values of the variance components, ${\gamma }_{0}$, with ${\mathbf{GAMMA}}\left(\mathit{i}\right)$ the initial value for ${\sigma }_{\mathit{i}}^{2}/{\sigma }_{R}^{2}$, for $\mathit{i}=1,2,\dots ,{\mathbf{NVPR}}$.
If ${\mathbf{GAMMA}}\left(1\right)=-1.0$, the remaining elements of GAMMA are ignored and the initial values for the variance components are estimated from the data using MIVQUE0.
On exit: ${\mathbf{GAMMA}}\left(\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{NVPR}}$, holds the final estimate of ${\sigma }_{\mathit{i}}^{2}$ and ${\mathbf{GAMMA}}\left({\mathbf{NVPR}}+1\right)$ holds the final estimate for ${\sigma }_{R}^{2}$.
Constraint: ${\mathbf{GAMMA}}\left(1\right)=-1.0\text{​ or ​}{\mathbf{GAMMA}}\left(\mathit{i}\right)\ge 0.0$, for $\mathit{i}=1,2,\dots ,g$.
5:     $\mathrm{EFFN}$ – INTEGEROutput
On exit: effective number of observations. If there are no weights (i.e., ${\mathbf{WEIGHT}}=\text{'U'}$), or all weights are nonzero, then ${\mathbf{EFFN}}={\mathbf{N}}$.
6:     $\mathrm{RNKX}$ – INTEGEROutput
On exit: the rank of the design matrix, $X$, for the fixed effects.
7:     $\mathrm{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 ${\mathbf{NCOV}}={\mathbf{NVPR}}$.
8:     $\mathrm{LNLIKE}$ – REAL (KIND=nag_wp)Output
On exit: $-2{l}_{R}\left(\stackrel{^}{\gamma }\right)$ where ${l}_{R}$ is the log of the maximum likelihood calculated at $\stackrel{^}{\gamma }$, the estimated variance components returned in GAMMA.
9:     $\mathrm{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 G02JEF is called.
Constraint: ${\mathbf{LB}}\ge {\mathbf{NFF}}+{\mathbf{NRF}}×{\mathbf{NLSV}}$.
10:   $\mathrm{ID}\left({\mathbf{LDID}},{\mathbf{LB}}\right)$ – INTEGER arrayOutput
On exit: an array describing the parameter estimates returned in B. The first ${\mathbf{NLSV}}×{\mathbf{NRF}}$ columns of ID describe the parameter estimates for the random effects and the last NFF columns the parameter estimates for the fixed effects.
The example program for this routine includes a demonstration of decoding the parameter estimates given in B using information from ID.
For fixed effects:
• for $l={\mathbf{NRF}}×{\mathbf{NLSV}}+1,\dots ,{\mathbf{NRF}}×{\mathbf{NLSV}}+{\mathbf{NFF}}$
• if ${\mathbf{B}}\left(l\right)$ contains the parameter estimate for the intercept then
 $ID1l = ID2l = ID3l = 0 ;$
• if ${\mathbf{B}}\left(l\right)$ contains the parameter estimate for the $i$th level of the $j$th fixed variable, that is the vector of values held in the $k$th column of DAT when ${\mathbf{FIXED}}\left(j+2\right)=k$ then
 $ID1l=0, ID2l=j, ID3l=i;$
• if the $j$th variable is continuous or binary, that is ${\mathbf{LEVELS}}\left({\mathbf{FIXED}}\left(j+2\right)\right)=1$, then ${\mathbf{ID}}\left(3,l\right)=0$;
• any remaining rows of the $l$th column of ID are set to $0$.
For random effects:
• let
• ${N}_{{R}_{b}}$ denote the number of random variables in the $b$th random statement, that is ${N}_{{R}_{b}}={\mathbf{RNDM}}\left(1,b\right)$;
• ${R}_{jb}$ denote the $j$th random variable from the $b$th random statement, that is the vector of values held in the $k$th column of DAT when ${\mathbf{RNDM}}\left(2+j,b\right)=k$;
• ${N}_{{S}_{b}}$ denote the number of subject variables in the $b$th random statement, that is ${N}_{{S}_{b}}={\mathbf{RNDM}}\left(3+{N}_{{R}_{b}},b\right)$;
• ${S}_{jb}$ denote the $j$th subject variable from the $b$th random statement, that is the vector of values held in the $k$th column of DAT when ${\mathbf{RNDM}}\left(3+{N}_{{R}_{b}}+j,b\right)=k$;
• $L\left({S}_{jb}\right)$ denote the number of levels for ${S}_{jb}$, that is $L\left({S}_{jb}\right)={\mathbf{LEVELS}}\left({\mathbf{RNDM}}\left(3+{N}_{{R}_{b}}+j,b\right)\right)$;
• then
• for $l=1,2,\dots {\mathbf{NRF}}×{\mathbf{NLSV}}$, if ${\mathbf{B}}\left(l\right)$ contains the parameter estimate for the $i$th level of ${R}_{jb}$ when ${S}_{\mathit{k}b}={s}_{\mathit{k}}$, for $\mathit{k}=1,2,\dots ,{N}_{{S}_{b}}$ and $1\le {s}_{\mathit{k}}\le L\left({S}_{jb}\right)$, i.e., ${s}_{k}$ is a valid value for the $k$th subject variable, then
 $ID1l=b, ID2l=j, ID3l=i, ID3+kl=sk, ​k=1,2,…,NSb;$
• if the parameter being estimated is for the intercept then ${\mathbf{ID}}\left(2,l\right)={\mathbf{ID}}\left(3,l\right)=0$;
• if the $j$th variable is continuous, or binary, that is $L\left({S}_{jb}\right)=1$, then ${\mathbf{ID}}\left(3,l\right)=0$;
• the remaining rows of the $l$th column of ID are set to $0$.
In some situations, certain combinations of variables are never observed. In such circumstances all elements of the $l$th row of ID are set to $-999$.
11:   $\mathrm{LDID}$ – INTEGERInput
On entry: the first dimension of the array ID as declared in the (sub)program from which G02JEF is called.
Constraint: ${\mathbf{LDID}}\ge 3+\underset{j}{\mathrm{max}}\phantom{\rule{0.25em}{0ex}}\left({\mathbf{RNDM}}\left(3+{\mathbf{RNDM}}\left(1,j\right),j\right)\right)$, i.e., $3+\text{}$ maximum number of subject variables (see G02JCF).
12:   $\mathrm{B}\left({\mathbf{LB}}\right)$ – REAL (KIND=nag_wp) arrayOutput
On exit: the parameter estimates, with the first ${\mathbf{NRF}}×{\mathbf{NLSV}}$ elements of ${\mathbf{B}}$ containing the parameter estimates for the random effects, $\nu$, and the remaining NFF elements containing the parameter estimates for the fixed effects, $\beta$. The order of these estimates are described by the ID argument.
13:   $\mathrm{SE}\left({\mathbf{LB}}\right)$ – REAL (KIND=nag_wp) arrayOutput
On exit: the standard errors of the parameter estimates given in B.
14:   $\mathrm{CZZ}\left({\mathbf{LDCZZ}},*\right)$ – REAL (KIND=nag_wp) arrayOutput
Note: the second dimension of the array CZZ must be at least ${\mathbf{NRF}}×{\mathbf{NLSV}}$ (see G02JCF).
On exit: if ${\mathbf{NLSV}}=1$, then CZZ holds the lower triangular portion of the matrix $\left(1/{\sigma }^{2}\right)\left({Z}^{\mathrm{T}}{\stackrel{^}{R}}^{-1}Z+{\stackrel{^}{G}}^{-1}\right)$, where $\stackrel{^}{R}$ and $\stackrel{^}{G}$ are the estimates of $R$ and $G$ respectively. If ${\mathbf{NLSV}}>1$ 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:   $\mathrm{LDCZZ}$ – INTEGERInput
On entry: the first dimension of the array CZZ as declared in the (sub)program from which G02JEF is called.
Constraint: ${\mathbf{LDCZZ}}\ge {\mathbf{NRF}}$.
16:   $\mathrm{CXX}\left({\mathbf{LDCXX}},*\right)$ – REAL (KIND=nag_wp) arrayOutput
Note: the second dimension of the array CXX must be at least ${\mathbf{NFF}}$ (see G02JCF).
On exit: CXX holds the lower triangular portion of the matrix $\left(1/{\sigma }^{2}\right){X}^{\mathrm{T}}{\stackrel{^}{V}}^{-1}X$, where $\stackrel{^}{V}$ is the estimated value of $V$.
17:   $\mathrm{LDCXX}$ – INTEGERInput
On entry: the first dimension of the array CXX as declared in the (sub)program from which G02JEF is called.
Constraint: ${\mathbf{LDCXX}}\ge {\mathbf{NFF}}$.
18:   $\mathrm{CXZ}\left({\mathbf{LDCXZ}},*\right)$ – REAL (KIND=nag_wp) arrayOutput
Note: the second dimension of the array CXZ must be at least ${\mathbf{NLSV}}×{\mathbf{NRF}}$ (see G02JCF).
On exit: if ${\mathbf{NLSV}}=1$, then CXZ holds the matrix $\left(1/{\sigma }^{2}\right)\left({X}^{\mathrm{T}}{\stackrel{^}{V}}^{-1}Z\right)\stackrel{^}{G}$, where $\stackrel{^}{V}$ and $\stackrel{^}{G}$ are the estimates of $V$ and $G$ respectively. If ${\mathbf{NLSV}}>1$ 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:   $\mathrm{LDCXZ}$ – INTEGERInput
On entry: the first dimension of the array CXZ as declared in the (sub)program from which G02JEF is called.
Constraint: ${\mathbf{LDCXZ}}\ge {\mathbf{NFF}}$.
20:   $\mathrm{RCOMM}\left(*\right)$ – REAL (KIND=nag_wp) arrayCommunication Array
Note: the dimension of the array RCOMM must be at least ${\mathbf{LRCOMM}}$ (see G02JCF).
On entry: communication array initialized by a call to G02JCF.
21:   $\mathrm{ICOMM}\left(*\right)$ – INTEGER arrayCommunication Array
Note: the dimension of the array ICOMM must be at least ${\mathbf{LICOMM}}$ (see G02JCF).
On entry: communication array initialized by a call to G02JCF.
22:   $\mathrm{IOPT}\left({\mathbf{LIOPT}}\right)$ – INTEGER arrayInput
On entry: optional parameters passed to the optimization routine.
By default G02JEF 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 ${\mathbf{IOPT}}\left(5\right)=1$. If ${\mathbf{LIOPT}}<5$ or ${\mathbf{IOPT}}\left(5\right)\ne 1$ then E04LBF will be used.
Different optional parameters are available depending on the optimization routine used. In all cases, using a value of $-1$ 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 $1$.
E04LBF is being used.
 $i$ Description Equivalent E04LBF argument Default Value $1$ Number of iterations MAXCAL $1000$ $2$ Unit number for monitoring information n/a As returned by X04ABF $3$ Print optional parameters ($1=$ print) n/a $-1$ (no printing performed) $4$ Frequency that monitoring information is printed IPRINT $-1$ $5$ 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.
 $i$ Description Equivalent E04UCA argument Default Value $1$ Number of iterations Major Iteration Limit $\mathrm{max}\left(50,3×{\mathbf{NVPR}}\right)$ $2$ Unit number for monitoring information n/a As returned by X04ABF $3$ Print optional parameters ($1=\text{}$ print, otherwise no print) List/Nolist $-1$ (no printing performed) $4$ Frequency that monitoring information is printed Major Print Level $0$ $5$ Optimizer used n/a n/a $6$ Number of minor iterations Minor Iteration Limit $\mathrm{max}\left(50,3×{\mathbf{NVPR}}\right)$ $7$ Frequency that additional monitoring information is printed Minor Print Level $0$
If ${\mathbf{LIOPT}}\le 0$ then default values are used for all optional parameters and IOPT is not referenced.
23:   $\mathrm{LIOPT}$ – INTEGERInput
On entry: length of the options array IOPT.
24:   $\mathrm{ROPT}\left({\mathbf{LROPT}}\right)$ – 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 $-1.0$ 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 $1$.
E04LBF is being used.
 $i$ Description Equivalent E04LBF argument Default Value $1$ Sweep tolerance n/a $\mathrm{max}\left(\sqrt{\mathrm{eps}},\sqrt{\mathrm{eps}}×\underset{i}{\mathrm{max}}\phantom{\rule{0.25em}{0ex}}\left({\mathrm{zz}}_{ii}\right)\right)$ $2$ Lower bound for ${\gamma }^{*}$ n/a $\mathrm{eps}/100$ $3$ Upper bound for ${\gamma }^{*}$ n/a ${10}^{20}$ $4$ Accuracy of linear minimizations ETA $0.9$ $5$ Accuracy to which solution is required XTOL $0.0$ $6$ Initial distance from solution STEPMX $100000.0$
E04UCA is being used.
 $i$ Description Equivalent E04UCA argument Default Value $1$ Sweep tolerance n/a $\mathrm{max}\left(\sqrt{\mathrm{eps}},\sqrt{\mathrm{eps}}×\underset{i}{\mathrm{max}}\phantom{\rule{0.25em}{0ex}}\left({\mathrm{zz}}_{ii}\right)\right)$ $2$ Lower bound for ${\gamma }^{*}$ n/a $\mathrm{eps}/100$ $3$ Upper bound for ${\gamma }^{*}$ n/a ${10}^{20}$ $4$ Line search tolerance Line Search Tolerance $0.9$ $5$ Optimality tolerance Optimality Tolerance ${\mathrm{eps}}^{0.72}$
where $\mathrm{eps}$ is the machine precision returned by X02AJF and ${\mathrm{zz}}_{ii}$ denotes the $i$ diagonal element of ${Z}^{\mathrm{T}}Z$.
If ${\mathbf{LROPT}}\le 0$ then default values are used for all optional parameters and ROPT is not referenced.
25:   $\mathrm{LROPT}$ – INTEGERInput
On entry: length of the options array ROPT.
26:   $\mathrm{IFAIL}$ – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this argument, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}=0$ or $-1$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=1$
On entry, ${\mathbf{LVPR}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{LVPR}}\ge 〈\mathit{\text{value}}〉$.
${\mathbf{IFAIL}}=2$
On entry, ${\mathbf{VPR}}\left(〈\mathit{\text{value}}〉\right)=〈\mathit{\text{value}}〉$ and ${\mathbf{NVPR}}=〈\mathit{\text{value}}〉$.
Constraint: $1\le {\mathbf{VPR}}\left(i\right)\le {\mathbf{NVPR}}$.
${\mathbf{IFAIL}}=3$
On entry, ${\mathbf{NVPR}}=〈\mathit{\text{value}}〉$.
Constraint: $1\le {\mathbf{NVPR}}\le 〈\mathit{\text{value}}〉$.
${\mathbf{IFAIL}}=4$
On entry, ${\mathbf{GAMMA}}\left(〈\mathit{\text{value}}〉\right)=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{GAMMA}}\left(1\right)=-1.0$ or ${\mathbf{GAMMA}}\left(i\right)\ge 0.0$.
${\mathbf{IFAIL}}=9$
On entry, ${\mathbf{LB}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{LB}}\ge 〈\mathit{\text{value}}〉$.
${\mathbf{IFAIL}}=11$
On entry, ${\mathbf{LDID}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{LDID}}\ge 〈\mathit{\text{value}}〉$.
${\mathbf{IFAIL}}=15$
On entry, ${\mathbf{LDCZZ}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{LDCZZ}}\ge 〈\mathit{\text{value}}〉$.
${\mathbf{IFAIL}}=17$
On entry, ${\mathbf{LDCXX}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{LDCXX}}\ge 〈\mathit{\text{value}}〉$.
${\mathbf{IFAIL}}=19$
On entry, ${\mathbf{LDCXZ}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{LDCXZ}}\ge 〈\mathit{\text{value}}〉$.
${\mathbf{IFAIL}}=21$
On entry, ICOMM has not been initialized correctly.
${\mathbf{IFAIL}}=32$
On entry, at least one value of i, for $\mathit{i}=1,2,\dots ,{\mathbf{NVPR}}$, does not appear in VPR.
${\mathbf{IFAIL}}=101$
Optimal solution found, but requested accuracy not achieved.
${\mathbf{IFAIL}}=102$
Too many major iterations.
${\mathbf{IFAIL}}=103$
Current point cannot be improved upon.
${\mathbf{IFAIL}}=104$
At least one negative estimate for GAMMA was obtained. All negative estimates have been set to zero.
${\mathbf{IFAIL}}=-99$
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{IFAIL}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{IFAIL}}=-999$
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

Not applicable.

## 8  Parallelism and Performance

G02JEF is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
G02JEF 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 routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

The argument VPR gives the mapping between the random variables and the variance components. In most cases ${\mathbf{VPR}}\left(\mathit{i}\right)=\mathit{i}$, for $\mathit{i}=1,2,\dots ,{\sum }_{\mathit{i}}{\mathbf{RNDM}}\left(1,\mathit{i}\right)+{\mathbf{RNDM}}\left(2,\mathit{i}\right)$. 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:
 $DAT= 113.6 214.5 311.1 128.3 227.2 326.1$
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
 $LEVELS=321$
also assume a model with no fixed effects, no random intercept, no nesting and all three variables being included as random effects, then
 $FIXED=00; RNDM=30123T.$
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
 $VPR=123.$
This is the recommended way of supplying the data to G02JEF, 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
 $DAT= 100103.6 010104.5 001101.1 100018.3 010017.2 001016.1$
where each column only has one level
 $LEVELS= 111111 .$
Again a model with no fixed effects, no random intercept, no nesting and all variables being included as random effects is required, so
 $FIXED=00 ; RNDM= 60123456T .$
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
 $VPR= 111223 .$
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.

## 10  Example

This example fits a random effects model with three levels of nesting to a simulated dataset with $90$ observations and $12$ variables.

### 10.1  Program Text

Program Text (g02jefe.f90)

### 10.2  Program Data

Program Data (g02jefe.d)

### 10.3  Program Results

Program Results (g02jefe.r)