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

Hmsc Error: 8 nodes produced errors; first error: the leading minor of order 4 is not positive definite #174

Open
wwhbeach opened this issue Dec 27, 2023 · 9 comments

Comments

@wwhbeach
Copy link

wwhbeach commented Dec 27, 2023

Hello,

I have been struggling with an error I've received for several of my models and I was wondering if I could get some help on why this may be occurring.

I am using presence-absence data for 20 species in 63 sites and have been attempting to run my model using 6 variables. Depending on my model, I have used different variables, but the total number of variables have consistently been 6. Depending on the set of variables, my model has either successfully run or failed .

Here are the errors I have received:

> for (thin in c(1,10,100))
+ {transient = 50*thin
+ m = sampleMcmc(m, thin = thin, samples = samples, transient = transient,
+                nChains = nChains, initPar = "fixed effects",
+                nParallel = nChains)
+ filename=file.path(model.directory, paste0("model_chains_",as.character(nChains),"_samples_",as.character(samples),"_thin_",as.character(thin)))
+ save(m,file=filename)}
Error in checkForRemoteErrors(val) : 
  8 nodes produced errors; first error: the leading minor of order 4 is not positive definite

> traceback()
5: stop(count, " nodes produced errors; first error: ", firstmsg, 
       domain = NA)
4: checkForRemoteErrors(val)
3: dynamicClusterApply(cl, fun, length(x), argfun)
2: clusterApplyLB(cl, 1:nChains, fun = sampleChain)
1: sampleMcmc(m, thin = thin, samples = samples, transient = transient, 
       nChains = nChains, initPar = "fixed effects", nParallel = nChains)

I have tried looking up this issue online and found a couple discussions on github discussing a similar issue, but the recommendations were either not relevant to my data or did not work as far as I can tell.
#45
#123

If you have any suggestions for how to fix this issue, it would be greatly appreciated. I am happy to provide additional information needed to fully address this issue.

@jarioksa
Copy link
Collaborator

Can you prepare a reproducible example? If not, can you reproduce this in non-parallel run?

Non-parallel runs allow better tracing: there are now 60 calls to chol in 12 functions that can give that very same error message, and we have hard time guessing which of them is involved here. Now clusterApplyLB is the last command we have written and tracing ends there from our point of view.

Yes, this can happen, and issue #45 indeed has similar features.

@wwhbeach
Copy link
Author

I tried running a non-parallel run and got this error:

Computing chain 1
Hmsc::computeInitialParameter - initializing fixed effects with SSDM estimates
Error in chol.default(V) :
the leading minor of order 4 is not positive definite
In addition: Warning messages:
1: glm.fit: fitted probabilities numerically 0 or 1 occurred
2: glm.fit: fitted probabilities numerically 0 or 1 occurred
3: glm.fit: fitted probabilities numerically 0 or 1 occurred
4: glm.fit: fitted probabilities numerically 0 or 1 occurred
5: glm.fit: fitted probabilities numerically 0 or 1 occurred
6: glm.fit: fitted probabilities numerically 0 or 1 occurred
7: glm.fit: fitted probabilities numerically 0 or 1 occurred
8: glm.fit: algorithm did not converge
9: glm.fit: fitted probabilities numerically 0 or 1 occurred
10: glm.fit: fitted probabilities numerically 0 or 1 occurred

@jarioksa
Copy link
Collaborator

Seems to be the "unexplained variance in species 'niches' (linear coefficients)" that cannot be inverted. It could be that failures in glm fit are a part of the problem. @ovaskain?

@ovaskain
Copy link
Collaborator

ovaskain commented Jan 2, 2024 via email

@jarioksa
Copy link
Collaborator

jarioksa commented Jan 2, 2024

@ovaskain We have similar reports when initPar="fixed effects" was used (issue #45). Now we also have warnings from glm. These seem to be cases with complete separation or other extreme cases where binary models tend to either 0 or 1, or Poisson model to 0 which cannot be represented with the link functions, and the linear predictor tends towards minus or plus infinity. It won't go that far, but the initial values of linear predictors will be extreme, and as initial values the MCMC chains can wander off to impossible territories. I don't know if we should try to handle these cases that give a warning glm.fit: fitted probabilities numerically 0 or 1 occurred warning?

@ovaskain
Copy link
Collaborator

ovaskain commented Jan 3, 2024 via email

@wwhbeach
Copy link
Author

wwhbeach commented Jan 3, 2024

Hi @jarioksa and @ovaskain,

Thank you for your help! This seems to have fixed the issue.

@wwhbeach
Copy link
Author

wwhbeach commented Jan 3, 2024

Hi again,

I've since rerun a few models that did not have any error when initPar= "fixed effects" was set and have run them without this. I've noticed that in many cases the Tjur R2 values, AUC, and WAIC results have changed quite a lot (For example, one model that originally had a mean Tjur R2 of .40 and was initially my best fitting model overall dropped to 0.32).
Any idea why this may have occurred?

@ovaskain
Copy link
Collaborator

ovaskain commented Jan 4, 2024 via email

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

3 participants