NAG FL Interface
g02jcf (mixeff_​hier_​init)

Note: this routine is deprecated. Replaced by g02jff.

1 Purpose

g02jcf preprocesses a dataset prior to fitting a linear mixed effects regression model of the following form via either g02jdf or g02jef.

2 Specification

Fortran Interface
Subroutine g02jcf ( weight, n, ncol, dat, lddat, levels, y, wt, fixed, lfixed, nrndm, rndm, ldrndm, nff, nlsv, nrf, rcomm, lrcomm, icomm, licomm, ifail)
Integer, Intent (In) :: n, ncol, lddat, levels(ncol), fixed(lfixed), lfixed, nrndm, rndm(ldrndm,*), ldrndm, lrcomm, licomm
Integer, Intent (Inout) :: ifail
Integer, Intent (Out) :: nff, nlsv, nrf, icomm(licomm)
Real (Kind=nag_wp), Intent (In) :: dat(lddat,*), y(n), wt(*)
Real (Kind=nag_wp), Intent (Out) :: rcomm(lrcomm)
Character (1), Intent (In) :: weight
C Header Interface
#include <nag.h>
void  g02jcf_ (const char *weight, const Integer *n, const Integer *ncol, const double dat[], const Integer *lddat, const Integer levels[], const double y[], const double wt[], const Integer fixed[], const Integer *lfixed, const Integer *nrndm, const Integer rndm[], const Integer *ldrndm, Integer *nff, Integer *nlsv, Integer *nrf, double rcomm[], const Integer *lrcomm, Integer icomm[], const Integer *licomm, Integer *ifail, const Charlen length_weight)
The routine may be called by the names g02jcf or nagf_correg_mixeff_hier_init.

3 Description

g02jcf must be called prior to fitting a linear mixed effects regression model with either g02jdf or g02jef.
The model fitting routines g02jdf and g02jef fit a model of the following form:
y=Xβ+Zν+ε  
where y is a vector of n observations on the dependent variable,
X is an n by p design matrix of fixed independent variables,
β is a vector of p unknown fixed effects,
Z is an n by q design matrix of random independent variables,
ν is a vector of length q of unknown random effects,
ε is a vector of length n of unknown random errors,
and ν and ε are Normally distributed 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.
Case weights can be incorporated into the model by replacing X and Z with Wc1/2X and Wc1/2Z respectively where Wc is a diagonal weight matrix.

4 References

None.

5 Arguments

1: weight Character(1) Input
On entry: indicates if weights are to be used.
weight='U'
No weights are used.
weight='W'
Case weights are used and must be supplied in array wt.
Constraint: weight='U' or 'W'.
2: n Integer Input
On entry: n, the number of observations.
The effective number of observations, that is the number of observations with nonzero weight (see wt for more detail), must be greater than the number of fixed effects in the model (as returned in nff).
Constraint: n1.
3: ncol Integer Input
On entry: the number of columns in the data matrix, dat.
Constraint: ncol0.
4: datlddat* Real (Kind=nag_wp) array Input
Note: the second dimension of the array dat must be at least ncol.
On entry: a matrix of data, with datij holding the ith observation on the jth variable. The two design matrices X and Z are constructed from dat and the information given in fixed (for X) and rndm (for Z).
Constraint: if levelsj1,1datijlevelsj.
5: lddat Integer Input
On entry: the first dimension of the array dat as declared in the (sub)program from which g02jcf is called.
Constraint: lddatn.
6: levelsncol Integer array Input
On entry: levelsi contains the number of levels associated with the ith variable held in dat.
If the ith variable is continuous or binary (i.e., only takes the values zero or one), then levelsi must be set to 1. Otherwise the ith variable is assumed to take an integer value between 1 and levelsi, (i.e., the ith variable is discrete with levelsi levels).
Constraint: levelsi1, for i=1,2,,ncol.
7: yn Real (Kind=nag_wp) array Input
On entry: y, the vector of observations on the dependent variable.
8: wt* Real (Kind=nag_wp) array Input
Note: the dimension of the array wt must be at least n if weight='W'.
On entry: if weight='W', wt must contain the diagonal elements of the weight matrix Wc.
If wti=0.0, the ith observation is not included in the model and the effective number of observations is the number of observations with nonzero weights.
If weight='U', wt is not referenced and the effective number of observations is n.
Constraint: if weight='W', wti0.0, for i=1,2,,n.
9: fixedlfixed Integer array Input
On entry: defines the structure of the fixed effects design matrix, X.
fixed1
The number of variables, NF, to include as fixed effects (not including the intercept if present).
fixed2
The fixed intercept flag which must contain 1 if a fixed intercept is to be included and 0 otherwise.
fixed2+i
The column of dat holding the ith fixed variable, for i=1,2,,fixed1.
See Section 9.1 for more details on the construction of X.
Constraints:
  • fixed10;
  • fixed2=0 or 1;
  • 1fixed2+incol, for i=1,2,,fixed1.
10: lfixed Integer Input
On entry: length of the vector fixed.
Constraint: lfixed2+fixed1.
11: nrndm Integer Input
On entry: the number of columns in rndm.
Constraint: nrndm>0.
12: rndmldrndm* Integer array Input
Note: the second dimension of the array rndm must be at least nrndm.
On entry: rndmij defines the structure of the random effects design matrix, Z. The bth column of rndm defines a block of columns in the design matrix Z.
rndm1b
The number of variables, NRb, to include as random effects in the bth block (not including the random intercept if present).
rndm2b
The random intercept flag which must contain 1 if block b includes a random intercept and 0 otherwise.
rndm2+ib
The column of dat holding the ith random variable in the bth block, for i=1,2,,rndm1b.
rndm3+NRbb
The number of subject variables, NSb, for the bth block. The subject variables define the nesting structure for this block.
rndm3+NRb+ib
The column of dat holding the ith subject variable in the bth block, for i=1,2,,rndm3+NRbb.
See Section 9.2 for more details on the construction of Z.
Constraints:
  • rndm1b0;
  • rndm2b=0 or 1;
  • at least one random variable or random intercept must be specified in each block, i.e., rndm1b + rndm2b > 0 ;
  • the column identifiers associated with the random variables must be in the range 1 to ncol, i.e., 1 rndm2+ib ncol , for i=1,2,,rndm1b;
  • rndm3+NRbb 0 ;
  • the column identifiers associated with the subject variables must be in the range 1 to ncol, i.e., 1 rndm3+ N R b +i b ncol , for i=1,2,,rndm3+NRbb.
13: ldrndm Integer Input
On entry: the first dimension of the array rndm as declared in the (sub)program from which g02jcf is called.
Constraint: ldrndm max b 3+NRb+NSb .
14: nff Integer Output
On exit: p, the number of fixed effects estimated, i.e., the number of columns in the design matrix X.
15: nlsv Integer Output
On exit: the number of levels for the overall subject variable (see Section 9.2 for a description of what this means). If there is no overall subject variable, nlsv=1.
16: nrf Integer Output
On exit: the number of random effects estimated in each of the overall subject blocks. The number of columns in the design matrix Z is given by q=nrf×nlsv.
17: rcommlrcomm Real (Kind=nag_wp) array Communication Array
On exit: communication array as required by the analysis routines g02jdf and g02jef.
18: lrcomm Integer Input
On entry: the dimension of the array rcomm as declared in the (sub)program from which g02jcf is called.
Constraint: lrcommnff×nrf+nrf×nrf+nrf×nlsv+nff×nff+nff+2.
19: icommlicomm Integer array Communication Array
On exit: if licomm=2, icomm1 holds the minimum required value for licomm and icomm2 holds the minimum required value for lrcomm, otherwise icomm is a communication array as required by the analysis routines g02jdf and g02jef.
20: licomm Integer Input
On entry: the dimension of the array icomm as declared in the (sub)program from which g02jcf is called.
Constraint: licomm=2 or licomm34+ NF×MFL+1+ nrndm×MNR×MRL+LRNDM+2×nrndm+ ncol+LDID×LB,
where
  • MNR = maxb N R b ,
  • MFL=maxi levels fixed2+i ,
  • MRL=maxb,i levels rndm2+ib ,
  • LDID=maxb NSb ,
  • LB=nff+nrf×nlsv, and
  • LRNDM= max b 3+NRb+NSb
21: ifail Integer Input/Output
On entry: ifail must be set to 0, -1 or 1. If you are unfamiliar with this argument you should refer to Section 4 in the Introduction to the NAG Library FL Interface for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1 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 -1 or 1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6 Error Indicators and Warnings

If on entry 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:
ifail=1
On entry, weight had an illegal value.
Constraint: weight='U' or 'W'.
ifail=2
On entry, n=value.
Constraint: n1.
ifail=3
On entry, ncol=value.
Constraint: ncol0.
ifail=4
On entry, variable j of observation i is less than 1 or greater than levelsj: i=value, j=value, value =value, levelsj=value.
ifail=5
On entry, lddat=value and n=value.
Constraint: lddatn.
ifail=6
On entry, levelsvalue=value.
Constraint: levelsi1.
ifail=8
On entry, wtvalue=value.
Constraint: wti0.0.
ifail=9
On entry, number of fixed parameters, value is less than zero.
ifail=10
On entry, lfixed=value.
Constraint: lfixedvalue.
ifail=11
On entry, nrndm=value.
Constraint: nrndm>0.
ifail=12
On entry, number of random parameters for random statement i is less than 0: i=value, number of parameters =value.
ifail=13
On entry, ldrndm=value.
Constraint: ldrndmvalue.
ifail=18
On entry, lrcomm=value.
Constraint: lrcommvalue.
ifail=20
On entry, licomm=value.
Constraint: licommvalue.
ifail=102
On entry, more fixed factors than observations, n=value.
Constraint: nvalue.
ifail=108
On entry, no observations due to zero weights.
ifail=109
On entry, invalid value for fixed intercept flag: value =value.
ifail=112
On entry, invalid value for random intercept flag for random statement i: i=value, value =value.
ifail=209
On entry, index of fixed variable j is less than 1 or greater than ncol: j=value, index =value and ncol=value.
ifail=212
On entry, must be at least one parameter, or an intercept in each random statement i: i=value.
ifail=312
On entry, index of random variable j in random statement i is less than 1 or greater than ncol: i=value, j=value, index =value and ncol=value.
ifail=412
On entry, number of subject parameters for random statement i is less than 0: i=value, number of parameters =value.
ifail=512
On entry, nesting variable j in random statement i has one level: j=value, i=value.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
ifail=-399
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
ifail=-999
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

7 Accuracy

Not applicable.

8 Parallelism and Performance

g02jcf is not threaded in any implementation.

9 Further Comments

9.1 Construction of the fixed effects design matrix, X

Let
The design matrix for the fixed effects, X, is constructed as follows:
The number of columns in the design matrix, X, is therefore given by
p= 1+ j=1 N F levels fixed 2+j -1 .  
This quantity is returned in nff.
In summary, g02jcf converts all non-binary categorical variables (i.e., where LFj>1) to dummy variables. If a fixed intercept is included in the model then the first level of all such variables is dropped. If a fixed intercept is not included in the model then the first level of all such variables, other than the first, is dropped. The variables are added into the model in the order they are specified in fixed.

9.2 Construction of random effects design matrix, Z

Let
The design matrix for the random effects, Z, is constructed as follows:
In summary, each column of rndm defines a block of consecutive columns in Z. g02jcf converts all non-binary categorical variables (i.e., where LRjb or LSjb>1) to dummy variables. All random variables defined within a column of rndm are nested within all subject variables defined in the same column of rndm. In addition each of the subject variables are nested within each other, starting with the first (i.e., each of the Rjb,j=1,2,,NRb are nested within S1b which in turn is nested within S2b, which in turn is nested within S3b, etc.).
If the last subject variable in each column of rndm are the same (i.e., SNS11 = SNS22 = = SNSbb ) then all random effects in the model are nested within this variable. In such instances the last subject variable ( SNS11 ) is called the overall subject variable. The fact that all of the random effects in the model are nested within the overall subject variable means that ZTZ is block diagonal in structure. This fact can be utilised to improve the efficiency of the underlying computation and reduce the amount of internal storage required. The number of levels in the overall subject variable is returned in nlsv=LSNS11.
If the last k subject variables in each column of rndm are the same, for k>1 then the overall subject variable is defined as the interaction of these k variables and
nlsv= j=NS1-k+1 NS1 LSj1 .  
If there is no overall subject variable then nlsv=1.
The number of columns in the design matrix Z is given by q=nrf×nlsv.

10 Example

See Section 10 in g02jdf and g02jef.