首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >运行香农和辛普森:素食包

运行香农和辛普森:素食包
EN

Stack Overflow用户
提问于 2019-08-20 16:28:44
回答 1查看 515关注 0票数 1

我对使用素食包计算生物多样性指数很感兴趣。辛普森指数起作用了,但香农论证没有结果。我希望有人知道解决方案

代码语言:javascript
复制
    What I have tried is that I have converted data. frame into vegan
    package test data format using code below  

      Plot     <- c(1,1,2,2,3,3,3)
      species  <- c( "Aa","Aa", "Aa","Bb","Bb","Rr","Xx")
      count   <-  c(3,2,1,4,2,5,7)

      veganData  <- data.frame(Plot,species,count)
      matrify(veganData )
      diversity(veganData,"simpson")
      diversity(veganData,"shannon", base = exp(1))


          1. I get the following results, so I think it produces all
              simpsons indices   

           > diversity(veganData,"simpson")
              simpson.D simpson.I simpson.R
           1      1.00      0.00       1.0
           2      0.60      0.40       1.7
           3      0.35      0.65       2.8


           2. But when I run for Shannon index get the following 
             message 

               > diversity(veganData,"shannon")
              data frame with 0 columns and 3 rows

     I am not sure why its not working ? do we need to make any changes 
      in data formatting while switching the methods?
EN

回答 1

Stack Overflow用户

发布于 2019-08-20 16:39:53

您的数据需要采用宽格式。此外,计数必须是总计数或平均值(不是同一图的重复计数)。

代码语言:javascript
复制
library(dply); library(tidyr)

df <- veganData %>% 
         group_by(Plot, species) %>% 
         summarise(count = sum(count)) %>% 
         ungroup %>% 
         spread(species, count, fill=0)

df
# # A tibble: 3 x 5
#     Plot    Aa    Bb    Rr    Xx
#    <dbl> <dbl> <dbl> <dbl> <dbl>
# 1     1     5     0     0     0
# 2     2     1     4     0     0
# 3     3     0     2     5     7

diversity(df[,-1], "shannon")
# [1] 0.0000000 0.5004024 0.9922820

要检查计算是否正确,请注意-1 \f25 Shannon -1\f6计算作为-1\f25 Pi*lnPi -1\f6的-1\f25 x-1\f6总和

代码语言:javascript
复制
# For plot 3:

-1*(
    (2/(2+5+7))*log((2/(2+5+7))) + #Pi*lnPi of Bb
      (5/(2+5+7))*log((5/(2+5+7))) + #Pi*lnPi of Rr 
        (7/(2+5+7))*log((7/(2+5+7))) #Pi*lnPi of Xx
    )

 # [1] 0.992282
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57569573

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档