1## maxLik
2vcov.maxLik <- function(object, eigentol=1e-12, ...) {
3   ## if exists $varcovar, take it
4   if(!is.null(object$varcovar))
5       return(object$varcovar)
6   ## otherwise invert hessian
7   activePar <- activePar(object)
8   if(!is.null(hess <- hessian(object))) {
9      hess <- hessian(object)[activePar, activePar,drop=FALSE]
10      hessev <- abs(eigen(hess, symmetric=TRUE, only.values=TRUE)$values)
11      varcovar <- matrix(0, nParam.maxim(object), nParam.maxim(object))
12                           # this makes the fixed parameters to 0
13      rownames( varcovar ) <- colnames(varcovar ) <- names(coef.maxLik(object))
14      if(min(hessev) > (eigentol*max(hessev))) {
15      ## If hessian is not singular, fill in the free parameter values
16         varcovar[activePar,activePar] <- solve(-hessian(object)[activePar,activePar])
17         # guarantee that the returned variance covariance matrix is symmetric
18         varcovar <- ( varcovar + t( varcovar ) ) / 2
19      }
20      else {
21      ## If singular, the free parameter values will be Inf
22         varcovar[activePar,activePar] <- Inf
23      }
24      return(varcovar)
25   }
26   else
27       return(NULL)
28}
29