R计算功能多样性— functional diversity (FD)

Python010

R计算功能多样性— functional diversity (FD),第1张

一般植物功能特征被划分为3类:一是植物形态特征, 包括生长型、生活型、植株高度等;二是植物生殖特征,包括传粉方式、扩散方式、种子重量等;三是植物生理特征, 如植物固氮能力等[30].

为研究中包括的每个物种创建一个定性和/或定量性状的矩阵;使用R中的FD包来计算你选择的性状的种间Gower距离。Gower距离矩阵可用于绘制树状图,描述物种间的相似性/不相似性,然后你可以使用R中的FD或BAT或其他软件包,以类似于计算系统发育多样性(PD)的方式,总结连接每个物种库中的物种的分支长度。 参考: https://www.researchgate.net/post/Can_anyone_help_with_measuring_functional_diversity

FD computes different multidimensional FD indices. Tocompute FD indices, a species-by-trait(s) matrix is required (or at least aspecies-by-species distance matrix). gowdis computes the Gower dissimilarityfrom different trait types (continuous, ordinal, nominal, or binary), andtolerates NAs. It can treat ordinal variables as described by Podani (1999),and can handle asymetric binary variables and variable weights. gowdis iscalled by dbFD , the main function of FD.】

dbFD uses principal coordinates analysis (PCoA) toreturn PCoA axes, which are then used as ‘traits’to compute FD. dbFD computesseveral multidimensional FD indices, including the three indices of Villéger etal. (2008): functional richness (FRic), functional evenness (FEve), andfunctional divergence ( FDiv ). It also computesfunctional dispersion (FDis) (Laliberté and Legendre 2010), Rao’s quadraticentropy (Q) (Botta-Dukát 2005), a posteriori functional group richness (FGR),and the community-level weighted means of trait values (CWM), an index offunctional composition. Some of these indices can be weighted by speciesabundances. dbFD includes several options for flexibility.

基本命令:  dbFD(x, a, w, w.abun = TRUE, stand.x = TRUE,..)

x: 功能特征的矩阵或数据框架

a: 包括出现在x中的物种丰富度矩阵。The number of species (columns) in a must match the number of species (rows) in x. In addition, thespecies labels in a and x must be identical and in the same order. (x和a两个数据集的物种数目一致和顺序相同)

建立两个数据dataframe, 保持两个数据集中的物种名称顺序保持一致:

情况1:手动录入的数据,或者数据量少的数据可手动调节;

情况2:物种较多,两个数据集包含较多的物种名称不一致情况;

解决办法:使用excel,若X和a中的物种不完全相符,以物种较少的数据物种数目为准,删减x中的数据以对应a。利用数据透视表功能建立数据矩阵; 注意: a中物种名称若出现空格,将不能成功读取,会出现格式变化,建议标准物种名称为“Abies_chensiensis”(加短横线)。

library(“FD”)   #加载FD包

traits <- read.csv("D:/ xxx.csv", row.names=1)   #x,加载数据

species <- read.csv("D:/xxx.csv", header=T,row.names=1)   #a,加载数据

rownames(traits)  #查看导入数据的行列名称,是否有不一致情况

colnames(traits)  #查看导入数据的行列名称,是否有不一致情况

rownames(species)  #查看导入数据的行列名称,是否有不一致情况

colnames(species)  #查看导入数据的行列名称,是否有不一致情况

results  = dbFD(traits, species, corr="lingoes")    #dbFD计算FD值

 解决办法:a =dbFD(traits, species, corr="lingoes")

write.csv(results,file = "D:/ xxx-FD-results.csv")  #数据导出,结果导出为csv格式数据

## FD一般是FR,FE,FD三个层面,FR指功能多样性丰富度,FE值功能多样性均匀度,FD值功能多样性离散度。

1、通过选择菜单:

程序包->安装程序包->在弹出的对话框中,选择你要安装的包,然后确定。

2、使用命令

install.packages(package_name,dir)

package_name:是指定要安装的包名,请注意大小写。

dir:包安装的路径。默认情况下是安装在..\library 文件夹中的。可以通过本参数来进行修改,来选择安装的文件夹。

3、本地来安装

如果你已经下载的相应的包的压缩文件,则可以在本地来进行安装。请注意在windows、unix、macOS操作系统下安装文件的后缀名是不一样的:

1)linux环境编译运行:tar.gz文件

2)windows 环境编译运行 :.zip文件

3)MacOSg环境编译运行:.tgz文件

注:包安装好后,并不可以直接使用,如果在使用包中相关的函数,必须每次使用前包加载到内存中。通过library(package_name)来完成。 包安装后,如果要使用包的功能。必须先把包加载到内存中(默认情况下,R启动后默认加载基本包),加载包命令:

Library(“包名”)

Require(“包名”) 1、查看包帮忙

library(help=package_name)

主要内容包括:例如:包名、作者、版本、更新时间、功能描述、开源协议、存储位置、主要的函数

help(package = package_name)

(1)人员编号->姓名 人员编号->性别 职位编号->职位名称 (人员编号,职位编号)->考试成绩

关键码(人员编号,职位编号)

(2)1

(3)renyuan(人员编号,姓名,性别)

zhiwei(职位编号,职位名称)

R(人员编号,职位编号,成绩)