Commit a3ec46e0 authored by patrick.lambert's avatar patrick.lambert
Browse files

increment = 0 when L > Ling to avoid production of NA

parent 12376092
......@@ -12,7 +12,7 @@ temperatureEffect = function(tempWater, Tmin, Topt, Tmax){
thermalRange = function(pct = 0.8, Tmin, Topt, Tmax){
lower = uniroot(function(x) temperatureEffect(x, Tmin, Topt, Tmax) - pct,
interval = c(Tmin, Topt))$root
interval = c(Tmin, Topt))$root
upper = uniroot(function(x) temperatureEffect(x, Tmin, Topt, Tmax) - pct,
interval = c(Topt, Tmax))$root
return(c(lower = lower,upper = upper))
......@@ -56,13 +56,20 @@ vonBertalanffyIncrement = function(nStep, L0, Linf, K, timeStepDuration, sigma,
vonBertalanffyWithNextIncrement = function(L, L0, Linf, K, timeStepDuration, sigma, tempEffect ){
if (sigma == 0) {
mu = log((Linf - L) * (1 - exp(-K * timeStepDuration)))
increment = exp(mu)
if (L <= Linf) {
mu = log((Linf - L) * (1 - exp(-K * timeStepDuration)))
increment = exp(mu)
} else
increment = 0
}
else {
mu = log((Linf - L) * (1 - exp(-K * timeStepDuration))) - (sigma * sigma) / 2
increment = exp(rnorm(1, mu, sigma))
}
if (L <= Linf) {
mu = log((Linf - L) * (1 - exp(-K * timeStepDuration))) - (sigma * sigma) / 2
increment = exp(rnorm(1, mu, sigma))
}
} else
increment = 0
L = L + increment * tempEffect
return(L)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment