无意落入生态学功能性多样性公式计算,R代码分享。包括FAD,MFAD,FD,FRIC,FEs,FEve,FDQ,FDiv

本文分享了使用R语言进行生态学功能性多样性计算的详细步骤,涵盖了FAD、MFAD、FD、FRIC、FEs、FEve、FDQ、FDiv等指标的计算方法,并提供了相应的R代码示例。
摘要由CSDN通过智能技术生成

---
title: "Bio_diversity"
author: "jin"
date: "2018年11月18日"
output: word_document
---
```{r}
knitr::opts_chunk$set(warning = F,message = F)
```

```{r setup}
setwd("C:/Users/jack/Desktop/mission/bio diversity")
library(readxl)
library(FD)
sample <- read_excel("sample.xlsx")
feature<-as.data.frame(sample[,-c(1,length(sample))])
abundance<-as.data.frame(sample[,length(sample)])
abundance<-t(abundance)
colnames(abundance)<-sample$种名
rownames(feature)<-sample$种名
feature
```

```{r load the data}
ex1<-dbFD(feature,abundance)
```

#功能性状距离FAD

```{r 功能性状距离FAD}
sum(dist(feature))

```

#功能性状平均距离MFAD
```{r 功能性状平均距离MFAD}
sum(dist(feature))/nrow(feature)

```

#功能树状图指数 FD
```{r 功能树状图指数 FD}
#Xtree
Xtree <- function(h)
{
  species.names <- h$labels 
  H1 <- matrix(0, length(h$order), 2 * length(h$order) - 2)
  l <- vector("numeric", 2 * length(h$order) - 2)
  for(i in 1:(length(h$order) - 1)) {
    # evaluate branch lengths
    #
    if(h$merge[i, 1] < 0) {
      l[2 * i - 1] <- h$height[order(h$height)[i]]
      H1[ - h$merge[i, 1], 2 * i - 1] <- 1
    }
    else {
      l[2 * i - 1] <- h$height[order(h$height)[i]] - h$height[order(h$height)[h$merge[i, 1]]]
      H1[, 2 * i - 1] <- H1[, 2 * h$merge[i, 1] - 1] + H1[
        , 2 * h$merge[i, 1]]
    }
 

评论 41
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值