Skip to content

Commit

Permalink
Fix missing variable M at length in LBSPRfit_(..., useCPP=TRUE)
Browse files Browse the repository at this point in the history
Variable natural mortality at length not applied when Mpow>0 for fitting
the model to observed size distribution (LBSPRfit_ function) while using
C++ function to calculate the NLL. Fixed by applying the allometric
relationship to M/k (a similar way as implemented in the simulation
function - LBSPRsim_).
  • Loading branch information
yreecht committed Oct 21, 2018
1 parent 92695ea commit e8920f9
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion R/LBSPRfit_.r
Expand Up @@ -77,7 +77,14 @@ LBSPRfit_ <- function(yr=1, LB_pars=NULL, LB_lengths=NULL, Control=list(),
if (modType=="GTG") {
SDLinf <- LB_pars@CVLinf * LB_pars@Linf
gtgLinfs <- seq(from= LB_pars@Linf-maxsd*SDLinf, to= LB_pars@Linf+maxsd*SDLinf, length=ngtg)
MKMat <- matrix(LB_pars@MK, nrow=length(LBins), ncol=ngtg)

## Variable MK at length if allometric exponent of M-length relationship (Mpow) >0:
MKL <- LB_pars@MK *
(LB_pars@Linf / (LBins + 0.5*By))^ ifelse(is.null(LB_pars@Mpow) || length(LB_pars@Mpow) < 1,
0, LB_pars@Mpow[1]) # Mpow from LB_pars or 0 if not defined.

## ..formated as a matrix, one column by GTG (MKL of same length as LBins):
MKMat <- matrix(rep(MKL, ngtg), nrow=length(LBins), ncol=ngtg)
recP <- dnorm(gtgLinfs, LB_pars@Linf, sd=SDLinf) / sum(dnorm(gtgLinfs, LB_pars@Linf, sd=SDLinf))
usePen <- 1
if (!pen) usePen <- 0
Expand Down

0 comments on commit e8920f9

Please sign in to comment.