simulator <- SimulatorReference$new()
# Example transformation: a random population is chosen for a severe disturbance event
# (only life cycle stage 3 individuals survive)
disturbance_function <- function(params) {
params$simulator$attached$params <- params # attach to reference object
random_population <- sample(params$occupied_indices, 1)
new_stage_abundance <- params$stage_abundance
new_stage_abundance[1:2, random_population] <- 0
return(new_stage_abundance)
}
transformation_function <- population_transformation(
replicates = 4, time_steps = 10, years_per_step = 1,
populations = 7, demographic_stochasticity = TRUE,
density_stages = c(0, 1, 1), transformation = disturbance_function,
simulator
)
carrying_capacity <- rep(10, 7)
carrying_capacity <- rep(10, 7)
stage_abundance <- matrix(c(
7, 13, 0, 26, 0, 39, 47,
2, 0, 6, 8, 0, 12, 13,
0, 3, 4, 6, 0, 9, 10
), nrow = 3, ncol = 7, byrow = TRUE)
occupied_indices <- (1:7)[-5]
transformation_function(r = 2, tm = 6, carrying_capacity, stage_abundance,
occupied_indices)
Run the code above in your browser using DataLab