Skip to content

Commit

Permalink
chainsaw.R: check tip diversity when interval == 0 since values are d…
Browse files Browse the repository at this point in the history
…ifferent in ultrametric and non-ultrametric cases.. and replace check for equality to zero with all.equal to account for machine rounding errors.
  • Loading branch information
soniamitchell committed Jun 1, 2016
1 parent 8131cc3 commit 716754b
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions R/chainsaw.R
Expand Up @@ -31,12 +31,6 @@ chainsaw <- function(data, leaf.abundance, interval) {
return(super)
}

# When phylogeny is removed, calculate the diversity of the tips
if(interval == 0) {
super <- supercommunity(leaf.abundance)
return(super)
}

# Distance from root
node.height <- ape::node.depth.edgelength(data)

Expand All @@ -47,6 +41,7 @@ chainsaw <- function(data, leaf.abundance, interval) {

# Distance from top of tree
node.depth <- max.height - node.height

# Remove non-zero rounding errors
node.depth <- sapply(node.depth, function(x) ifelse(isTRUE(all.equal(0, x)), 0, x))
node.depth <- cbind.data.frame(all.nodes, node.depth)
Expand All @@ -59,6 +54,18 @@ chainsaw <- function(data, leaf.abundance, interval) {
data <- rdphylo(leaf.abundance, data)
}

# When phylogeny is removed, calculate the diversity of the tips
if(isTRUE(all.equal(0, interval))) {
if(is.ultrametric(data))
super <- supercommunity(leaf.abundance)

if(!is.ultrametric(data)) {
nodes.at.zero <- node.depth$node[node.depth$depth %in% 0]
super <- supercommunity(leaf.abundance[nodes.at.zero,])
}
return(super)
}

historic.species <- data@historic.species

# Ancestral nodes
Expand Down

0 comments on commit 716754b

Please sign in to comment.