张金龙的博客分享 http://blog.sciencenet.cn/u/zjlcas 物种适应性、分布与进化

博文

R软件计算生物多样性指数

已有 56088 次阅读 2010-4-8 13:52 |个人分类:科研笔记|系统分类:科研笔记| 生物多样性, 群落

生物多样性指数的计算在R中计算十分简单,这里介绍一下用vegan包计算生物多样性指数的方法。

首先要将R软件和用到的程序包安装好。在数据处理和格式转换过程中,需要用到openxlsx、reshape2和vegan包。如果没有安装这几个程序包,就在R console中输入以下命令安装。

install.packages('reshape2')
install.packages('openxlsx')
install.packages('vegan')

第一步 在Excel中输入数据

建议将数据整理成样方、物种、个体数格式,这也是样方调查时最常见的一种格式,将数据输入到Excel中。注意:Excel文件列的名字要与下面的格式完全一致,因为R对大小写敏感,所以大小写也要一致。

plotname species abundance
plot1     sp1         3
plot1     sp2         6
plot1     sp3         1
plot1     sp4         2
plot1     sp5         1
plot2     sp1         8
plot2     sp3        30
plot3     sp4         2
plot3     sp2         1
plot3     sp6         1
plot3     sp7         3
.....

保存为 herbplots.xlsx,假设保存在“D:/herb/”。

第二步 读取Excel文件

library(openxlsx)
library(reshape2)
library(vegan)
herb.data <- read.xlsx("D:/herb/herbplots.xlsx")

第三步 转换为样方-物种矩阵

library(reshape2)
herb.mat <- acast(herb.data, 
             formula = plotname ~ species , 
             value.var = "abundance", 
             fill = 0)

此时生成的矩阵,格式如下:

       sp1 sp2 sp3 sp4 sp5 sp6 sp7
plot1   3   6   1   2   1   0   0
plot2   8   0  30   0   0   0   0
plot3   0   1   0   2   0   1   3

第四步 计算生物多样性指数

Shannon-Wiener指数

Shannon.Wiener <- diversity(herb.mat, index = "shannon")

Simpson指数

Simpson <- diversity(herb.mat, index = "simpson")

Inverse Simpson指数

Inverse.Simpson <- diversity(herb.mat, index = "inv")

物种累计数

S <- specnumber(herb.mat)
plot(S)

#Pielou均匀度指数

J <- Shannon.Wiener/log(S)




https://blog.sciencenet.cn/blog-255662-310032.html

上一篇:早春的金缕梅
下一篇:R软件中如何进行群落聚类分析?
收藏 IP: 113.28.150.*| 热度|

2 梅卫平 陆绍暖

该博文允许注册用户评论 请点击登录 评论 (32 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-20 04:28

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部