Description Usage Arguments Details Value Examples
View source: R/phenotypeThroughTime.R
This function reconstructs a continuous trait through time and uses these reconstructions to estimate statistics through time.
1 | traitStatsThroughTime(tree, x, funs = c("mean", "sd"), rnd = 0.1)
|
tree |
an object of class "phylo" or "simmap" containing a phylogenetic tree (optionally with a mapped discrete character) |
x |
a vector of tip values for species; names should correspond to the respective species names in |
rnd |
time bin boundary rounding factor |
fun |
a vector of function names as characters |
For each time bin, each of the specified functions in fun
will be carried out across the branches that pass through that time bin. The boundaries of the time bins are defined by the node ages rounded by rnd
. If the tree has a mapped discrete character, the functions will be carried out separately for each state of the character.
A list with two elements:
stats |
A data.frame containing the statistics through time |
xy |
A data.frame containing the edge coordinates for the tree |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | library(phytools)
# simulate tree
tree <- pbtree(n=70,scale=1)
# simulate discrete trait
Q <- matrix(c(-1,1,1,-1),2,2)
rownames(Q) <- colnames(Q)<-c(0,1)
tree <- sim.history(tree,Q)
# simulate continuous trait
x2 <- fastBM(tree,sig2=0.1)
# calculate stats through time
tstt <- traitStatsThroughTime(tree, x2)
coords <- tstt$xy
stats <- tstt$stats
# plot phenogram
ys <- c(coords$y1, coords$y2)
plot(NULL, xlim=c(0,1), ylim=c(min(ys), max(ys)), ylab="trait", xlab="time")
segments(coords$x1, coords$y1, coords$x2, coords$y2)
# plot stats
plot(stats$x, stats$mean)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.