adnuts icon indicating copy to clipboard operation
adnuts copied to clipboard

check_identifiable() crashes when eigenvalues of "covariance" matrix are complex

Open wStockhausen opened this issue 3 years ago • 1 comments

check_identifiable() crashes when eigenvalues of a bad "covariance" matrix are complex. The following code handles the situation without blowing up. Might want to add an error message pointing out why the check failed.

check_identifiable <- function(model, path=getwd()){

Check eigendecomposition

fit <- adnuts:::.read_mle_fit(model, path) hes <- adnuts:::.getADMBHessian(path) ev <- eigen(hes); if (any(is.complex(ev$values))){ WhichBad <- which( abs(Im(ev$values)) > .Machine$double.eps); } else { WhichBad <- which( ev$values < sqrt(.Machine$double.eps) ); }

if(length(WhichBad)==0){ message( "All parameters are identifiable" ) } else { ## Check for parameters if(length(WhichBad)==1){ RowMax <- abs(ev$vectors[,WhichBad]) } else { RowMax <- apply(ev$vectors[, WhichBad], MARGIN=1, FUN=function(vec){max(Mod(vec))} ) } bad <- data.frame(ParNum=1:nrow(hes), Param=fit$par.names, MLE=fit$est[1:nrow(hes)], Param_check=ifelse(RowMax>0.1, "Bad","OK")) row.names(bad) <- NULL bad <- bad[bad$Param_check=='Bad',] print(bad) return(invisible(bad)) } }

wStockhausen avatar May 13 '21 17:05 wStockhausen

@wStockhausen sorry for the delay I was not alerted to this issue for some reason.

I implemented your fix in this commit. If you have time could you confirm it works? I haven't run across a matrix with complex eigenvalues yet.

Cole-Monnahan-NOAA avatar Jun 14 '23 18:06 Cole-Monnahan-NOAA