Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wStockhausen opened this issue May 13, 2021 · 1 comment

Comments

@wStockhausen
Copy link

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))
}
}

@Cole-Monnahan-NOAA
Copy link
Owner

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants