Commit 906e0d48 authored by patrick.lambert's avatar patrick.lambert
Browse files

calibrate grwoth curve by gender

parent 002ef709
objFUN = function(par, ages, parGrow){
meanCurve = vonBertalanffyGrowth(ages, parGrow$L0, parGrow$Linf, parGrow$K)
femaleCurve = vonBertalanffyGrowth(ages, parGrow$L0, parGrow$Linf, par['Kfemale'])
maleCurve = vonBertalanffyGrowth(ages, parGrow$L0, parGrow$Linf, par['Kmale'])
SCE1 = sum(((maleCurve + femaleCurve)/2 - meanCurve)^2) / length(ages)
femaleAgeAtMaturity = vonBertalanffyInverse(parGrow$LatMaturity, parGrow$L0, parGrow$Linf, par['Kfemale'])
maleAgeAtMaturity = vonBertalanffyInverse(parGrow$LatMaturity, parGrow$L0, parGrow$Linf, par['Kmale'])
SCE2 = ((femaleAgeAtMaturity - maleAgeAtMaturity) - parGrow$diffMeanAgeAtMaturity)^2
return (unname(SCE1 + SCE2))
}
parGrow = data.frame(Linf = 45.4,
K = 0.49,
L0 = 4.4,
LatMaturity =40 ,
diffMeanAgeAtMaturity = 1.5) # female - male)
ages = seq_len(12)
objFUN(par = c(Kfemale = 0.45, Kmale = .52),
ages = ages,
parGrow = parGrow)
res = optim(par = c(Kfemale = 0.45, Kmale = .52),
fn = objFUN,
ages = ages,
parGrow = parGrow)
data.frame(age = seq(0,15, .1)) %>% mutate(Lmale = vonBertalanffyGrowth(age, parGrow$L0, parGrow$Linf, res$par['Kmale']),
Lfemale = vonBertalanffyGrowth(age, parGrow$L0, parGrow$Linf, res$par['Kfemale']),
Lboth = vonBertalanffyGrowth(age, parGrow$L0, parGrow$Linf, parGrow$K)
) %>%
pivot_longer(cols = starts_with('L'), names_to = 'gender', values_to = 'L') %>%
mutate(gender = str_replace(gender, 'L', '')) %>%
ggplot(aes(x = age, y = L, color = gender)) +
geom_line() +
geom_abline(slope = 0, intercept = parGrow$LatMaturity)
data.frame(age = seq(0,15, .1)) %>% mutate(LStich = vonBertalanffyGrowth(age, L0 = 4.44, Linf = 45.4 , K = 0.49)) %>%
ggplot(aes( x = age, y = LStich)) +
geom_path() +
geom_abline(slope = 0, intercept = c(40.3, 42))
\ No newline at end of file
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