Skip to content
Snippets Groups Projects
run_analysis.R 2.75 KiB
Newer Older
thierrychambert's avatar
thierrychambert committed
rm(list = ls(all.names = TRUE))
graphics.off()

thierrychambert's avatar
thierrychambert committed
## Libraries
library(eolpop)

## Inputs
thierrychambert's avatar
thierrychambert committed

fatalities_mean = c(0, 5)
fatalities_se = c(0,0.05)
thierrychambert's avatar
thierrychambert committed

pop_size_mean = 200
thierrychambert's avatar
thierrychambert committed

pop_growth_mean = 0.95
pop_growth_se = 0.03
thierrychambert's avatar
thierrychambert committed

survivals <- c(0.5, 0.7, 0.8, 0.95)
fecundities <- c(0, 0, 0.05, 0.55)
thierrychambert's avatar
thierrychambert committed

model_demo = NULL # M2_noDD_WithDemoStoch #M1_noDD_noDemoStoch #M4_WithDD_WithDemoStoch #M3_WithDD_noDemoStoch #
coeff_var_environ = 0.10
thierrychambert's avatar
thierrychambert committed
fatal_constant = "h"
thierrychambert's avatar
thierrychambert committed

onset_time = onset_year - min(onset_year) + 1
thierrychambert's avatar
thierrychambert committed

# Pop size total
sum(pop_vector(pop_size = pop_size_mean, pop_size_type = pop_size_type, s = survivals, f = fecundities))


# Define K
carrying_capacity = 500
theta = 1
K = pop_vector(pop_size = carrying_capacity, pop_size_type = pop_size_type, s = survivals, f = fecundities) %>% sum
K

# Define theoretical rMAX for the species
rMAX_species <- rMAX_spp(surv = tail(survivals,1), afr = min(which(fecundities != 0)))
rMAX_species

##  Avoid unrealistic scenarios
pop_growth_mean <- min(1 + rMAX_species, pop_growth_mean)
pop_growth_mean



thierrychambert's avatar
thierrychambert committed
##--------------------------------------------
thierrychambert's avatar
thierrychambert committed
##--------------------------------------------
# Calibrate vital rates to match the the desired lambda
inits <- init_calib(s = survivals, f = fecundities, lam0 = pop_growth_mean)
vr_calibrated <- calibrate_params(inits = inits, f = fecundities, s = survivals, lam0 = pop_growth_mean)
s_calibrated <- head(vr_calibrated, length(survivals))
f_calibrated <- tail(vr_calibrated, length(fecundities))
thierrychambert's avatar
thierrychambert committed

build_Leslie(s = s_calibrated, f = f_calibrated) %>% lambda





thierrychambert's avatar
thierrychambert committed
##==============================================================================
##                         Analyses (simulations)                             ==
##==============================================================================
run0 <- run_simul(nsim, cumuated_impacts,
                  fatalities_mean, fatalities_se, onset_time,
                  pop_size_mean, pop_size_se, pop_size_type,
thierrychambert's avatar
thierrychambert committed
                  pop_growth_mean, pop_growth_se,
                  survivals = s_calibrated, fecundities = f_calibrated,
                  carrying_capacity = carrying_capacity, theta = theta,
                  rMAX_species = rMAX_species,
thierrychambert's avatar
thierrychambert committed
                  model_demo, time_horzion, coeff_var_environ, fatal_constant)


plot_traj(N, xlab = "Annee", ylab = "Taille de population (totale)")
thierrychambert's avatar
thierrychambert committed

# plot_impact(N, onset_year = onset_year , xlab = "Annee", ylab = "Impact relatif")
#plot_impact(N = N, xlab = "year", ylab = "pop size")
#source("draws_histog.R")
#draws_histog(draws = run0$lambdas, mu = pop_growth_mean, se = pop_growth_se)