lamho86 / phylolm

GNU General Public License v2.0
30 stars 12 forks source link

Error in optim(par = c(startB, startlL), fn = npllh, method = "L-BFGS-B", : L-BFGS-B needs finite values of 'fn' #63

Closed NB-Bio closed 7 months ago

NB-Bio commented 11 months ago

Hi, I am trying to run a phylogenetic logistic regression using the function phyloglm phyloglm(status.num ~ id10, data = frogs, phy = tree.frogs, btol = 30, method = "logistic_MPLE)

and I get the following error:

Error in optim(par = c(startB, startlL), fn = npllh, method = "L-BFGS-B", : L-BFGS-B needs finite values of 'fn'

I tried with different higher and lower values of btol but the error persists. I also checked if the tree is rooted is.rooted(tree.frogs), if it is fully resolved is.binary(tree.frogs), if the tree and the dataset contain the same species setdiff(tree.frogs$tip.label, rownames(frogs)) setdiff(rownames(frogs), tree.frogs$tip.label)

Furthermore, I set any zero-length branches to one-ten-millionth of the tree size tree.frogs$edge.length[tree.frogs$edge.length==0]<-max(nodeHeights(tree.frogs))*10^-6

I also tried different values for log.alpha.bound and start.alpha without success.

None of this solved the problem and I still cannot run the model. I'm interested in using the method "logistic_MPLE" for consistency with some other analyses I run with other species groups (for which the same code worked properly).

Do you have any idea about how I could solve this issue??

Thank you so much!! Nic

lamho86 commented 11 months ago

Hello Nic,

This error means that the penalized likelihood function is not finite. You have already checked all the common causes of this problem. It is hard to speculate what went wrong here. The first thing is to identify the source of this problem. You could randomly generate a tree with an appropriate size and use it with your data. If it works, then the tree causes the problem. Otherwise, the data are the culprit. Let me know what happens and we will proceed from there.

Best, Lam