polytomyBind: Drop all tips but one per named clade

View source: R/polytomyBind.R

polytomyBindR Documentation

Drop all tips but one per named clade

Description

Collapse a phylogeny by node and rename according to a clade table.

Usage

polytomyBind(dropped.result, oc.result)

Arguments

dropped.result

The result of a call to dropManyTips.

oc.result

Data frame with four columns: node, present (0/1), collapse (0/1), and clade.

Details

Stuff.

Value

A tree with the tips from a collapsed node bound in as polytomies.

Author(s)

Eliot Miller

Examples

#start with a corHMM output and build up a states.df
#load data. these are the results of following the corHMM precursor model vignette
data(Precur_res.corHMM)
data(phy)
nodeStates <- data.frame(state=Precur_res.corHMM$states[,3]+Precur_res.corHMM$states[,4])
tipStates <- data.frame(state=Precur_res.corHMM$tip.states[,3]+Precur_res.corHMM$tip.states[,4])

#note that tip states comes first here!
states <- rbind(tipStates, nodeStates)

#binarize this. choosing to call 0.5 chance of having trait present
states$state[states$state >= 0.5] <- 1
states$state[states$state < 0.5] <- 0

#flip node 103 and all nodes towards tips from there to trait = absent
induced <- states
induced[geiger:::.get.descendants.of.node(103, phy),] <- 0
induced[103,] <- 0

#get rid of row names
row.names(induced) <- NULL

#run the function and don't flip those tips
ocResult <- optimalCollapse(orig.tree=phy, states.df=induced, flip.tips=FALSE)

#run the dropManyTips fxn
dropped <- dropManyTips(orig.tree=phy, oc.result=ocResult)

#run the polytomyBind function
polyTree <- polytomyBind(dropped.result=dropped, oc.result=ocResult)

eliotmiller/shiftPlot documentation built on March 30, 2023, 4:26 a.m.