paternogbc / sensiPhy

R package to perform sensitivity analysis for comparative methods
http://onlinelibrary.wiley.com/doi/10.1111/2041-210X.12990/full
GNU General Public License v2.0
12 stars 4 forks source link

BUG- multiphylo and how to know what tree are without edge lenght #188

Closed abraao-crypto closed 4 years ago

abraao-crypto commented 4 years ago

function

tree_physig

Problem

I can't know what is the problem when I using a multiphylo. Hence, always there is a warning about the incompatibility between phylogenies and data. How can I know what's going on? How can I know if the edge length of trees is ok? Script_issue_SensyPhy.zip

Reproducible example

databir<-read.csv2("birdresid.csv",sep = ";",dec=",",header=T,fileEncoding="UTF-8-BOM") tree<-read.tree(file = "mbirdresid.phy") for(i in 1:length(tree)) phylotree <- tree[[i]] phylotree$tip.label=gsub("_", " ",phylotree$tip.label) rownames(databir)=databir$ssp databir=databir[phylotree$tip.label,] tree <- tree_physig(trait.col = "rbrain", method="lambda",data =databir, phy =tree, n.tree =1000) sensi_plot(tree) sensi_plot(tree, graphs = 1) sensi_plot(tree, graphs = 2) summary(tree)

library(sensiPhy)
#### your code goes here 
paternogbc commented 4 years ago

Dear @abraao-crypto,

you can use the following function to check which trees have no branch length in a multiphylo object:

no_branch <- function(multiphylo){
  res <- character()
  for (i in 1:1000) {
    res[i] <- class(multiphylo[[i]]$edge.length)
  }
  which(res != "numeric")
}

# Usage
no_branch(multiphylo = tree)

For each tree in a multiphylo object you can also simple check:

multiphylo[[1]]$edge.length 

to see if it contains a numeric vector with branch lengths.

abraao-crypto commented 4 years ago

Hello Gustavo.  I got it!   Thank you!

paternogbc commented 4 years ago

To test if there are missing species between phylogenies and data, you can use the sensiPhy function match_dataphy().

In you case, the species "Phylidonyris__melanops" was dropped.

dat <- match_dataphy(formula = rbrain ~ 1, data = databir, phy = tree)

# Which species was dropped?
dat$dropped
abraao-crypto commented 4 years ago

Ok I will do it. Thank you!