.simulatedPopulation = function(C = numeric(), sp = "anchoveta", ages = NULL, n = 200, sd=0.1,
prob = TRUE){
info = getSpeciesInfo(sp)
k = info$k
Linf = info$Linf
t0 = info$t0
longevity = info$longevity
nRec = info$nRec
dL = info$bin
if(length(C) == 0 & is.null(ages))
stop("Al menos 'ages' o 'C' deben tener un valor definido.")
if(!is.null(ages)){
C <- length(ages)
}else{
age = runif(1, min=0, longevity)
ages = seq(from = age, by = 1/nRec, len = C) %% longevity
}
ages <- sort(unique(ages))
marcas = .createMarks(info)
#N = diff(sort(c(0, runif(length(ages)-1), 1)))
N = rtruncnorm(n = length(ages), a = 0, b = 1, mean = 0.5, sd = 0.25)
L = Linf*(1-exp(-k*(ages-t0)))
S = sd*L # to improve
ind = sample(length(L), size = n*length(L), prob=N, replace=TRUE)
x = rnorm(n*length(L), mean=L[ind], sd=S[ind])
bins = c(union(marcas - 0.5*dL, marcas + 0.5*dL), Inf)
Nil = table(cut(x, breaks = bins, useNA = FALSE, labels = c(marcas, Inf)))
Pil = Nil/sum(Nil)
output = if(isTRUE(prob)) Pil else Nil
return(output)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.