Answers.Body: <p>The <code>ape</code> library (Analyses of Phylogenetics and Evolution) using the <code>MPR</code> method (Most Parsimonious Reconstruction).</p>
  <p>Information on <code>ape</code> is <a href="https://rdrr.io/cran/ape/" rel="nofollow noreferrer">here</a>.</p>
  <p>The format</p>
  <pre><code>install.packages(“ape”)
  library(ape)
  MPR(x, phy, outgroup)
  </code></pre>
  <blockquote>
  <p><strong>x</strong> :   a vector of integers.</p>
  </blockquote>
  <blockquote>
  <p><strong>phy</strong> : an object of class &quot;phylo&quot;; the tree must be unrooted and fully dichotomous.</p>
  </blockquote>
  <blockquote>
  <p><strong>outgroup</strong> : an integer or a character string giving the tip of phy used as outgroup.</p>
  </blockquote>
  <p>Rooting the tree is recommended. In the example rooting isn't used but an outgroup is used as taxa <code>t1</code>, that will be fine.</p>
  <p>Generating random data,</p>
  <pre><code>vectx &lt;- rpois(50, 1) # make random data
  tree &lt;- rtree(50, rooted = FALSE)  # also rtree(50) make random tree
  MPR(vectx, tree, &quot;t1&quot;) 
  </code></pre>
  <p>Thats it, there's nothing more. Data, tree = steps.</p>
  <p><strong>Clarification</strong> the question is number of parsimonious characters. As a strict definition the number of informative characters is the same as the number of steps and thats what <code>MPR</code> will describe ... thats easy.</p>
  <p>There are other possible meanings</p>
  <ol>
  <li>The number of parsimonious characters/steps to make a tree is calculated via <code>MPR</code> as above.</li>
  <li>if its the actual changes at a given position in the alignment (or vector) for each node in the tree - thats the answer below - but thats complicated.</li>
  <li>If its simply is this site (not character) is parsimoniously informative and this one isn't then the &quot;alignment&quot; or vector could be used one character position at a time and subject to <code>MPR</code> and the step length would determine how parsimoniously informative each site was ... thus point 3 is easily doable in <code>R</code></li>
  </ol>
  <hr />
  <p><strong>Note</strong> Calculating the actual sites on the alignment and associated changes per node is easily done outside <code>R</code>, but within <code>R</code> I don't know if thats doable.</p>
  <p>Wait, I'm wrong it's doable but I would envisage its difficult to implement. Calculating parsimonious characters for each given node in a tree - yes I do that - doing that in <code>R</code> ... errhhh thats not me. There are Pythonic ways in, but I've not implemented them.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-02-10T12:49:19.837Z
Answers.LastActivityDate: 2023-02-10T23:51:58.327Z
Answers.LastEditDate: 2023-02-10T23:51:58.327Z
Answers.UserDisplayName: M__
Body: <p>I have a dataset of binary morphological characters and would like to know how many of them are parsimony informative. Is there a way to calculate this with an R package?</p>
  
Tags: <r><phylogenetics>
Title: Is there a way to calculate the number of parsimony informative characters in a morphological dataset in R?
ThreadText: # Is there a way to calculate the number of parsimony informative characters in a morphological dataset in R?
  
  (Asked by: username_0 on 2023-02-10)
  
  I have a dataset of binary morphological characters and would like to know how many of them are parsimony informative. Is there a way to calculate this with an R package?
  
  **Tags:** r, phylogenetics
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-02-10. Score: 1
  
  The `ape` library (Analyses of Phylogenetics and Evolution) using the `MPR` method (Most Parsimonious Reconstruction).
  
  Information on `ape` is [here](https://rdrr.io/cran/ape/).
  
  The format
  
  ```
  install.packages(“ape”)
  library(ape)
  MPR(x, phy, outgroup)
  
  ```
  
  > **x** : a vector of integers.
  
  > **phy** : an object of class "phylo"; the tree must be unrooted and fully dichotomous.
  
  > **outgroup** : an integer or a character string giving the tip of phy used as outgroup.
  
  Rooting the tree is recommended. In the example rooting isn't used but an outgroup is used as taxa `t1`, that will be fine.
  
  Generating random data,
  
  ```
  vectx <- rpois(50, 1) # make random data
  tree <- rtree(50, rooted = FALSE)  # also rtree(50) make random tree
  MPR(vectx, tree, "t1") 
  
  ```
  
  Thats it, there's nothing more. Data, tree = steps.
  
  **Clarification** the question is number of parsimonious characters. As a strict definition the number of informative characters is the same as the number of steps and thats what `MPR` will describe ... thats easy.
  
  There are other possible meanings
  
  1. The number of parsimonious characters/steps to make a tree is calculated via `MPR` as above.
  2. if its the actual changes at a given position in the alignment (or vector) for each node in the tree - thats the answer below - but thats complicated.
  3. If its simply is this site (not character) is parsimoniously informative and this one isn't then the "alignment" or vector could be used one character position at a time and subject to `MPR` and the step length would determine how parsimoniously informative each site was ... thus point 3 is easily doable in `R`
  
  ---
  
  **Note** Calculating the actual sites on the alignment and associated changes per node is easily done outside `R`, but within `R` I don't know if thats doable.
  
  Wait, I'm wrong it's doable but I would envisage its difficult to implement. Calculating parsimonious characters for each given node in a tree - yes I do that - doing that in `R` ... errhhh thats not me. There are Pythonic ways in, but I've not implemented them.
  
  
  ---
  
  