Closed geryan closed 5 years ago
Related error:
Error in if (any(pop_new[!missing] > 0)) { :
missing value where TRUE/FALSE needed
This error appears instead when a low value for fecundity is used. E.g.:
egk_mat_lf <- matrix(c(0.00,0.00,0.10,
0.50,0.00,0.00,
0.00,0.85,0.85),
nrow = 3,
ncol = 3,
byrow = TRUE)
egk_pop_dynamics_fd_lf <- population_dynamics(change = growth(transition_matrix = egk_mat_lf),
dispersal = fast_dispersal(
dispersal_kernel = exponential_dispersal_kernel(
distance_decay = 1000)),
modification = NULL,
density_dependence = NULL)
egk_landscape <- landscape(population = egk_pop,
suitability = NULL,
carrying_capacity = NULL)
egk_results <- simulation(landscape = egk_landscape,
population_dynamics = egk_pop_dynamics_fd_lf,
habitat_dynamics = NULL,
timesteps = 100,
replicates = 1,
verbose = FALSE)
Both of these errors are coming from the round_pop() function because rmultinom() can only handle integers up to a certain size.
Possible workaround if populations size is too large:
chunksize <- 1000000
chunks <- population/ chunksize
rowSums(rmultinom(chunks, population, probs)))
https://stackoverflow.com/a/43718966
Would need something to not land on decimals of course.
We added a wrapper function that deals with large integers
Error appears over longer runs with demographic stochasticity and fast dispersal