tipFlip | R Documentation |
Ensure tips have the same states as their parent nodes, to preclude shifts on terminal branches.
tipFlip(orig.tree, states.df)
orig.tree |
Phylogeny in ape format, corresponding to states.df. |
states.df |
Data frame in the specified shiftPlot format. Should contain one column named "state", and a number (state) for every node in the phylogeny, with the tips above the internal nodes, and no row names. See details and examples. |
states.df should have one column titled "state". This column should take the form of a numeric vector, indicating the statee of the trait. states.df should have as many rows as there are nodes in phylogeny, and the tip nodes should come first in the data frame. For example, you might rbind the $tip.states and $states objects from a corHMM output together to create states.df The main reason one would use this function is to preclude shifts on terminal branches. You might want to do that if, for example, your phylogeny was so large that corHMM was having trouble calculating the marginal probabilities of a tip having a hidden trait, and the result would otherwise be that it appeared there were many shifts in the hidden trait towards the tips.
An updated states.df with the tip values flipped as needed.
Eliot Miller
#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
#make the model a little more exciting (all tips were origianlly
#inferred to have the hidden precursor trait)
tipsInQ <- tips(phy, 103)
states[tipsInQ,] <- 0
#' #get rid of row names
row.names(states) <- NULL
#try running the function
result <- tipFlip(orig.tree=phy, states.df=states)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.