NAG CL Interface
g02jhc (lmm_​fit)

Settings help

CL Name Style:


1 Purpose

g02jhc fits a multi-level linear mixed effects regression model using restricted maximum likelihood (REML) or maximum likelihood (ML). Prior to calling g02jhc the initialization function g02jfc must be called.

2 Specification

#include <nag.h>
void  g02jhc (void *hlmm, Integer nvpr, double gamma[], Integer *effn, Integer *rnkx, Integer *ncov, double *lnlike, Integer lb, double b[], double se[], double czz[], Integer pdczz, double cxx[], Integer pdcxx, double cxz[], Integer pdcxz, double rcomm[], Integer icomm[], NagError *fail)
The function may be called by the names: g02jhc or nag_correg_lmm_fit.

3 Description

g02jhc 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×p design matrix for the fixed independent variables,
β is a vector of length p of unknown fixed effects,
Z is a known n×q design matrix for the random independent variables,
ν is a vector of length q of unknown random effects,
and ε is a vector of length n of unknown random errors.
Both ν and ε are assumed to have a Gaussian distribution with expectation zero and variance/covariance matrix defined by
Var[ ν ε ] = [ G 0 0 R ]  
where R= σ 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 q groups with each group being identically distributed with expectation zero and variance σi2 . The diagonal elements of matrix G , therefore, take one of the values {σi2:i=1,2,,g} , 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 g+1 variance components γ , where γ = {σ12,σ22,, σ g-1 2 ,σg2,σR2} . Rather than working directly with γ , g02jhc uses an iterative process to estimate γ* = { σ12 / σR2 , σ22 / σR2 ,, σg-12 / σR2 , σg2 / σR2 ,1} . Due to the iterative nature of the estimation a set of initial values, γ0 , for γ* is required. g02jhc 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).
g02jhc fits the model by maximizing the restricted log-likelihood function:
-2 l R = log(|V|) + (n-p) log( r TV-1r) + log| X TV-1X| + (n-p) (1+log(2π/(n-p)))  
or the log-likelihood function:
-2 l R = log(|V|) + n log( r TV-1r) + log(2π/n)  
where
V = ZG ZT + R,   r=y-Xb   and   b = (XTV-1X)-1 XT V-1 y .  
By default the restricted log-likelihood function is used, the log-likelihood function can be chosen through the optional parameter Solver as detailed in the documentation for g02jfc.
Once the final estimates for γ * have been obtained, the value of σR2 is given by
σR2 = (rTV-1r) / (n-p) .  
Case weights, Wc , can be incorporated into the model by replacing XTX and ZTZ with XTWcX and ZTWcZ respectively, for a diagonal weight matrix Wc .
The log-likelihood, lR, 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 g02jhc the initialization function g02jfc must be called, therefore, this documentation should be read in conjunction with the document for g02jfc. In particular some argument names and conventions described in that document are also relevant here, but their definition has not been repeated. Specifically, hlmm should be interpreted identically in both functions.
1: hlmm void * Input
On entry: a G22 handle to the internal data structure containing a description of the required model as returned in hlmm by g02jfc.
2: nvpr Integer Input
On entry: g, the number of variance components being estimated (excluding the overall variance, σR2).
This should be set to the value of nvpr returned by g02jfc.
3: gamma[nvpr+1] double Input/Output
On entry: holds the initial values of the variance components, γ0 , with gamma[i-1] the initial value for σi2/σR2, for i=1,2,,nvpr.
If gamma[0]=-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: gamma[i-1], for i=1,2,,nvpr, holds the final estimate of σi2 and gamma[nvpr] holds the final estimate for σR2.
Labels for the variance components can be obtained using g22ydc.
Constraint: gamma[0]=-1.0 or gamma[i-1]0.0, for i=1,2,,g.
4: effn Integer * Output
On exit: effective number of observations. If there are no weights (i.e., wtisNULL), or all weights are nonzero, effn=n.
5: rnkx Integer * Output
On exit: the rank of the design matrix, X, for the fixed effects.
6: ncov Integer * Output
On exit: number of variance components not estimated to be zero. If none of the variance components are estimated to be zero, ncov=nvpr.
7: lnlike double * Output
On exit: - 2 lR (γ^) where lR is the log of the restricted maximum likelihood calculated at γ^ , the estimated variance components returned in gamma.
8: lb Integer Input
On entry: the dimension of the arrays b and se.
Constraint: lbfnlsv×nff+rnlsv×nrf.
9: b[lb] double Output
On exit: the parameter estimates, with the first nrf×rnlsv elements of b containing the parameter estimates for the random effects, ν, and the remaining nff×fnlsv elements containing the parameter estimates for the fixed effects, β.
Labels for the parameter estimates can be obtained using g22ydc.
10: se[lb] double Output
On exit: the standard errors of the parameter estimates given in b.
11: czz[pdczz×rnlsv×nrf] double Output
Note: where CZZ(i,j) appears in this document, it refers to the array element czz[(j-1)×pdczz+i-1].
On exit: if rnlsv=1, CZZ holds the lower triangular portion of the matrix (1/ σ 2 ) (ZTR^-1Z+G^-1) , where R^ and G^ are the estimates of R and G respectively.
If rnlsv>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 random subject variable, the next nrf columns holding the part of the matrix corresponding to the second level of the overall random subject variable etc.
If pdczz=0, czz is not referenced and may be NULL.
12: pdczz Integer Input
On entry: the stride separating matrix row elements in the array czz.
Constraints:
  • pdczz=0 or pdczznrf;
  • if pdczz=0, pdcxx=pdcxz=0.
 (see g02jfc)
13: cxx[pdcxx×fnlsv×nff] double Output
Note: where CXX(i,j) appears in this document, it refers to the array element cxx[(j-1)×pdcxx+i-1].
On exit: if fnlsv=1, CXX holds the lower triangular portion of the matrix (1/ σ 2 ) (XTV^-1X) , where V^ is the estimated value of V.
If fnlsv>1, then CXX holds this matrix in compressed form, with the first nff columns holding the part of the matrix corresponding to the first level of the overall fixed subject variable, the next nff columns holding the part of the matrix corresponding to the second level of the overall fixed subject variable, etc.
If pdcxx=0, cxx is not referenced and may be NULL.
14: pdcxx Integer Input
On entry: the stride separating matrix row elements in the array cxx.
Constraint: pdcxx=0 or pdcxxnff.  (see g02jfc)
15: cxz[pdcxz×fnlsv×nrf] double Output
Note: where CXZ(i,j) appears in this document, it refers to the array element cxz[(j-1)×pdcxz+i-1].
On exit: CXZ holds the matrix (1/σ2) (XTV^-1Z) G^ , where V^ and G^ are the estimates of V and G respectively.
If pdcxz=0, cxz is not referenced and may be NULL.
16: pdcxz Integer Input
On entry: the stride separating matrix row elements in the array cxz.
Constraint: pdcxz=0 or pdcxzfnlsv×nff.  (see )
17: rcomm[dim] double Communication Array
On entry: communication array initialized by a call to g02jfc.
18: icomm[dim] Integer Communication Array
On entry: communication array initialized by a call to g02jfc.
19: fail 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, lb=value.
Constraint: lbvalue.
On entry, pdcxx=value.
Constraint: pdcxxvalue.
On entry, pdcxz=value.
Constraint: pdcxzvalue.
On entry, pdczz=value.
Constraint: pdczzvalue.
NE_BAD_PARAM
On entry, argument value had an illegal value.
NE_HANDLE
hlmm has not been initialized or is corrupt.
hlmm is not a G22 handle as generated by g02jfc.
NE_ILLEGAL_COMM
On entry, the communication arrays, icomm and rcomm, have not been initialized correctly.
NE_INT
On entry, nvpr=value.
Constraint: nvprvalue.
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_NEG_ELEMENT
At least one negative estimate for gamma was obtained. All negative estimates have been set to zero.
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, gamma[value]=value.
Constraint: gamma[0]=-1.0 or gamma[i-1]0.0.
NW_KT_CONDITIONS
Current point cannot be improved upon.
NW_NOT_CONVERGED
Optimal solution found, but requested accuracy not achieved.
NW_TOO_MANY_ITER
Too many major iterations.

7 Accuracy

Not applicable.

8 Parallelism and Performance

g02jhc is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g02jhc 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.

9 Further Comments

If g02jgc has been called, then rather than use the values of fnlsv, nff, rnlsv, nrf and nvpr as returned by g02jfc they should be obtained by calling g02zlc. See Section 9 in g02jgc for more details.

10 Example

This example fits a random effects model with three random submodels and two fixed effects to a simulated dataset with 90 observations and 12 variables. The model is fit using restricted maximum likelihood (REML). Custom labels for the parameter estimates and variance components are then constructed from information returned by g22ydc. See g02jfc for an example that uses the standard parameter labels directly.

10.1 Program Text

Program Text (g02jhce.c)

10.2 Program Data

Program Data (g02jhce.d)

10.3 Program Results

Program Results (g02jhce.r)