Defaunation reshapes the distribution of biomass of tropical wild mammals
收藏资源简介:
This repository contains the data and the 13 R scripts for the analysis of wild mammal biomass loss and changes in community weighted means of body mass across tropical forests at 50x50km resolution. Important note: Due to data use agreements and copyright restrictions, only the input data required to run analyses from Script 07 onwards are provided in this repository. Data Folder Structure The Data/ folder contains all input data required to run the analyses. Due to data use restrictions, only the files needed for Scripts 08-13 are provided in this repository. Below is a description of each subdirectory: Data/Output/Abundance_Matrix/ Contains 20 CSV files with species abundance matrices) for each scenario and confidence interval. Each file represents a combination of scenario (Natural, IUCN_Historical, Hloss, Hunting, COMB) and statistical metric (Mean, lw95, up75, up95). These matrices are the aggregated input for biomass and CWM computations. Data/Output/Biomass_Matrix/ Contains 20 CSV files with biomass matrices derived from abundance matrices multiplied by species body mass. Files follow the same naming convention as abundance matrices and serve as input for total biomass calculations and supplementary tables. Data/Output/CWM/ Contains 5 CSV files with Community Weighted Mean (CWM) body mass values per grid cell. Includes CWM for all mammals combined and separately for each trophic guild: Herbivores, Carnivores, Omnivores, and Invertivores. These files are used for statistical analysis and map visualization. Data/Spatial/World/ Contains the World shapefile (World.shp with associated .shx, .dbf, .prj, .cpg) used as a basemap for generating global figures in scripts 10 and 11. The shapefile is projected to Mollweide CRS for consistency with all spatial outputs. Data/Traits/ Contains Density_Traits_Predictions.csv, which includes trophic guild classification and diet trait data for all mammal species. This file is required for computing guild-specific CWM values. Note: The individual species CSV files from Data/Output/Mammal_50x50_Abundances/ are not included in this Zenodo repository due to space constraints. However, these are not required to run Scripts 08-13, as all necessary data are already aggregated in the abundance matrices, biomass matrices, and CWM files provided. R Codes Folder Structure Note: Scripts 01-06 require external datasets (e.g., IUCN Red List species ranges, PHYLACINE natural ranges, Santini's population density models, and high-resolution spatial predictors) that cannot be shared publicly. However, these scripts are fully documented for transparency. Scripts 08-13 are fully runnable as they process intermediate outputs generated from previous steps and do not require restricted external data. Users interested in reproducing the full pipeline should request access to the restricted datasets from the respective data providers (IUCN, PHYLACINE, etc.) following their data use policies. 01_Prep_Data.R: Rasterizes tropical forest shapefile to 50x50 km grid and extracts spatial predictors (distance to hunters’ access points, travel time to major cities, human population density, stunting prevalence, NPP, livestock biomass, protected areas, countries ISO code, precipitation CV, NDVI) for population density and hunting impacts predictions. 02_Frac_Covers.R: Computes fractional cover of PNV (Potential Natural Vegetation) and current anthropogenic habitats at 50x50 km resolution. Processes forest, savanna, shrubland, grassland, wetlands, rocky areas, desert, and artificial habitats 03_Mammal_Ranges.R: Extracts present natural ranges (PHYLACINE), current IUCN ranges, and IUCN ranges with extinct polygons for tropical mammals at 50x50km resolution. Processes species name crosswalks, handles taxonomic discrepancies between datasets, rasterizes distribution polygons, and creates individual CSV files per species with presence/absence data. 04_Hunting_Impacts.R: Hunting impacts on tropical mammals using hurdle models (binomial + Gaussian), validates model independence via residual correlation and covariance, rescales predictors and generates predictions for each species across its historical and current ranges, including uncertainty per species per grid cell. 05_Dens_Predictions.R: Population densities for tropical mammals using Santini's GAMM model for projecting density estimates (log10 and natural log scales) across species ranges, including uncertainty per species per grid cell. 06_Suitable_Cover_Estimation.R: Extracts suitable habitat preferences and elevation ranges for each mammal species via IUCN Red List API in parallel. Computes Area of Habitat (AOH) by summing fractional covers of suitable PNV and current habitat types, applies elevation filters, aggregates to 50x50km resolution, and integrates results into species presence dataframes. Handles errors and reprocesses missing species. 07_Abundance_Estimation.R: Propagates uncertainty from three models (hunting impact models and population density models) using delta method (analytical and derivative approaches). Calculates abundances per grid cell (multiplying by 2500 km² and suitable habitat fraction) for the five scenarios. Computes mean abundances with 95% confidence intervals. 08_Biomass_Species.R: Converts abundances to biomass per species across five scenarios. Creates spatial biomass matrices (3785 species × grid cells) for each scenario and confidence interval. Summarizes biomass by order, realm (Neotropical, Afrotropical, Indomalayan, Pantropical), and scenario. Generates stacked bar plots and calculates percentage changes between scenarios. 09_CWM_Computation.R: Computes Community Weighted Mean (CWM) body mass for each grid cell across five scenarios. Creates abundance matrices (3785 species × grid cells), calculates relative abundances, multiplies by species body mass, and sums to obtain CWM. Disaggregates analyses by trophic guild (Herbivores, Carnivores, Invertivores, Omnivores). Computes deltas between Combined and Baseline scenarios. Outputs CWM rasters for all mammals and each trophic guild separately. 10_CWM_Results.R: Generates statistical summaries and visualizations of CWM results. Calculates summary statistics (mean, median, quantiles, SD) for baseline and defaunated scenarios across realms. Performs paired Wilcoxon tests to compare scenarios. Creates global maps of relative change (ΔCWM) for all mammals and by trophic guild using Mollweide projection. Produces density distribution plots comparing baseline vs COMB scenarios across guilds. 11_Biomass_Results.R: Computes total biomass estimates for baseline and anthropogenic scenarios. Calculates relative changes (Δ) and confidence intervals for biomass loss across realms. Disaggregates contributions of habitat loss vs overhunting as drivers of defaunation. Generates global biomass distribution maps and identifies top-10 contributing species per realm. Creates figures comparing baseline, habitat loss, hunting, and combined scenarios for tropical forests. 12_Supp_Tables_CWM.R: Generates supplementary tables for CWM (Community Weighted Mean) body mass analysis. Produces five tables: (1) CWM distribution statistics across scenarios and realms, (2) Deltas between baseline and defaunation scenarios (HL, OH, COMB) using both PHYLACINE and IUCN baselines, (3) Comparison between overhunting and habitat loss scenarios, (4) CWM distribution by trophic guild across scenarios and realms, (5) Relative changes in CWM by trophic guild. Includes Wilcoxon signed-rank tests with significance levels. Exports tables as Excel and CSV files for manuscript supplementary materials. 13_Supp_Tables_Biomass.R: Generates supplementary tables for biomass analysis. Produces three tables: (6) Total biomass across the tropics and realms per scenario (mean, 75% CI, 95% CI), (7) Deltas and statistical differences in biomass across scenarios using both PHYLACINE and IUCN baselines, (8) Comparison between overhunting and habitat loss scenarios for biomass loss. Includes Wilcoxon signed-rank tests with significance levels. Exports tables as Excel and CSV files for manuscript supplementary materials. System requirements Hardware: - Minimum RAM: 32 GB (your system has 36 GB, which is adequate) - Recommended RAM: 64 GB for running scripts 04-07 in parallel without memory swapping - Storage: 50 GB free space (for intermediate raster files and species-level abundance matrices) - CPU: 8+ cores (your Apple M3 Pro has 12 physical cores / 12 threads) *The analysis was developed and tested on a Mac laptop with Apple M3 Pro (12 cores, 36 GB RAM).* Software dependencies - R version: 4.4.0 or higher (tested on 4.4.0) - RStudio (optional) Performance note Scripts 1-07 use parallel processing across species. On the Apple M3 Pro (12 cores, 36 GB RAM): Scripts 01-07 (full pipeline with restricted data): > 5 days Scripts 08-13 (provided data only): 30-1 hour R Packages used: Data Manipulation & Transformation dplyr for data frame manipulation, filtering, joining and summarising data.table for high-performance data manipulation and fast file I/O tidyr for data reshaping and tidying tibble for data frame structure and consistent output stringr for string manipulation and pattern matching readr for fast reading and writing of CSV files readxl for importing Excel files (.xlsx, .xls) writexl for exporting data frames to Excel format scales for data scaling, transformation and axis formatting Spatial Analysis & GIS terra for raster and vector spatial data manipulation, projections, aggregations and extraction sf for vector spatial data handling and GIS operations mapview for interactive visualization of spatial data raster for legacy raster operations (older code sections) Statistical Modeling glmmTMB for generalized linear mixed models in hunting impact predictions mgcv for Generalized Additive Models (GAM) in density predictions Parallel Processing foreach for parallel loop construction doParallel as backend for parallel execution across multiple CPU cores parallel for core parallelization functions (detectCores, cluster creation) Data Visualization ggplot2 for publication-quality graphics and custom plotting ggpubr for arranging multiple plots and adding statistical annotations ggtext for enhanced text formatting (markdown, HTML) in ggplot2 API & Web Services rredlist for interface to IUCN Red List API iucnredlist for alternative IUCN API client for species assessments Utilities & Performance matrixStats for fast row/column-wise matrix operations openxlsx for reading and writing Excel files with formatting tictoc for execution time measurement and performance profiling tools for file path manipulation To install R packages, run the following code in R: install.packages(c("dplyr", "data.table", "tidyr", "tibble", "stringr", "readr", "readxl", "writexl", "scales", "terra", "sf", "raster", "glmmTMB", "mgcv", "foreach", "doParallel", "parallel", "ggplot2", "ggpubr", "ggtext", "rredlist", "iucnredlist", "matrixStats", "openxlsx", "tictoc", "tools"))
本仓库包含用于分析50×50km分辨率热带森林区域野生哺乳动物生物量损失以及群落加权平均体重(Community Weighted Mean, CWM)变化的数据集与13个R脚本。 重要说明:受数据使用协议与版权限制,本仓库仅提供从脚本07起运行分析所需的输入数据。 数据文件夹结构 Data/文件夹包含运行分析所需的全部输入数据。受数据使用限制,本仓库仅提供脚本08-13所需的文件。以下为各子目录的说明: Data/Output/Abundance_Matrix/:包含20个CSV文件,对应各情景与置信区间的物种多度矩阵。每个文件对应一种情景(自然状态、IUCN红色名录历史范围、生境丧失、狩猎压力、综合影响)与一种统计指标(均值、下限95%置信区间、上限75%置信区间、上限95%置信区间)。此类矩阵为生物量与CWM计算的聚合输入数据。 Data/Output/Biomass_Matrix/:包含20个CSV文件,为通过多度矩阵乘以物种种体重得到的生物量矩阵。文件命名规则与多度矩阵一致,可作为总生物量计算与辅助表格制作的输入数据。 Data/Output/CWM/:包含5个CSV文件,存储每个网格单元的CWM值。涵盖所有哺乳动物整体以及各营养类群(植食性动物、肉食性动物、杂食性动物、食虫性动物)的CWM数据,用于统计分析与地图可视化。 Data/Spatial/World/:包含世界矢量shapefile文件(World.shp及关联的.shx、.dbf、.prj、.cpg文件),用于在脚本10与11中生成全球图表的底图。该shapefile采用莫尔韦德投影坐标系(Mollweide CRS),以与所有空间输出保持一致。 Data/Traits/:包含Density_Traits_Predictions.csv文件,该文件包含所有哺乳动物物种种的营养类群分类与食性特征数据,是计算类群特异性CWM值的必要输入文件。 注意:受存储空间限制,Data/Output/Mammal_50x50_Abundances/目录下的单个物种种CSV文件未包含在本Zenodo仓库中。但运行脚本08-13无需此类文件,因为所有必要数据已聚合至提供的多度矩阵、生物量矩阵与CWM文件中。 R代码文件夹结构 注意:脚本01-06需要使用外部数据集(如IUCN红色名录(IUCN Red List)物种分布范围、PHYLACINE自然分布范围、Santini种群密度模型与高分辨率空间预测因子),此类数据无法公开共享。但为保证透明度,所有脚本均已完成详细文档说明。脚本08-13可直接运行,其处理的是此前步骤生成的中间输出文件,无需受限的外部数据。若用户希望复现完整分析流程,需按照数据使用政策,向对应数据提供方(IUCN、PHYLACINE等)申请获取受限数据集的访问权限。 01_Prep_Data.R:将热带森林shapefile栅格化为50×50km网格,并提取空间预测因子(狩猎通路距离、前往大城市的通行时间、人口密度、发育迟缓患病率、净初级生产力(Net Primary Productivity, NPP)、牲畜生物量、保护区、国家ISO代码、降水变异系数、归一化植被指数(Normalized Difference Vegetation Index, NDVI)),用于种群密度与狩猎影响预测。 02_Frac_Covers.R:计算50×50km分辨率下潜在自然植被(Potential Natural Vegetation, PNV)与当前人为生境的分数覆盖度,处理森林、稀树草原、灌丛、草地、湿地、岩石区域、荒漠与人工生境。 03_Mammal_Ranges.R:提取热带哺乳动物的当前自然分布范围(PHYLACINE)、当前IUCN分布范围以及包含灭绝多边形的IUCN分布范围,分辨率为50×50km。处理物种名称对照表,解决不同数据集间的分类学差异,将分布多边形栅格化,并为每个物种种生成包含存在/不存在数据的单个CSV文件。 04_Hunting_Impacts.R:使用障碍(hurdle)模型(二项分布+高斯分布)分析狩猎对热带哺乳动物的影响,通过残差相关性与协方差验证模型独立性,对预测因子进行标准化,并为每个物种种在其历史与当前分布范围内生成预测结果,包含每个网格单元每个物种种的不确定性信息。 05_Dens_Predictions.R:使用Santini的广义加性混合模型(Generalized Additive Mixed Model, GAMM)预测热带哺乳动物的种群密度,在物种种分布范围内投影密度估计值(log10与自然对数尺度),包含每个网格单元每个物种种的不确定性信息。 06_Suitable_Cover_Estimation.R:通过并行调用IUCN红色名录API,提取每个哺乳动物物种种的适宜生境偏好与海拔范围。通过汇总适宜PNV与当前生境类型的分数覆盖度计算生境面积(Area of Habitat, AOH),应用海拔过滤条件,聚合至50×50km分辨率,并将结果整合至物种种存在数据框中。处理错误并重新处理缺失物种。 07_Abundance_Estimation.R:使用delta方法(解析法与导数法)传播三个模型(狩猎影响模型与种群密度模型)的不确定性。针对五种情景计算每个网格单元的种群多度(乘以2500km²与适宜生境分数占比),计算带有95%置信区间的平均多度。 08_Biomass_Species.R:将各情景下的种群多度转换为物种种生物量,为每种情景与置信区间生成空间生物量矩阵(3785个物种种 × 网格单元)。按物种种目级、生物地理区(新热带区(Neotropical)、非洲热带区(Afrotropical)、印澳区(Indomalayan)、泛热带区(Pantropical))与情景汇总生物量,生成堆叠条形图并计算情景间的百分比变化。 09_CWM_Computation.R:计算五种情景下每个网格单元的CWM值。生成多度矩阵(3785个物种种 × 网格单元),计算相对多度,乘以物种种体重后求和得到CWM值。按营养类群(植食性动物、肉食性动物、食虫性动物、杂食性动物)拆分分析,计算综合情景与基线情景间的差值。输出所有哺乳动物及各营养类群单独的CWM栅格文件。 10_CWM_Results.R:生成CWM结果的统计汇总与可视化内容。计算各生物地理区内基线情景与去动物群情景的汇总统计量(均值、中位数、分位数、标准差),进行配对Wilcoxon符号秩检验(Wilcoxon signed-rank test)以比较不同情景。使用莫尔韦德投影生成所有哺乳动物及各营养类群的相对变化(ΔCWM)全球地图,生成各营养类群基线情景与综合情景的密度分布对比图。 11_Biomass_Results.R:计算基线与人为活动情景下的总生物量估计值,计算各生物地理区生物量损失的相对变化(Δ)与置信区间,拆分生境丧失与狩猎压力作为动物群丧失驱动因子的贡献。生成全球生物量分布地图,识别每个生物地理区内贡献最大的前10个物种种。生成对比热带森林区域基线、生境丧失、狩猎压力与综合情景的图表。 12_Supp_Tables_CWM.R:生成CWM分析的辅助表格。共生成5张表格:(1) 各情景与生物地理区内的CWM分布统计量;(2) 基线情景与去动物群情景(生境丧失、狩猎压力、综合影响)的差值(同时使用PHYLACINE与IUCN基线);(3) 狩猎压力与生境丧失情景的对比;(4) 各情景与生物地理区内按营养类群划分的CWM分布;(5) 各营养类群的CWM相对变化。包含带有显著性水平的Wilcoxon符号秩检验结果。将表格导出为Excel与CSV格式,用于论文补充材料。 13_Supp_Tables_Biomass.R:生成生物量分析的辅助表格。共生成3张表格:(6) 全球热带区域及各生物地理区内各情景的总生物量(均值、75%置信区间、95%置信区间);(7) 各情景间生物量的差值与统计差异(同时使用PHYLACINE与IUCN基线);(8) 狩猎压力与生境丧失情景对生物量损失的对比。包含带有显著性水平的Wilcoxon符号秩检验结果。将表格导出为Excel与CSV格式,用于论文补充材料。 系统要求 硬件: - 最低内存:32 GB(本系统配备36 GB内存,满足要求) - 推荐内存:64 GB,用于并行运行脚本04-07且不发生内存交换 - 存储空间:需50 GB可用空间(用于存储中间栅格文件与物种种级多度矩阵) - CPU:8核及以上(本Apple M3 Pro配备12物理核/12线程) *本分析基于搭载Apple M3 Pro(12核、36 GB内存)的Mac笔记本开发与测试。* 软件依赖: - R版本:4.4.0及以上(已在4.4.0版本测试) - RStudio(可选) 性能说明 脚本1-07采用跨物种种并行处理。在Apple M3 Pro(12核、36 GB内存)设备上: - 脚本01-07(完整流程需受限数据):运行时间>5天 - 脚本08-13(仅使用本仓库提供的数据):运行时间为1~3小时 使用的R包 数据处理与转换: - dplyr:用于数据框的操作、筛选、连接与汇总 - data.table:用于高性能数据处理与快速文件读写 - tidyr:用于数据重塑与清洗 - tibble:用于统一数据框结构与输出格式 - stringr:用于字符串操作与模式匹配 - readr:用于快速读写CSV文件 - readxl:用于导入Excel文件(.xlsx、.xls) - writexl:用于将数据框导出为Excel格式 - scales:用于数据缩放、转换与轴格式设置 空间分析与地理信息系统: - terra:用于栅格与矢量空间数据的处理、投影、聚合与提取 - sf:用于矢量空间数据处理与地理信息系统操作 - mapview:用于交互式空间数据可视化 - raster:用于遗留栅格操作(旧代码段) 统计建模: - glmmTMB:用于狩猎影响预测中的广义线性混合模型 - mgcv:用于密度预测中的广义加性模型(GAM) 并行处理: - foreach:用于构建并行循环 - doParallel:作为多CPU核心并行执行的后端 - parallel:用于核心并行化函数(检测核心数、创建集群) 数据可视化: - ggplot2:用于生成符合出版标准的图形与自定义绘图 - ggpubr:用于排列多幅图表与添加统计注释 - ggtext:用于ggplot2中的增强文本格式化(支持Markdown、HTML) API与网络服务: - rredlist:用于对接IUCN红色名录API - iucnredlist:用于物种评估的替代IUCN API客户端 工具与性能优化: - matrixStats:用于快速的矩阵行/列操作 - openxlsx:用于读写带格式的Excel文件 - tictoc:用于执行时间测量与性能分析 - tools:用于文件路径操作 安装R包的代码(在R中运行): install.packages(c("dplyr", "data.table", "tidyr", "tibble", "stringr", "readr", "readxl", "writexl", "scales", "terra", "sf", "raster", "glmmTMB", "mgcv", "foreach", "doParallel", "parallel", "ggplot2", "ggpubr", "ggtext", "rredlist", "iucnredlist", "matrixStats", "openxlsx", "tictoc", "tools"))



