rpcaeigenvaluephylogenyape

Complex eigenvalues in Principal Coordinate Analysis (PCoA)


I'm sharing a problem related to complex eigenvalues in Principal Coordinate Analysis (PCoA). Any help much appreciated!

The aim: perform PCoA on a matrix of phylogenetic distances -> include the ordination axes in a regression model to account for phylogenetic relatedness among plant species (n = 1013 species).

The input data: a phylogenetic distance matrix, obtained by applying the cophenetic() function on a rooted and time-calibrated phylogeny. The result is a 1013 x 1013 matrix, with 0 in the main diagonal. The input matrix is symmetric (according to isSymmetric()) and doesn't contain complex numbers (according to any(is.complex()). There are no NA either. See a subset of some species below:

    structure(c(0, 55.7063710000001, 105.333883, 237.6822, 237.682199, 
261.495339, 55.7063710000001, 0, 105.333886, 237.682203, 237.682202, 
261.495342, 105.333883, 105.333886, 0, 237.682201, 237.6822, 
261.49534, 237.6822, 237.682203, 237.682201, 0, 66.171369, 261.495341, 
237.682199, 237.682202, 237.6822, 66.171369, 0, 261.49534, 261.495339, 
261.495342, 261.49534, 261.495341, 261.49534, 0), .Dim = c(6L, 
6L), .Dimnames = list(c("Cyrtomium_falcatum", "Cyrtomium_fortunei", 
"Nephrolepis_cordifolia", "Pteris_cretica", "Pteris_vittata", 
"Azolla_filiculoides"), c("Cyrtomium_falcatum", "Cyrtomium_fortunei", 
"Nephrolepis_cordifolia", "Pteris_cretica", "Pteris_vittata", 
"Azolla_filiculoides")))

Minimum reproducible example: I've created a subset of the distance matrix that reproduces the error message. It is in txt format, you can load in R with read.table("you_path/distance.matrix.subset.txt", header = T, row.names = 1, sep = " "). Donwload it here (GoogleDrive).

The problem: error message indicating that complex eigenvalues were produced when performing PCoA (if I understand the error correctly). I used ape::pcoa() with default settings (ape version 5.4.1).

Error in min(D.eig$values) : invalid 'type' (complex) of argument

There has been some discussion on this error message elsehwere, but I haven't found a solution there.

Interestingly, I don't get any error message if I perform PCoA using stats::cmdscale() (stats version 3.6.3). Moreover, I've done the same procedure recently on a smaller set of species (n = 79), and I got no error message when using ape::pcoa().

Many thanks in advance for any help and/or insights! I'm new to Stack Overflow, so don't hesitate to tell me how I can make the problem more understandable, or whether additional information is needed.

Cheers!


Solution

  • I think I've figured out the problem - it's a rounding error deep in an internal function called centre() which turns symmetric matrices non-symmetric - and submitted a Github issue.

    https://github.com/emmanuelparadis/ape/issues/17