0

I need a pretty simple loop that takes each phylogenetic tree from the multiphylo object and calculate the Ic for each tree and put it in a dataframe. sorry if it is so simple, I'm new to R and I couldn't figure it out!

    library(apTreeshape)
    library(phytools)
   multi_trees<- pbtree(b=0.5, d=0, n=200, t=NULL, scale=NULL, 
  nsim=50, type="continuous", extant.only=TRUE) ### simulate 50 trees stored as multiphylo object
    converted_tree <- as.treeshape(multi_trees[[nsim=1]]) ## each tree need to be converted to class treeshapes using following function

 Ic <- colless(converted_tree, norm = NULL) #And finally calculate Ic for each tree
Jack
  • 165
  • 2
  • 12

1 Answers1

0

The loop is simple so I'm assuming it's self explanatory.

    library(apTreeshape)
    library(phytools)

    # simulate 50 trees stored as multiphylo object
    multi_trees<- pbtree(b=0.5, d=0, n=200, t=NULL, scale=NULL, nsim=50, type="continuous", extant.only=TRUE)

    # make data.frame for results
    Ic <- matrix(nrow=50, ncol=2)
    Ic <- data.frame(Ic)
    colnames(Ic) <- c("sim", "Ic")

    # loop
    for (i in 1:50) {
        converted_tree <- as.treeshape(multi_trees[[i]])
        Ic[i,1] <- i # get simulation number
        Ic[i,2] <- colless(converted_tree, norm = NULL) # get Ic
    }

    Ic
N311V
  • 196
  • 5