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

Error in solve.default(C) : Lapack routine dgesv: system is exactly singular: U[393,393]=0 #89

Open
vanessayang0927 opened this issue May 7, 2021 · 3 comments

Comments

@vanessayang0927
Copy link

vanessayang0927 commented May 7, 2021

Hey phytools! I'm trying to use the phylosig function to computes phylogenetic signal. It's going well using the lambda method. But it's wrong when using the K method. I have no idea what the issue is, but it seems a very common question. And there are some information about the error:

R version 4.0.5
phytools version 0.7-70

file
files.zip

my code:
library(phytools)
my_tree <- read.tree("otus1.16s.pick725.Neighbor-Joinning.nwk")
abun <- read.table("test.txt", header = TRUE, sep = "\t", row.names = 1, check.names = FALSE)
C <- setNames(abun$C,rownames(abun))
phylosig(my_tree,C,method = "K",test = TRUE)
phylosig(my_tree,C,method = "lambda",test = TRUE)

error:
Error in solve.default(C) : Lapack routine dgesv: system is exactly singular: U[393,393]=0

I'm trying phylosig(my_tree,C*100,method = "K",test = TRUE) but still get the same error

@liamrevell
Copy link
Owner

Hi Vanessa. The problem is that some of the tips of your tree are separated by patristic distance of zero. (For instance, a pair of sister species with zero length terminal branches.) You can see this by running:

D<-cophenetic(my_tree) min(as.dist(D))

(The function as.dist converts the symmetric distance matrix to a lower/upper diagonal object of class "dist" so the diagonal is ignored.)

This makes the among species covariance matrix uninvertible ("exactly singular").

There's no single solution to this, but perhaps it would be OK to just prune one or the other tip that is affected in this way?

-- Liam

@vanessayang0927
Copy link
Author

vanessayang0927 commented May 13, 2021

Hi Liam. Thanks for your reply. I tried to use as.dist and get the same error. There are some information about the error:

R version 4.0.5
my code:
D <- cophenetic(my_tree)
tree <- ape::njs(D)
phylosig(tree,C,method = "K",test = TRUE)

error:
Error in solve.default(C) : Lapack routine dgesv: system is exactly singular: U[301,301] = 0

It seems to be correlated with negative or zero branch lengths produced by neighbor-joining. I'm trying to make negative or zero branch lengths a really small positive number(1e-10) and it's going well.
my_tree$edge.length[which(my_tree$edge.length <=0)] <- 1e-10
phylosig(my_tree,C,method = "K",test = TRUE)
phylosig(my_tree,C,method = "lambda",test = TRUE)

@clementfkent
Copy link

Thanks for your work-around, Vanessa. I had the same problem and your seeting things positive fixed it. I wonder if Prof. Revell has any comments on what particuklar small positive edge lengths are desirable?

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