Body: <p>I'm trying to simulate the evolution of binary traits on phylogenies in R to end up with a dataset of the traits held by each tip. Starting at the root, at every timestep, new traits are added with a certain probability, and existing traits are lost with another probability.  This happens independently for every branch that exists at that timestep before moving to the next timestep. Those traits are added/removed from the final trait vectors of each species that is descended from the current branch/timestep.</p>
  <p>The issue is I don't know how to identify which tips (final species) originate from which current branches (at a specific timestep).</p>
  <p>Is there a function for identifying, on a phylogeny, at a specific time, tips that share a current ancestor/tips that are descended from the currently selected internal branch?</p>
  <p>Or, do you have a better way of organizing the trait data through time?</p>
  <p>I've tried using other software (TraitLab in Matlab) but not sure that it does exactly what I want, which is why I'd rather code it in R. If you have other suggestions of software to use, that would also be much appreciated! Unfortunately most trait evolution simulation software require you to know the total number of traits from the start, whereas I want new traits to appear and be lost.</p>
  <p>I want to do something similar but different to getMRCA. Starting with one selected species, at a specific time in the phylogeny, I want to identify all other species from which it hasn't yet split.</p>
  <p>Traits are gained under this model. The way I planned it is that every species has a vector of traits, each position in the vector being for 1 unique trait (the positions indicate the same traits across all species). So when a trait is gained, a &quot;1&quot; is added to all vectors of species descended from that branch, and a &quot;0&quot; is added to all other species. When a trait is lost, the &quot;1&quot; for that trait in all species descended from that branch is replaced with a &quot;0&quot;. I'm using the ape library, I just can't figure out how to identify which species are descended from a specific branch.</p>
  <p>Do you know of a function that can do that?</p>
  <p>Thanks!</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-05-03T02:07:50.340Z
Comments.Text: Okay there are other ways in using complete packages outside R, but if it's strictly R I just dunno. `getMRCA` is a good idea, but it's the opposite of what is wanted here I think. I believe the OP wants MRCA -> tips (OTUs), rather than tips -> MRCA.  Possibly from the `bio.infer` library `get.otu`? Just guessing.
Comments.UserDisplayName: M__
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-05-04T18:05:43.400Z
Comments.Text: Maybe you want `extract.clade` in `ape` that gets the subtree at a specified node? Its description is hidden in the `drop.tip` documentation.
Comments.UserDisplayName: Mosquite
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-05-12T05:29:32.143Z
Comments.Text: It sounds like you do know the total number of traits from the start; it's just the length of the vector of traits. As I understand it, what you're calling gaining or losing a trait, is really just changing the state of the trait between 0 and 1.
Comments.UserDisplayName: Darlingtonia
Tags: <r><phylogenetics><phylogeny><simulated-data>
Title: How to identify all descendents of a branch on a phylogeny
ThreadText: # How to identify all descendents of a branch on a phylogeny
  
  (Asked by: username_0 on 2023-05-02)
  
  I'm trying to simulate the evolution of binary traits on phylogenies in R to end up with a dataset of the traits held by each tip. Starting at the root, at every timestep, new traits are added with a certain probability, and existing traits are lost with another probability. This happens independently for every branch that exists at that timestep before moving to the next timestep. Those traits are added/removed from the final trait vectors of each species that is descended from the current branch/timestep.
  
  The issue is I don't know how to identify which tips (final species) originate from which current branches (at a specific timestep).
  
  Is there a function for identifying, on a phylogeny, at a specific time, tips that share a current ancestor/tips that are descended from the currently selected internal branch?
  
  Or, do you have a better way of organizing the trait data through time?
  
  I've tried using other software (TraitLab in Matlab) but not sure that it does exactly what I want, which is why I'd rather code it in R. If you have other suggestions of software to use, that would also be much appreciated! Unfortunately most trait evolution simulation software require you to know the total number of traits from the start, whereas I want new traits to appear and be lost.
  
  I want to do something similar but different to getMRCA. Starting with one selected species, at a specific time in the phylogeny, I want to identify all other species from which it hasn't yet split.
  
  Traits are gained under this model. The way I planned it is that every species has a vector of traits, each position in the vector being for 1 unique trait (the positions indicate the same traits across all species). So when a trait is gained, a "1" is added to all vectors of species descended from that branch, and a "0" is added to all other species. When a trait is lost, the "1" for that trait in all species descended from that branch is replaced with a "0". I'm using the ape library, I just can't figure out how to identify which species are descended from a specific branch.
  
  Do you know of a function that can do that?
  
  Thanks!
  
  **Tags:** r, phylogenetics, phylogeny, simulated-data
  
  > **Comments:**
  > **username_1**: Okay there are other ways in using complete packages outside R, but if it's strictly R I just dunno. `getMRCA` is a good idea, but it's the opposite of what is wanted here I think. I believe the OP wants MRCA -> tips (OTUs), rather than tips -> MRCA.  Possibly from the `bio.infer` library `get.otu`? Just guessing.  
  > **username_2**: Maybe you want `extract.clade` in `ape` that gets the subtree at a specified node? Its description is hidden in the `drop.tip` documentation.  
  > **username_3**: It sounds like you do know the total number of traits from the start; it's just the length of the vector of traits. As I understand it, what you're calling gaining or losing a trait, is really just changing the state of the trait between 0 and 1.  
  
  ---
  
  ## 0 answers
  
  