... | ... | @@ -34,9 +34,44 @@ create_ancestor_species <- function(landscape, config) { |
|
|
}
|
|
|
~~~
|
|
|
|
|
|
### 1.1.2
|
|
|
|
|
|
Global ancestor (Evolutionary Speed Hypothesis, Skeels et al 2021)
|
|
|
|
|
|
This function intialises a single species that occupies all global grid cells.
|
|
|
Requires 4 traits: dispersal, temp, prec, body_size
|
|
|
|
|
|
~~~R
|
|
|
|
|
|
create_ancestor_species <- function(landscape, config) {
|
|
|
#browser()
|
|
|
# set up a raster of global temperatures
|
|
|
t_world <- raster::rasterFromXYZ(cbind(landscape$coordinates,landscape$environment[, 1, drop = F]))
|
|
|
t_world <- extend(t_world, landscape$extent)
|
|
|
|
|
|
# Will the simulation sample the ancestor from a partcular continent or randomly from anywhere?
|
|
|
start_cells <- as.character(Which(t_world, cells=T))
|
|
|
|
|
|
# now fill the list of new species
|
|
|
all_species <- list()
|
|
|
|
|
|
new_species <- create_species(as.character(start_cells), config)
|
|
|
new_species$traits[ , "dispersal"] <- 1
|
|
|
new_species$traits[ , "temp"] <- landscape$environment[start_cells, "temp"]
|
|
|
new_species$traits[ , "prec"] <- landscape$environment[start_cells, "prec"]
|
|
|
new_species$traits[ , "body_size"] <- 0.2
|
|
|
|
|
|
all_species <- append(all_species, list(new_species))
|
|
|
|
|
|
|
|
|
return(all_species)
|
|
|
|
|
|
}
|
|
|
~~~
|
|
|
|
|
|
# 1.2 Dispersal
|
|
|
|
|
|
### 1.2.1 (Weibull dispersal kernel (Pantropical diversity, Hagen and Skeels et al 2021)
|
|
|
### 1.2.1 Weibull dispersal kernel (Pantropical diversity, Hagen and Skeels et al 2021)
|
|
|
|
|
|
This function draws the dispersal kernel from a Weibull distriution with shape and scale parameters.
|
|
|
Specify paramters: params$WeibullShape, params$WeibullScale
|
... | ... | @@ -50,7 +85,7 @@ get_dispersal_values <- function(n, species, landscape, config) { |
|
|
|
|
|
# 1.3 Evolution
|
|
|
|
|
|
### 1.3.1 Pantropical diversity (Brownian Motion (Hagen and Skeels et al 2021)
|
|
|
### 1.3.1 Species-level Brownian Motion (Pantropical diversity, Hagen and Skeels et al 2021)
|
|
|
|
|
|
This function evolves a single temperature-niche trait under a random walk (Brownian Motion) model.
|
|
|
Requires 1 trait: temp
|
... | ... | @@ -70,9 +105,47 @@ apply_evolution <- function(species, cluster_indices, landscape, config) { |
|
|
return(traits)
|
|
|
|
|
|
}
|
|
|
|
|
|
~~~
|
|
|
|
|
|
### 1.3.2 Cluster-level OU + BM (Evolutionary Speed Hypothesis, Skeels et al 2021)
|
|
|
|
|
|
This function evolves a temperature-niche trait under a Ornstein Uhlenbeck model of trait evolution and evolves a body size trait under a Brownian Motion model. The OU model has a random walk element as in the Brownian motion model and also a parameter (psi) that draws the value towards an optimal value (based on the mean temperature value across the clusters geographic range). When psi=0 OU = BM. The OU and BM models each have an independant rate parameter (sigma squared). This function evolves each geographic cluster seperately (instead of each species speerately or each grid cell seperately).
|
|
|
|
|
|
Requires 2 traits: temp and body_size
|
|
|
Specify paramters: params$sigma_squared_bs, params$sigma_squared_t, params$psi
|
|
|
|
|
|
|
|
|
sigma_squared_bs <- params$sigma_squared_bs
|
|
|
sigma_squared_t <- params$sigma_squared_t
|
|
|
psi <- params$psi
|
|
|
|
|
|
apply_evolution <- function(species, cluster_indices, landscape, config) {
|
|
|
|
|
|
# cell names
|
|
|
traits <- species[["traits"]]
|
|
|
cells <- rownames( traits )
|
|
|
|
|
|
# evolve traits for each cluster
|
|
|
for(cluster_index in unique(cluster_indices)){
|
|
|
cells_cluster <- cells[which(cluster_indices == cluster_index)]
|
|
|
t_theta_cluster <- mean(landscape$environment[cells_cluster,"temp"], na.rm=T)
|
|
|
# evolve temperature
|
|
|
traits[cells_cluster, "temp"] <- traits[cells_cluster, "temp"] + ( psi * (t_theta_cluster - traits[cells_cluster, "temp"]) ) + rnorm(1, mean = 0, sd = sigma_squared_t)
|
|
|
# evolve body size
|
|
|
traits[cells_cluster, "body_size"] <- traits[cells_cluster, "body_size"] + rnorm(1, mean = 0, sd = sigma_squared_bs)
|
|
|
}
|
|
|
|
|
|
# set bounds between 0 and 1 so the species can;t evolve a niche beyond that present in the data (all temp is scaled between 0 and 1)
|
|
|
if(any(traits[, "temp"] > 1)){traits[which(traits[,"temp"]>1), "temp"] <- 1}
|
|
|
if(any(traits[, "temp"] < 0)){traits[which(traits[,"temp"]<0), "temp"] <- 0}
|
|
|
if(any(traits[, "body_size"] > 1)){traits[which(traits[,"body_size"]>1), "body_size"] <- 1}
|
|
|
if(any(traits[, "body_size"] < 0)){traits[which(traits[,"body_size"]< 0), "body_size"] <- 0}
|
|
|
|
|
|
return(traits)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
# 1.4 Speciation
|
|
|
|
|
|
### 1.4.1 Linear divergence (Pantropical diversity, Hagen and Skeels et al 2021)
|
... | ... | |