Supplement 1. Simulation code. Encompasses all functions and libraries required by individual based simulation, the implementation of the model fitting, as well as the goodness-of-fit and prediction experiments with graphical diagnostics.
收藏WILEY2016-08-10 更新2026-04-17 收录
下载链接:
https://wiley.figshare.com/articles/dataset/Supplement_1_Simulation_code_Encompasses_all_functions_and_libraries_required_by_individual_based_simulation_the_implementation_of_the_model_fitting_as_well_as_the_goodness-of-fit_and_prediction_experiments_with_graphical_diagnostics_/3568977/1
下载链接
链接失效反馈官方服务:
资源简介:
File List fitness.r (MD5: 970fccf39d71a26e27dffc1d6446a9c7)Description The code is presented in nine sections described below. <b>Section 0: Functions and libraries</b> This section loads all necessary R-libraries and introduces the four custom functions. Functions Espace.numer and Espace.approx are used to generate density plots of the availability of different habitats in a two-dimensional E-space. Espace.numer plots the actual availability (effectively a 2D histogram of the frequencies of different habitats). Espace.approx plots the approximate availabilities generated by the Gaussian decomposition of the library mclust. These two plots are used in the bottom row of Fig. 3 of the paper. Function environ is used to create environmental layers (e.g., distribution of food) across space. Function resCi, generates percentile confidence intervals from a distribution of residuals. <b>Section 1: Population simulation</b> This section contains the simulation of population redistribution and growth (fecundity and mortality) in response to the combined fitness afforded by the two environmental variables. At the very beginning of this section, the environmental layers are generated and the Gaussian decomposition of E-space is calculated (this step is described as Stage 1 in section 10 of the main paper). The code in this section also records the data and visualizes the outcome of each scenario graphically (example is shown in Fig. 3 in the paper). The simulation is outlined in section 11 of the paper. <b>Section 2: Generation of fitting data frames</b> The code in this section constructs the data frames used for fitting the habitat selection functions, as well as the population data to be used for the temporal dynamics model fit. Depending on the values chosen for the constants scmaxi, stp, stpc, these data can be thinned by scenario, years or spatial cells. This thinning approach was used to create the data-impoverishment experiments described in Appendix C. <b>Section 3: Spatial model fitting</b> Here, the spatial date-frame generated in Section 2 is used to fit Generalised Functional Responses to statistically describe the distribution of the animals in response to environmental covariates. This step is described as Stage 2 in section 10 of the main paper. The values for the Akaike Information Criterion of the GFR and a simple Generalised Linear Model are also compared. <b>Section 4: Some exploratory plots</b> Three composite plots can be generated here. The first compares a simple GLM Habitat Selection Function with the GFR HSF (both models are generated in the previous section). The second plot looks at a sample of spatial snapshots of usage from different scenarios and years in the simulated data, and compares those with the corresponding spatial fits generated by the GFR. The third plot looks at the collection of population trajectories from all scenarios. The red trajectories belong to the model fitting data set. The grey trajectories belong to the model validation data set (this is how Fig. 4 in the main paper is generated). <b>Section 5: Calculation of constructed covariates for spatial population model</b> This is the heart of the method. The implementation is described as stage 3 in section 10 of the main paper. Here, the values of the <i>φ</i> expressions in Eq. 31 of the main paper are calculated. <b>Section 6: Fitting the population models</b> The fitting part of the data is used to estimate the beta parameters of Eq. 31 in the main paper. This is the spatially explicit version of the population model. A mean field version of the model is also fitted and the AICs of the two models are compared. <b>Section 7: Goodness-of-fit plots</b> This section compares the quality of fit of the spatial and the mean field models to the data used for fitting both models. The comparison is described as simulation experiment 1 in section 12 of the main paper. This output is used in Figs 5a, 5b, 6a, 6c. <b>Section 8: Prediction plots</b> This section compares the quality of predictions from the spatial and the mean field models using the new scenarios from the validation data. The comparison is described as simulation experiments 2 and 3 in section 12 of the main paper. This output is used in Figs 5c, 5d, 5e, 5f, 6c, 6d, 6e, 6f.
文件列表:fitness.r(MD5:970fccf39d71a26e27dffc1d6446a9c7)
描述:本代码分为如下9个章节,详述如下。
<b>第0章:函数与依赖库</b> 本章加载所有必要的R语言库,并引入4个自定义函数。函数Espace.numer与Espace.approx用于生成二维E空间中不同生境可获得性的密度图。其中Espace.numer绘制实际可获得性(本质为不同生境频率的二维直方图);Espace.approx通过mclust库进行高斯分解,生成并绘制近似可获得性。这两幅绘图将用于论文图3的底部行。函数environ用于创建跨空间的环境图层(例如食物分布)。函数resCi用于从残差分布中生成百分位数置信区间。
<b>第1章:种群模拟</b> 本章实现种群再分布与增长(繁殖与死亡)的模拟,模拟基于两个环境变量共同作用下的综合适合度。本章开篇首先生成环境图层并计算E空间的高斯分解(该步骤在主论文第10章中记为阶段1)。本章代码同时会记录数据,并以图形方式可视化每个模拟场景的结果(示例见论文图3)。该模拟流程在主论文第11章中有概述。
<b>第2章:拟合数据框的生成</b> 本章代码用于构建用于拟合生境选择函数的数据框,以及用于时间动态模型拟合的种群数据。根据常量scmaxi、stp、stpc的取值,这些数据可按场景、年份或空间单元进行稀疏化。该稀疏化方法被用于附录C中描述的数据匮乏实验。
<b>第3章:空间模型拟合</b> 本章使用第2章生成的空间数据框,拟合广义功能响应(Generalised Functional Responses, GFR),以统计描述动物对环境协变量的分布响应。该步骤在主论文第10章中记为阶段2。本章同时会比较广义功能响应模型与简单广义线性模型(Generalised Linear Model, GLM)的赤池信息准则值。
<b>第4章:探索性绘图</b> 本章可生成3幅复合绘图:第一幅对比简单广义线性模型生境选择函数与广义功能响应生境选择函数(两类模型均在上一章生成);第二幅绘制模拟数据中不同场景与年份的种群空间使用快照,并将其与广义功能响应生成的对应空间拟合结果进行对比;第三幅绘制所有场景下的种群轨迹集合,其中红色轨迹对应模型拟合数据集,灰色轨迹对应模型验证数据集(主论文图4即通过该输出生成)。
<b>第5章:空间种群模型构造协变量的计算</b> 本章为该方法的核心部分,其实现流程在主论文第10章中记为阶段3。本章将计算主论文式(31)中<i>φ</i>表达式的取值。
<b>第6章:种群模型拟合</b> 本章使用拟合数据集估计主论文式(31)中的beta参数,该模型为空间显式版本的种群模型。同时本章还会拟合该模型的平均场版本,并比较两类模型的赤池信息准则值。
<b>第7章:拟合优度绘图</b> 本章对比空间模型与平均场模型对两类模型拟合所用数据的拟合质量,该对比在主论文第12章中记为模拟实验1,其输出结果将用于图5a、5b、6a、6c。
<b>第8章:预测绘图</b> 本章使用验证数据中的新场景,对比空间模型与平均场模型的预测质量。该对比在主论文第12章中记为模拟实验2与3,其输出结果将用于图5c、5d、5e、5f、6c、6d、6e、6f。
提供机构:
Hawthorne L. Beyer
创建时间:
2016-08-10



