Answers.Body: <p>I assume the OP has correctly rooted all trees in the analysis consistently. If this has not happened then that could be problematic and explain the discrepancy.</p>
  <p>Otherwise ....</p>
  <hr />
  <p>Basically I suspect this data is single locus metagenomics. Build a tree and quantitate the phylogenetic distance as a metric.
  The pd scores between the figure and the individual samples are not comparable, because the figure appears to represent grouped samples. The values from individual samples need some definition about what they represent. More generally an additional layer of analysis is required like Kraken2 to underpin what the diversity is and whether it is representative of the sample.</p>
  <p>Basically, if this is all the information provided, the pd scores are not necessarily low, its just comparing grouped data to individual samples. Grouped data will inevitably cause a large shift in genetic diversity represented by pd.</p>
  <p>Thus two samples of pd = 3 could generate a pd of 40 when combined, but it depends on the species composition of the samples.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-10-28T16:41:17.653Z
Answers.LastActivityDate: 2024-10-29T12:06:21.083Z
Answers.LastEditDate: 2024-10-29T12:06:21.083Z
Answers.UserDisplayName: M__
Body: <p>I am trying to compute Faith's pd for the first time using the picante package in R.</p>
  <p>My code is the following:</p>
  <pre><code>library(picante)
  library(tidyverse)
  
  set.seed(19990409)
  
  setwd(&quot;~/Desktop/Urbanization/Bacteria_QIIME2/Urb_Grad&quot;)
  
  
  # loading a tsv list that has all OTUs as the first column, then all samples with the subsequent abundance of the OTU and taxonomy
  #  data has been rarefied to match the sample with the fewest observed features
  
  tab_samp_feat &lt;- read_tsv(&quot;feature_and_taxonomy.txt&quot;,col_types = list(OTU_ID=col_character(),
                                                                       taxonomy=col_character(),
                                                                       .default=col_number()))
  
  tab_samp_feat &lt;- tab_samp_feat %&gt;% select(-taxonomy) %&gt;%
    rotate_df()
  colnames(tab_samp_feat) &lt;- tab_samp_feat[1,]
  tab_samp_feat &lt;- tab_samp_feat[-1,]
  
  
  metadata &lt;- read_tsv(&quot;Metadata.csv&quot;, col_types = cols(Samples = col_character(),
                                                                                        Sampling_season = col_character(),
                                                                                        Site = col_character(),
                                                                                        .default = col_number())) %&gt;%
    select(c(&quot;Samples&quot;, &quot;Sampling_season&quot;, &quot;Site&quot;)) %&gt;% as.matrix()
  rownames(metadata) &lt;- metadata[,1]
  metadata &lt;- metadata[,-1]
  
  # rooted tree exported from QIIME2
  phy &lt;- read.tree(&quot;Exported/tree.nwk&quot;)
  
  
  combined &lt;- match.phylo.comm(phy, tab_samp_feat)
  
  phy &lt;- combined<span class="math-container">$phy
  dat &lt;- combined$</span>comm
  metadata &lt;- metadata[match(rownames(dat), rownames(metadata)), ]
  all.equal(rownames(dat), rownames(metadata))
  
  
  dat.pd &lt;- pd(dat, phy)
  head(dat.pd)
  boxplot(dat.pd<span class="math-container">$PD ~as.data.frame(metadata)$</span>Site, xlab = &quot;Site&quot;, ylab = &quot;PD&quot;)
  
  </code></pre>
  <p>Everything seems to work alright, in the sense of all OTUs in my samples existing in the tree and the order of the metadata samples being the same as the order of the data. But the output is very strange:
  <a href="https://i.sstatic.net/raM303kZ.png" rel="nofollow noreferrer">PD results:</a></p>
  <p>The PD metric is very low, but I think that is a consequence of the very small SR number for most samples. However I believe that is wrong as for example, even when looking at the first sample M-N1 there are way more than two OTUs present.
  <a href="https://i.sstatic.net/MXZPRIpB.png" rel="nofollow noreferrer">Screenshot of more than 2 features being present in the M-N1 sample</a></p>
  <p>I was expecting the SR column to reflect the real presence/absence data of the features in my sample and for SR and PD to have more balanced values.
  I would be so grateful if anyone could help me realize what it is that I am doing wrong.
  Thank you!</p>
  <p>Update: I tried using QIIME2 to visualize the Faith pd metric and the results look like the following:</p>
  <p><a href="https://i.sstatic.net/IbGYCtWk.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/IbGYCtWk.png" alt="Faith pd boxplots computed with QIIME2 and expected result for the R analysis" /></a></p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-10-25T20:21:19.703Z
Comments.Text: The question has been given a tag of "microbiology". What species groups are being analysed and any biogeographic or sample information. Is this metagenomics data?
  Basically, the question cannot be answered without surrounding biological information, because its not clear whether "high" or "medium" phylogenetic diversity should be expected.
Comments.UserDisplayName: M__
Tags: <r><phylogeny><microbiology>
Title: When calculating Faith pd with picante package in R species richness appears very low for most samples but that is not true
ThreadText: # When calculating Faith pd with picante package in R species richness appears very low for most samples but that is not true
  
  (Asked by: username_0 on 2024-10-21)
  
  I am trying to compute Faith's pd for the first time using the picante package in R.
  
  My code is the following:
  
  ```
  library(picante)
  library(tidyverse)
  
  set.seed(19990409)
  
  setwd("~/Desktop/Urbanization/Bacteria_QIIME2/Urb_Grad")
  
  # loading a tsv list that has all OTUs as the first column, then all samples with the subsequent abundance of the OTU and taxonomy
  #  data has been rarefied to match the sample with the fewest observed features
  
  tab_samp_feat <- read_tsv("feature_and_taxonomy.txt",col_types = list(OTU_ID=col_character(),
                                                                       taxonomy=col_character(),
                                                                       .default=col_number()))
  
  tab_samp_feat <- tab_samp_feat %>% select(-taxonomy) %>%
    rotate_df()
  colnames(tab_samp_feat) <- tab_samp_feat[1,]
  tab_samp_feat <- tab_samp_feat[-1,]
  
  metadata <- read_tsv("Metadata.csv", col_types = cols(Samples = col_character(),
                                                                                        Sampling_season = col_character(),
                                                                                        Site = col_character(),
                                                                                        .default = col_number())) %>%
    select(c("Samples", "Sampling_season", "Site")) %>% as.matrix()
  rownames(metadata) <- metadata[,1]
  metadata <- metadata[,-1]
  
  # rooted tree exported from QIIME2
  phy <- read.tree("Exported/tree.nwk")
  
  combined <- match.phylo.comm(phy, tab_samp_feat)
  
  phy <- combined$phy
  dat <- combined$comm
  metadata <- metadata[match(rownames(dat), rownames(metadata)), ]
  all.equal(rownames(dat), rownames(metadata))
  
  dat.pd <- pd(dat, phy)
  head(dat.pd)
  boxplot(dat.pd$PD ~as.data.frame(metadata)$Site, xlab = "Site", ylab = "PD")
  
  ```
  
  Everything seems to work alright, in the sense of all OTUs in my samples existing in the tree and the order of the metadata samples being the same as the order of the data. But the output is very strange:
  [PD results:](https://i.sstatic.net/raM303kZ.png)
  
  The PD metric is very low, but I think that is a consequence of the very small SR number for most samples. However I believe that is wrong as for example, even when looking at the first sample M-N1 there are way more than two OTUs present.
  [Screenshot of more than 2 features being present in the M-N1 sample](https://i.sstatic.net/MXZPRIpB.png)
  
  I was expecting the SR column to reflect the real presence/absence data of the features in my sample and for SR and PD to have more balanced values.
  I would be so grateful if anyone could help me realize what it is that I am doing wrong.
  Thank you!
  
  Update: I tried using QIIME2 to visualize the Faith pd metric and the results look like the following:
  
  [![Faith pd boxplots computed with QIIME2 and expected result for the R analysis](https://i.sstatic.net/IbGYCtWk.png)](https://i.sstatic.net/IbGYCtWk.png)
  
  **Tags:** r, phylogeny, microbiology
  
  > **Comments:**
  > **username_1**: The question has been given a tag of "microbiology". What species groups are being analysed and any biogeographic or sample information. Is this metagenomics data? Basically, the question cannot be answered without surrounding biological information, because its not clear whether "high" or "medium" phylogenetic diversity should be expected.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2024-10-28. Score: 0
  
  I assume the OP has correctly rooted all trees in the analysis consistently. If this has not happened then that could be problematic and explain the discrepancy.
  
  Otherwise ....
  
  ---
  
  Basically I suspect this data is single locus metagenomics. Build a tree and quantitate the phylogenetic distance as a metric.
  The pd scores between the figure and the individual samples are not comparable, because the figure appears to represent grouped samples. The values from individual samples need some definition about what they represent. More generally an additional layer of analysis is required like Kraken2 to underpin what the diversity is and whether it is representative of the sample.
  
  Basically, if this is all the information provided, the pd scores are not necessarily low, its just comparing grouped data to individual samples. Grouped data will inevitably cause a large shift in genetic diversity represented by pd.
  
  Thus two samples of pd = 3 could generate a pd of 40 when combined, but it depends on the species composition of the samples.
  
  
  ---
  
  