Skip to content

Find Hessian in MixCat and glmmTMB packages

2 messages · Sun, John, Ben Bolker

#
Dear All,

I am writing to ask how to find the hessian from these fitted objects to calculate the condition number of the hessian to diagnose loss of precision.
Please let me know if you know any information.

library(mixcat)
data(schizo)
attach(schizo)
a<-npmlt(y~trt*sqrt(wk),formula.npo=~trt,random=~1+trt,id=id,k=2,EB=FALSE)

library(glmmTMB)
(m1 <- glmmTMB(count ~ mined + (1|site),
  zi=~mined,
  family=poisson, data=Salamanders))

I cannot find how to find the hessian from these fitted objects.

Best regards,
John
#
From ?npmlt,

## CVmat: the inverse of the observed information matrix of the model.
rcond(solve(a$CVmat))

   (this is the inverse condition number)


  For glmmTMB: the Hessian isn't stored in the object, here is one way 
to compute it:

hessian.glmmTMB <- function(fit) {
     obj <- fit$obj
     ee <- obj$env
     pp <- ee$last.par.best
     if (!is.null(r <- ee$random)) {
         pp <- pp[-r]
     }
     h <- numDeriv::jacobian(obj$gr, pp)
     return(h)
}
rcond(hessian.glmmTMB(m1))
On 2022-09-24 12:25 p.m., Sun, John wrote: