Main Page | Directories | File List | Globals

lmer.c File Reference

#include "lmer.h"

Defines

#define BLK(i, j)   INTEGER(VECTOR_ELT(VECTOR_ELT(Parent, i), 1))[j]
#define PAR(i, j)   INTEGER(VECTOR_ELT(VECTOR_ELT(Parent, i), 0))[j]

Functions

static R_INLINE int coef_length (int nf, const int nc[])
SEXP lmer_validate (SEXP x)
static SEXP lmer_crosstab (SEXP flist, int nobs, const int nc[])
SEXP lmer_update_mm (SEXP x, SEXP mmats)
SEXP lmer_create (SEXP flist, SEXP mmats)
SEXP lmer_initial (SEXP x)
SEXP lmer_inflate (SEXP x)
static R_INLINE int * block_parent (int j, int n, int par[], SEXP ParP)
SEXP lmer_factor (SEXP x)
static void lmer_sm (char side, char trans, int nf, const int Gp[], int n, double alpha, SEXP L, double B[], int ldb)
static int max_nnz (int j, SEXP Parent)
static void fill_nnz (int i, int j, int nf, SEXP Parent, const int nc[], int nnz[], double *tmp[], int *ind[])
static R_INLINE int fsrch (int target, const int vals[], int nvals)
SEXP lmer_invert (SEXP x)
SEXP lmer_sigma (SEXP x, SEXP REML)
SEXP lmer_coef (SEXP x, SEXP Unc)
SEXP lmer_coefGets (SEXP x, SEXP coef, SEXP Unc)
SEXP lmer_fixef (SEXP x)
SEXP lmer_ranef (SEXP x)
SEXP lmer_firstDer (SEXP x, SEXP val)
static SEXP EM_grad_array (int nf, const int nc[])
static double * EM_grad_lc (double *cc, int EM, int REML, int ns[])
static void EMsteps_verbose_print (SEXP x, int iter, int REML, SEXP firstDer, SEXP val)
SEXP lmer_ECMEsteps (SEXP x, SEXP nsteps, SEXP REMLp, SEXP Verbp)
SEXP lmer_gradient (SEXP x, SEXP REMLp, SEXP Uncp)
static SEXP lmer_secondDer (SEXP x, SEXP Valp)
SEXP lmer_variances (SEXP x)
SEXP lmer_Crosstab (SEXP flist)

Define Documentation

#define BLK (  i,
j   )     INTEGER(VECTOR_ELT(VECTOR_ELT(Parent, i), 1))[j]
 

Fill the nnz array with the number of nonzero inner blocks in each outer block of the jth inner column block of the ith outer block of L^{-1}. Also allocate the tmp and ind arrays and fill the ind array.

Parameters:
i outer block index
j inner block index within the ith outer block
nf number of factors
Parent pointer to the extended parent pairs
nc 
nnz array of length nf
tmp array of length nf of pointers to doubles
ind array of length nf of pointers to ints

#define PAR (  i,
j   )     INTEGER(VECTOR_ELT(VECTOR_ELT(Parent, i), 0))[j]
 


Function Documentation

static R_INLINE int* block_parent (  int  j,
int  n,
int  par[],
SEXP  ParP
)  [static]
 

Convert the extended parent pair (Parent, Block) to a parent array for the jth diagonal block of size n.

Parameters:
j index (0-based) of the diagonal outer block
n number of inner column blocks in the outer block
par array of length n to be filled with the parent array
ParP pointer to the extended parent structure
Returns:
par

static R_INLINE int coef_length (  int  nf,
const int  nc[]
)  [static]
 

Calculate the length of the parameter vector (historically called "coef" even though these are not coefficients).

Parameters:
nf number of factors
nc number of columns in the model matrices for each factor
Returns:
total length of the coefficient vector

static SEXP EM_grad_array (  int  nf,
const int  nc[]
)  [static]
 

Return a length nf list of arrays of dimension (nci, nci, 4). The values of these arrays are assigned in lmer_firstDer.

Parameters:
nf number of factors
nc vector of number of columns per factor
Returns:
pointer to a list of REAL arrays

static double* EM_grad_lc (  double *  cc,
int  EM,
int  REML,
int  ns[]
)  [static]
 

Fill in the 4-dimensional vector of linear combinations of the firstDer array according to whether ECME steps or the gradient are needed and to whether or not REML is being used.

Parameters:
cc coefficient vector to be filled in
EM non-zero for ECME steps, zero for gradient
REML non-zero for REML, zero for ML
ns ns[0] is p+1, ns[1] is n
Returns:
cc with the coefficients filled in

static void EMsteps_verbose_print (  SEXP  x,
int  iter,
int  REML,
SEXP  firstDer,
SEXP  val
)  [static]
 

Print the verbose output in the ECME iterations

Parameters:
x pointer to an ssclme object
iter iteration number
REML non-zero for REML, zero for ML
firstDer arrays for calculating ECME steps and the first derivative
val Pointer to a list of arrays to receive the calculated values

static void fill_nnz (  int  i,
int  j,
int  nf,
SEXP  Parent,
const int  nc[],
int  nnz[],
double *  tmp[],
int *  ind[]
)  [static]
 

static R_INLINE int fsrch (  int  target,
const int  vals[],
int  nvals
)  [static]
 

SEXP lmer_coef (  SEXP  x,
SEXP  Unc
) 
 

Extract the upper triangles of the Omega matrices. These aren't "coefficients" but the extractor is called coef for historical reasons. Within each group these values are in the order of the diagonal entries first then the strict upper triangle in row order.

Parameters:
x pointer to an lme object
Unc pointer to a logical scalar indicating if the parameters are in the unconstrained form.
Returns:
numeric vector of the values in the upper triangles of the Omega matrices

SEXP lmer_coefGets (  SEXP  x,
SEXP  coef,
SEXP  Unc
) 
 

Assign the upper triangles of the Omega matrices. (Called coef for historical reasons.)

Parameters:
x pointer to an lme object
coef pointer to an numeric vector of appropriate length
Unc pointer to a logical scalar indicating if the parameters are in the unconstrained form.
Returns:
R_NilValue

SEXP lmer_create (  SEXP  flist,
SEXP  mmats
) 
 

Create an lmer object from a list of grouping factors and a list of model matrices. There is one more model matrix than grouping factor. The last model matrix is the fixed effects and the response.

Parameters:
facs pointer to a list of grouping factors
ncv pointer to a list of model matrices
Returns:
pointer to an lmer object

SEXP lmer_Crosstab (  SEXP  flist  ) 
 

static SEXP lmer_crosstab (  SEXP  flist,
int  nobs,
const int  nc[]
)  [static]
 

Create the pairwise crosstabulation of the elements of flist.

Parameters:
flist pointer to the factor list.
nobs number of observations.
nc number of columns in the model matrices.
Returns:
the pairwise crosstabulation in the form of the ZtZ array.

SEXP lmer_ECMEsteps (  SEXP  x,
SEXP  nsteps,
SEXP  REMLp,
SEXP  Verbp
) 
 

Perform ECME steps for the REML or ML criterion.

Parameters:
x pointer to an ssclme object
nsteps pointer to an integer scalar - the number of ECME steps to perform
REMLp pointer to a logical scalar indicating if REML is to be used
verb pointer to a logical scalar indicating verbose output
Returns:
R_NilValue if verb == FALSE, otherwise a list of iteration numbers, deviances, parameters, and gradients.

SEXP lmer_factor (  SEXP  x  ) 
 

If status[["factored"]] is FALSE, create and factor Z'Z+Omega. Also create RZX and RXX, the deviance components, and the value of the deviance for both ML and REML.

Parameters:
x pointer to an lmer object
Returns:
NULL

SEXP lmer_firstDer (  SEXP  x,
SEXP  val
) 
 

Fill in four symmetric matrices for each level, providing the information to generate the gradient or the ECME step. The four matrices are 1) -m_i^{-1} 2) 3) [{}(+)] 4) The term added to 3) to get [{}]

Parameters:
x pointer to an lme object
val pointer to a list of matrices of the correct sizes
Returns:
val

SEXP lmer_fixef (  SEXP  x  ) 
 

Extract the conditional estimates of the fixed effects

Parameters:
x Pointer to an lme object
Returns:
a numeric vector containing the conditional estimates of the fixed effects

SEXP lmer_gradient (  SEXP  x,
SEXP  REMLp,
SEXP  Uncp
) 
 

SEXP lmer_inflate (  SEXP  x  ) 
 

Copy ZtZ to ZZpO and L. Inflate diagonal blocks of ZZpO by Omega. Update devComp[1].

Parameters:
x pointer to an lmer object

SEXP lmer_initial (  SEXP  x  ) 
 

Create and insert initial values for Omega.

Parameters:
x pointer to an lmer object
Returns:
NULL

SEXP lmer_invert (  SEXP  x  ) 
 

If necessary, factor Z'Z+Omega, ZtX, and XtX then, if necessary, replace the RZX and RXX slots by the corresponding parts of the inverse of the Cholesky factor. Replace the elements of the D slot by the blockwise inverses and evaluate bVar.

Parameters:
x pointer to an lmer object
Returns:
NULL (x is updated in place)

SEXP lmer_ranef (  SEXP  x  ) 
 

Extract the conditional modes of the random effects.

Parameters:
x Pointer to an lme object
Returns:
a vector containing the conditional modes of the random effects

static SEXP lmer_secondDer (  SEXP  x,
SEXP  Valp
)  [static]
 

Fill in five symmetric matrices, providing the information to generate the Hessian.

Parameters:
x pointer to an lme object
val ignored at present
Returns:
val an array consisting of five symmetric faces

SEXP lmer_sigma (  SEXP  x,
SEXP  REML
) 
 

Extract the ML or REML conditional estimate of sigma

Parameters:
x pointer to an lme object
REML logical scalar - TRUE if REML estimates are requested
Returns:
pointer to a numeric scalar

static void lmer_sm (  char  side,
char  trans,
int  nf,
const int  Gp[],
int  n,
double  alpha,
SEXP  L,
double  B[],
int  ldb
)  [static]
 

Solve one of the matrix equations op(L)*X=alpha*B or X*op(L)=alpha*B where L is a sparse, blocked, unit lower triangular matrix.

Parameters:
side 'L' for left, 'R' for right
trans 'T' for transpose, otherwise no transpose
nf number of grouping factors
Gp group pointers for the rows
n number of columns
alpha multiplier
L pointer to the L cscb object
mm pointer to the matrix of right-hand sides

SEXP lmer_update_mm (  SEXP  x,
SEXP  mmats
) 
 

Update the arrays ZtZ, ZtX, and XtX in an lme object according to a list of model matrices.

Parameters:
x pointer to an lmer object
mmats pointer to a list of model matrices
Returns:
NULL

SEXP lmer_validate (  SEXP  x  ) 
 

Check validity of an lmer object.

Parameters:
x Pointer to an lmer object
Returns:
TRUE if the object is a valid lmer object, else a string describing the nature of the violation.

SEXP lmer_variances (  SEXP  x  ) 
 

Return the unscaled variances

Parameters:
x pointer to an lmer object
Returns:
a list similar to the Omega list with the unscaled variances

static int max_nnz (  int  j,
SEXP  Parent
)  [static]
 


Generated on Fri Feb 18 08:49:35 2005 for Matrix by  doxygen 1.4.1