# Discrepancies in Shannon Index Calculations Between QIIME2 and vegan R Package

**URL:** https://forum.qiime2.org/t/discrepancies-in-shannon-index-calculations-between-qiime2-and-vegan-r-package/32231
**Category:** User Support
**Created:** [January 2, 2025, 12:55pm UTC](https://forum.qiime2.org/t/discrepancies-in-shannon-index-calculations-between-qiime2-and-vegan-r-package/32231 "2025-01-02T12:55:44Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Bella](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/b/ce73a5/32.png) [@Bella](https://forum.qiime2.org/u/Bella)
#### Post date: [January 2, 2025, 12:55pm UTC](https://forum.qiime2.org/t/discrepancies-in-shannon-index-calculations-between-qiime2-and-vegan-r-package/32231/1 "2025-01-02T12:55:44Z")

</div>

Hi QIIME2 Team,

I've encountered some discrepancies when calculating the Shannon index using two different methods: QIIME2 and the diversity function from the R package vegan. I followed the "Moving Pictures" tutorial to compute the Shannon index in QIIME2 with the following command:

```auto
qiime diversity alpha-group-significance \
  --i-alpha-diversity shannon_vector.qza \
  --m-metadata-file metadata.txt \
  --o-visualization shannon-group-significance.qzv

```

This was done after applying the `core-metrics-phylogenetic` method. However, when I attempted to calculate the Shannon index using the vegan package in R, I found that the results were different, and the significance between groups was inconsistent.

I understand that the two methods might use different bases for their calculations, such as base 2 for QIIME2 and base e for vegan. Even after converting the results to a common base, the discrepancy remains unclear.

Additionally, I've noticed that the values for corresponding samples are significantly different. For instance, QIIME2 yielded values of 7.02, 7.68, and 6.96, while vegan provided 3.60, 5.07, and 4.77.

I also considered the downsampling performed in the `core-metrics-phylogenetic` method and tried the following command:

```auto
qiime diversity alpha \
  --i-table table.qza \
  --p-metric shannon \
  --o-alpha-diversity shannon_vector.qza

```

Unfortunately, this did not resolve the issue.

I'm curious to know what might be causing these differences and how I can reconcile the results.

Best,  
Bella

---

<div class="post-metadata">

### Author: ![colinvwood](https://forum.qiime2.org/user_avatar/forum.qiime2.org/colinvwood/32/17303_2.png) [@colinvwood](https://forum.qiime2.org/u/colinvwood)
#### Post date: [January 2, 2025, 5:51pm UTC](https://forum.qiime2.org/t/discrepancies-in-shannon-index-calculations-between-qiime2-and-vegan-r-package/32231/2 "2025-01-02T17:51:49Z")

</div>

Hello @Bella,

What version of qiime2 are you using? Which R function did you use? Were the input tables to each method the same?

---

<div class="post-metadata">

### Author: ![Bella](https://forum.qiime2.org/letter_avatar_proxy/v4/letter/b/ce73a5/32.png) [@Bella](https://forum.qiime2.org/u/Bella)
#### Post date: [January 3, 2025, 11:43am UTC](https://forum.qiime2.org/t/discrepancies-in-shannon-index-calculations-between-qiime2-and-vegan-r-package/32231/3 "2025-01-03T11:43:12Z")

</div>

Hello @colinvwood,

I'm using QIIME2 version `q2cli 2024.5.0` and have computed the Shannon index using the `diversity()` function from the vegan package. Upon verification, I've confirmed that the input tables for both `diversity()` and `qiime diversity alpha` are indeed the same.

---

<div class="post-metadata">

### Author: ![colinvwood](https://forum.qiime2.org/user_avatar/forum.qiime2.org/colinvwood/32/17303_2.png) [@colinvwood](https://forum.qiime2.org/u/colinvwood)
#### Post date: [January 3, 2025, 5:51pm UTC](https://forum.qiime2.org/t/discrepancies-in-shannon-index-calculations-between-qiime2-and-vegan-r-package/32231/4 "2025-01-03T17:51:38Z")

</div>

Hello @Bella,

Using a QIIME2 2024.5 amplicon environment and running `qiime diversity alpha` with `--p-metric shannon` and `vegan::diversity` with `base = 2` on the feature table from the moving pictures tutorial yield the same per-sample vector of diversity indices for me. Perhaps you could retrace your steps and see if you overlooked something?

---

<div class="post-metadata">

### Author: ![system](https://forum-qiime2-org.s3.dualstack.us-west-2.amazonaws.com/original/3X/2/1/21af5fe23cb6f4579467c66a9ed94e55274ca7bd.svg) [@system](https://forum.qiime2.org/u/system)
#### Post date: [February 3, 2025, 11:52pm UTC](https://forum.qiime2.org/t/discrepancies-in-shannon-index-calculations-between-qiime2-and-vegan-r-package/32231/5 "2025-02-03T23:52:35Z")

</div>

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.
