Title: | Multi-Species Trait-Based Coexistence Model in Discrete time |
---|---|
Description: | A modified Beverton-Holt model used in the Denelle, Grenié et al. manuscript that expresses environmental filtering, limiting similarity and hierarchical competition explicitely in function of species traits. This package provides all the code necessary to rerun the analyses of the manuscript. |
Authors: | Matthias Grenié [aut, cre] , Pierre Denelle [aut] , Caroline Tucker [aut] , François Munoz [aut] , Cyrille Violle [aut] |
Maintainer: | Matthias Grenié <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.0.1 |
Built: | 2025-01-14 05:39:08 UTC |
Source: | https://github.com/Rekyt/fdcoexist |
From a competition matrix (for the moment the distance between species traits) and a vector of abundances by species, return the alpha term in the Beverton-Holt equation. The order of species between the two should be the same as no checks are done. Typically the competition matrix is an euclidean trait distance matrix between species. The closer the species are the higher the combination. The term is computed as follow:
alphaterm(distance, Nts, A, B, di_thresh)
alphaterm(distance, Nts, A, B, di_thresh)
distance |
dissimilarity matrix between species |
Nts |
vector of abundances of species at time t |
A |
scalar for the inter-specific competition |
B |
scalar for the intra-specific competition |
di_thresh |
dissimilary threshold above which species are considered maximally dissimilar |
, where alpha_i is the competition term of species i; Ntjx the abundance of species j, at time t, in patch x and delta_ij the functional distance between species i and species j.
To simulate growth easily, use the Beverton-Holt equation. Which is:
bevHoltFct(R, N, alpha)
bevHoltFct(R, N, alpha)
R |
a numeric vector of species growth rates |
N |
a numeric vector of species population sizes |
alpha |
the competition coefficient see |
where t is time, i is the species of interest and x the patch it occupies.
This is an internal help function to check the trait weights data.frame
(used in multigen()
). The structure of the given trait weights is fixed:
one column should be named trait`` with the names of the traits in it. The two other columns
growth_weightand
compet_weightcontains respectively the relative weight of the trait in growth and competition. The function also additionnally check that the traits in the
traitcolumn are in the
traits' data.frame.
check_trait_weights(trait_weights, traits)
check_trait_weights(trait_weights, traits)
trait_weights |
data.frame with at least three columns equal to |
traits |
a species-traits data.frame with species as rownames and
traits as numeric columns with names matching
|
nothing if data.frame passes the checks, stops early otherwise.
# Working trait weights data.frame traits = data.frame(trait1 = 1, trait2 = 2, trait3 = 3) weight_1 = data.frame( trait = c("trait1", "trait2", "trait3"), growth_weight = c(0.5, 0.5, 0), compet_weight = c(0, 0.5, 0.5), hierarchy_weight = c(0, 0, 0)) # Silent function check_trait_weights(weight_1, traits) ## Not run: # Not valid trait weights data.frame not_valid = data.frame(trait = c("trait1", "trait2", "trait3"), growth_weight = c(0.5, 0.8, 0), compet_weight = c(0, 0.5, 0.9)) # Stop and error check_trait_weights(not_valid, traits) ## End(Not run)
# Working trait weights data.frame traits = data.frame(trait1 = 1, trait2 = 2, trait3 = 3) weight_1 = data.frame( trait = c("trait1", "trait2", "trait3"), growth_weight = c(0.5, 0.5, 0), compet_weight = c(0, 0.5, 0.5), hierarchy_weight = c(0, 0, 0)) # Silent function check_trait_weights(weight_1, traits) ## Not run: # Not valid trait weights data.frame not_valid = data.frame(trait = c("trait1", "trait2", "trait3"), growth_weight = c(0.5, 0.8, 0), compet_weight = c(0, 0.5, 0.9)) # Stop and error check_trait_weights(not_valid, traits) ## End(Not run)
This function compute trait distance between species using a trait matrix and a trait weights data.frame. For all the traits with competition weights not equal to zero, it computes a weighted 'composite trait' that is then used to compute euclidean trait distance between species. Trait distance is first exponentiated then standardized between 0 and 1.
compute_compet_distance(trait_weights, traits, exponent = 1)
compute_compet_distance(trait_weights, traits, exponent = 1)
trait_weights |
data.frame with at least three columns equal to |
traits |
a species-traits data.frame with species as rownames and
traits as numeric columns with names matching
|
exponent |
[ |
an euclidean distance matrix (of type matrix)
Outputs a matrix of additional growth per patch per species given by hierarchical competition. The values are considered
compute_hierarchical_compet( composition_given_time_step, trait_values, trait_weights, H, exponent = 1 )
compute_hierarchical_compet( composition_given_time_step, trait_values, trait_weights, H, exponent = 1 )
composition_given_time_step |
composition matrix at a given time step (a site-species matrix with sites in rows) |
trait_values |
a trait matrix |
trait_weights |
data.frame with at least three columns equal to |
H |
the hierarchical competition scalar |
exponent |
exponent to use for hierarchical compet. distances |
Only in the special case of 3 traits with 1 always driving growth and another one only driving competition
create_trait_weights(R, A, H, n_traits = 4)
create_trait_weights(R, A, H, n_traits = 4)
R |
an integer value giving the contribution of trait in growth |
A |
an integer value giving the contribution of trait in limiting similarity |
H |
an integer value giving the contribution of trait in hierarchical competition |
n_traits |
number of traits considered in table |
create_trait_weights(50, 50, 0)
create_trait_weights(50, 50, 0)
Using traits that affect growth rate and specified environments, this function returns a numeric value of expected growth rates given the traits and the environmental value. The total growth rate is then the average of the growth rates computed with each trait.
env_curve(trait_values, env_value, trait_weights, k = 2, width = 0.5)
env_curve(trait_values, env_value, trait_weights, k = 2, width = 0.5)
trait_values |
a numeric vector of species trait values |
env_value |
a single numeric value giving the environmental variable |
trait_weights |
data.frame with at least three columns equal to |
k |
a scalar giving the maximum growth rate in optimal environment |
width |
a numeric for niche breadth, constant in gaussian function |
For the moment the environmental filter follows a Gaussian distribution:
, where t_i is trait of species i, env_x the environmental value in patch x, k a scalar giving the maximal growth rate and width the environmental breadth of species.
Extract different growth rates from fdcoexist simulation
extract_growth_rates(simul, chosen_time = NULL)
extract_growth_rates(simul, chosen_time = NULL)
simul |
Simulation object from |
chosen_time |
numeric timestep at which to extract growth rates |
Extract species mismatches
extract_mismatches(x, z)
extract_mismatches(x, z)
x |
Simulation object from |
z |
Number of the species |
This function generates a matrix of traits based on the given number of patches, species, the number of "additional" traits with a given correlation coefficient. The first trait is always uniform between 1 and the number of patches provided. Then the other traits are generated correlated to this first one. In the end all the traits are scaled between 1 and the number of patches.
generate_cor_traits( number_patches, number_species, number_other = 9, cor_coef = 0.7, min_value = 1 )
generate_cor_traits( number_patches, number_species, number_other = 9, cor_coef = 0.7, min_value = 1 )
number_patches |
a numeric value giving the total number of patches |
number_species |
a numeric value giving the total number of species to simulate (number of rows in the trait tables) |
number_other |
a numeric value giving the number of additional traits to generate in addition to the trait correlated to the number of patches |
cor_coef |
a numeric value giving the correlation coefficient between the first trait and the other ones |
min_value |
a minimum trait value |
a matrix of traits with species in rows and traits in columns
traits <- generate_cor_traits(25, 100, 3, 0.3)
traits <- generate_cor_traits(25, 100, 3, 0.3)
Generate random traits Compared to generate_cor_traits() introduce a little of variability in first trait as instead of being directly determined by the species number it adds little white noise to it and scale it to a minimum of 0 if negative and maximum of 25 if maximum value is over 25.
generate_cor_traits_rand( number_patches, number_species, number_other = 9, cor_coef = 0.7, min_value = 1 )
generate_cor_traits_rand( number_patches, number_species, number_other = 9, cor_coef = 0.7, min_value = 1 )
number_patches |
Number of patches to consider |
number_species |
Number of species to which generate the traits |
number_other |
(default = 9) Number of other traits to generate |
cor_coef |
(default = 0.7) Correlation coefficient between first and other traits |
min_value |
absolute minimum trait value |
Plot mismatch per species between environmental optimum and max. abundance
mismatch(simul, n_patches = 25, sp, time = 50, plot = TRUE)
mismatch(simul, n_patches = 25, sp, time = 50, plot = TRUE)
simul |
results array of a given simulation (a |
n_patches |
an integer indicating the patch number |
sp |
integer for the number of species to consider |
time |
an integer indicating the number of time steps |
plot |
a boolean determining whether to plot or not the mismatch |
Using specified parameters this function run the simulation
multigen( traits, trait_weights, env, time, species, patches, composition, A = A, B = B, d, k, width, H, h_fun = "+", di_thresh = 24, lim_sim_exponent = 2, hierar_exponent = 0.5 )
multigen( traits, trait_weights, env, time, species, patches, composition, A = A, B = B, d, k, width, H, h_fun = "+", di_thresh = 24, lim_sim_exponent = 2, hierar_exponent = 0.5 )
traits |
a species-traits data.frame with species as rownames and
traits as numeric columns with names matching
|
trait_weights |
data.frame with at least three columns equal to |
env |
a vector of environmental values |
time |
an integer giving the total number of generations |
species |
an integer giving the total number of species to simulate |
patches |
an integer giving the total number of patches to simulate |
composition |
the actual array containing species abundances per site over time, giving the initial populations of each species |
A |
the scalar of inter-specific competition coefficient
(see |
B |
the scalar for intra-specific competition coefficient by default B = A |
d |
a numeric value between 0 and 1 giving the percentage of dispersal occurring across all patches |
k |
a scalar giving the maximum growth rate in optimal environment |
width |
a numeric giving niche breadth of all species |
H |
a numeric for hierarchical competition such as H/k <= 1 |
h_fun |
a function that describes how hierarchical is combined to
environmental-based growth (default: |
di_thresh |
dissimilary threshold above which species are considered maximally dissimilar |
lim_sim_exponent |
exponent to use for limiting similarity distances |
hierar_exponent |
exponent to use for hierarchical compet. distances |
Plot the dynamics of species in a single patch over time. Automatically assigns one color per species.
plot_patch(results, patch, time, equilibrium = FALSE)
plot_patch(results, patch, time, equilibrium = FALSE)
results |
results array of a given simulation (a |
patch |
an integer indicating the patch number |
time |
an integer indicating the maximum timestep to look at |
equilibrium |
a boolean, if TRUE, displays a vertical line when equilibrium is reached |
Automatically assigns one color per species.
plot_rh(simul, n_patches, time)
plot_rh(simul, n_patches, time)
simul |
results array of a given simulation (a |
n_patches |
an integer indicating the patch number |
time |
an integer indicating the number of time steps |
Automatically assigns one color per species.
r_env(simul, n_patches, sp, plot = TRUE)
r_env(simul, n_patches, sp, plot = TRUE)
simul |
results array of a given simulation (a |
n_patches |
an integer indicating the patch number |
sp |
integer for the number of species to consider |
plot |
a boolean determining whether to plot or not the response curves |
Extract Species by Patch Growth Rates and Optimal Patches
r_env_CT(simul, n_patches, sp1, time)
r_env_CT(simul, n_patches, sp1, time)
simul |
a simulation output from |
n_patches |
the number of patches in the simulation |
sp1 |
the number of species |
time |
the time slice at which e |
Outputs 4 data.frame of species by patch mismatches each with four columns:
env_all
-> Environmental Growth only
r_all
-> Environmental + Hierarchical competition Growth only
r_comp
-> Abundance
r_envab
-> Abundance based on environmental filtering only
The 4 data.frame are:
env
-> Patch
sp
-> Species
r_env
-> Observed statistic (environmental growth, total growth,
abundance, environmental filtering abundance)
max_r_env
-> Patch of maximum observed statistic
dist - min(dist) / (max(dist) - min(dist))
scale_distance(dist_matrix)
scale_distance(dist_matrix)
dist_matrix |
a matrix or a dist object |
Automatically assigns one color per species.
sp_ab_gr(simul, n_patches, sp, time)
sp_ab_gr(simul, n_patches, sp, time)
simul |
results array of a given simulation (a |
n_patches |
an integer indicating the patch number |
sp |
integer for the number of species to consider |
time |
integer determining the time step of interest |
Compute weighted kurtosis using Weighted.Desc.Stat::w.kurtosis
but add an
option to remove NA
values
wtd_kurtosis(x, w, na.rm = TRUE)
wtd_kurtosis(x, w, na.rm = TRUE)
x |
values whose weighted mean is to be computed |
w |
weights of the same length as |
na.rm |
a logical values indicating whether |
Weighted mean that allows NA in values and weights
wtd_mean(x, w, na.rm = TRUE)
wtd_mean(x, w, na.rm = TRUE)
x |
values whose weighted mean is to be computed |
w |
weights of the same length as |
na.rm |
a logical values indicating whether |
Compute weighted Skewness using Weighted.Desc.Stat::w.skewness
but add an
option to remove NA
values
wtd_skewness(x, w, na.rm = TRUE)
wtd_skewness(x, w, na.rm = TRUE)
x |
values whose weighted mean is to be computed |
w |
weights of the same length as |
na.rm |
a logical values indicating whether |
Weighted Variance
wtd_var(x, w, na.rm = TRUE)
wtd_var(x, w, na.rm = TRUE)
x |
values whose weighted mean is to be computed |
w |
weights of the same length as |
na.rm |
a logical values indicating whether |