Topic: Utilities

Topic Description:

Basic R utilities used in many packages and functions, such as date and string manipulations, statistical distributions, geometry of lines and distances. The R package date is required for the two data functions.



File: utilities/lmerBayes.r

View File Source Download File No help file available

Function: lmerBayes.hyperllike.sigma

Function Description: lmerBayes.hyperllike.sigma

This is the hyper-likelihood for updating the covariances. It is always based on dmvnorm. The par is a matrix of parameters, one row per random effect, one column the set of parameters. It allows the Gibbs sampler to work by passing a single scalar parameter as the first argument.

Function Arguments:

ArgumentDefault Value
testcov
fullcov
hypermean
modelpar
whichrow
whichcol

Sample Usage:

lmerBayes.hyperllike.sigma=function(testcov,fullcov,hypermean,modelpar,whichrow,whichcol){ covar=arrangeParam.llike.2D(testcov,fullcov,whichrow,whichcol,forcesymmetry=TRUE) eigen.vector=eigen(covar,symmetric=TRUE,only.values=TRUE)$values if(!isSymmetric(covar)) browser() if(length(which(eigen.vector<=0))>0) {


Function Source:

lmerBayes.hyperllike.sigma=function(testcov,fullcov,hypermean,modelpar,whichrow,whichcol)
{
covar=arrangeParam.llike.2D(testcov,fullcov,whichrow,whichcol,forcesymmetry=TRUE)

eigen.vector=eigen(covar,symmetric=TRUE,only.values=TRUE)$values
if(!isSymmetric(covar)) browser()

if(length(which(eigen.vector<=0))>0) { return(-Inf) } # A covariance matrix must have strictly pos
        itive eigenvalues

# In addition to testing eigenvectors. Problem is, I believe, that a nearly zero eigenvector may al
        so fail to invert test=try(solve(covar))
if(class(test)=='try-error') return(-Inf)

llike=dmvnorm(modelpar,mean=hypermean,sigma=covar,log=TRUE)

if(length(which(is.na(llike)))>0) browser()
return(sum(llike))
}