Dear Miguel.

One way to do something like would be by using the phytools function treeSlice.

treeSlice cuts the tree at a particular point. Depending on the argument orientation, it returns either the rootward tree or the descendant subtrees. So, say you want to simulate under Brownian motion from time 0 to time t, and then just draw random values from a distribution centered on the ancestral value of each subtree descended from time t, you would just need to do two sets of simulations. First on the rootward tree, and then on each descendant subtree.

This could look something like the following:

## get hidden lambdaTree function (this is just to simulate random
## values for the subtrees from time t
lt<-phytools:::lambdaTree
## set t (here I'm imagining the tree has a total length of 100 and
## I want to slice it at time = 70 units above the root
t<-70
## slice the tree rootward of time = t -- this generates an object
## of class "multiPhylo"
rootward<-treeSlice(tree,orientation="rootwards",slice=t)
## now slice the tree tipward of time t -- this generates an object
## of class "multiPhylo" with a length equal to the number of tips
## in rootward
tipward<-treeSlice(tree,orientation="tipwards",trivial=TRUE,
        slice=t)
## convert each subtree in tipward to a "phylo" object with an
## unbranching (singleton) root node. This is for simulation.
tipward<-lapply(tipward,rootedge.to.singleton)
## simulate the ancestral states for each subtree in tipward under
## pure Brownian motion
aa<-fastBM(rootward)
## create a vector of values
xx<-vector()
## simulate on each subtree to populate it. a is the ancestral state
## for each simulation
for(i in 1:length(tipward))
        xx<-c(xx,fastBM(lt(tipward[[i]],0),a=aa[i]))

All the best, Liam

Liam J. Revell
University of Massachusetts Boston [Assoc. Prof.]
Universidad Católica de la Ssma Concepción [Adj. Res.]

Web & phytools:
http://faculty.umb.edu/liam.revell/, http://www.phytools.org, http://blog.phytools.org

Academic Director UMass Boston Chile Abroad:
https://www.umb.edu/academics/caps/international/biology_chile

U.S. COVID-19 explorer web application:
https://covid19-explorer.org/

On 11/4/2021 1:29 PM, Miguel Verdú del Campo wrote:
EXTERNAL SENDER

Dear list

Is there any way to simulate the evolution of a trait with a given significant 
signal (say K=1) from the tree root to time x and no signal (K=0) from time X 
to the present?

Thanks

Miguel Verdú

_______________________________________________
R-sig-phylo mailing list - R-sig-phylo@r-project.org
https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-sig-phylo&amp;data=04%7C01%7Cliam.revell%40umb.edu%7C1a5101f33c0a4deb496008d99fb8c766%7Cb97188711ee94425953c1ace1373eb38%7C0%7C1%7C637716438239880743%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000&amp;sdata=mPBjrHJPPEd1iW0%2Bm3nfSEZiCAALVxhJ8EOsXJYXH7Q%3D&amp;reserved=0
Searchable archive at 
https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.mail-archive.com%2Fr-sig-phylo%40r-project.org%2F&amp;data=04%7C01%7Cliam.revell%40umb.edu%7C1a5101f33c0a4deb496008d99fb8c766%7Cb97188711ee94425953c1ace1373eb38%7C0%7C1%7C637716438239880743%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000&amp;sdata=d9koDURvcfb9cKVmMCB%2BenCUYsUViejZwALJbr9lNxU%3D&amp;reserved=0


_______________________________________________
R-sig-phylo mailing list - R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
Searchable archive at http://www.mail-archive.com/r-sig-phylo@r-project.org/

Reply via email to