Hi Jovana The warnings you’re encountering (NaNs were generated) are likely because the phyl.pca function uses eigenvalue decomposition. When eigenvalues are negative or very close to zero, taking the square root as part of the process (e.g., sqrt(V[i, i] * obj$Eval[j, j])) results in NaN values.
Negative eigenvalues can arise due to numerical imprecision, or they may indicate a problem with the structure of your dataset or the phylogenetic covariance matrix. If you've already identified Z-score transformation as a potential issue, it might be worth investigating further. Here are a few steps to try: Check the Data: Ensure that the input data (data.mean) and the phylogenetic tree (tree) are appropriately scaled and formatted. Look for extreme values or cases where all variables for a particular taxon are identical. Inspect the Phylogenetic Tree: Ensure the tree is ultrametric and well-resolved. If the tree has branch lengths that are zero or very small, these can lead to computational issues. Tools like ape::is.ultrametric(tree) can help verify this. Use Alternative Transformations: If the Z-score transformation introduces negative values that may be problematic, you could experiment with other normalization techniques (e.g., range scaling to [0,1]). Try Alternative PCA Methods: If the problem persists, consider using other PCA methods tailored for phylogenetic data, such as prcomp with pre-transformed data or robust PCA options in the phytools or vegan packages, depending on your data structure. If none of these approaches resolve the issue, sharing a reproducible example of your data and code could be useful? Best wishes Michael Zyphur Director Institute for Statistical and Data Science instats.org Best wishes Michael Zyphur Director Institute for Statistical and Data Science instats.org On Thu, 21 Nov 2024 at 23:08, Jovana Malikovic <jovana.maliko...@anatomy.uzh.ch> wrote: > > Dear all, > Can someone explain the correct way to handle this warning message? > > data.ppca <-phyl.pca(tree, data.mean) > data.ppca > > Warnings: > 1: In sqrt(V[i, i] * obj$Eval[j, j]) : NaNs were generated > 2: In sqrt(V[i, i] * obj$Eval[j, j]) : NaNs were generated > 3: In sqrt(V[i, i] * obj$Eval[j, j]) : NaNs were generated > 4: In sqrt(V[i, i] * obj$Eval[j, j]) : NaNs were generated > 5: In sqrt(V[i, i] * obj$Eval[j, j]) : NaNs were generated > > > I understand that this happened because of the negative values in the dataset > after the Z-score transformation, but I don't know if there is a way to solve > it. > > Thank you in advance, > Jovana > > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-phylo mailing list - R-sig-phylo@r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-phylo > Searchable archive at http://www.mail-archive.com/r-sig-phylo@r-project.org/ _______________________________________________ R-sig-phylo mailing list - R-sig-phylo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-phylo Searchable archive at http://www.mail-archive.com/r-sig-phylo@r-project.org/