emmanuelparadis / ape

Analysis of Phylogenetics and Evolution
https://emmanuelparadis.github.io/
GNU General Public License v2.0
53 stars 11 forks source link

model fit suspicious: gradients apparently non-finite #81

Closed xuechunxu closed 1 year ago

xuechunxu commented 1 year ago

Hi,

I estimated ancestral character states for discretely valued traits. But got the error: Error in matexpo(Q * EL[i]) : NA/NaN/Inf in foreign function call (arg 1) In addition: Warning messages: 1: In log(comp[-TIPS]) : NaNs produced 2: In ace(x, tree, model = "ER", type = "discrete") : model fit suspicious: gradients apparently non-finite

Here is my command line: image image

This is my niche file, these are five niche types image

The input file: ace.zip

Looking forward to your reply!

Chun Xu

emmanuelparadis commented 1 year ago

Hi, There are a few things you need to pay attention to: 1/ The function multi2di has the option random = TRUE by default which may not resolve the root of the tree correctly. You can set random = FALSE, but you are not sure about the output too. I suggest:

tree <- root(tree, ".....", resolve.root = TRUE)

where you replace "....." by the outgroup label. 2/ You certainly need to do the following transformation:

x[x == "DontKnow"] <- NA

See the explanation in ?ace about how missing values are treated by this function. 3/ It seems you need to transform the branch lengths of the tree. For instance:

tree2 <- compute.brlen(tree, 1)

This is quite common that non-ultrametric trees fail when input into ace. You may try different transformations (see ?compute.brlen and other functions in other packages like geiger or phytools). Then it's up to you to interpret these transformations with respect to your data. Best, Emmanuel

xuechunxu commented 1 year ago

Thank you very much, it worked. The bug is caused that the length of some leaves being zero in my phylogenetic tree. Thank you again.