noaa-afsc / afscOSA

One-step ahead (OSA) residuals for age and length compositions fit in stock assessment models.
0 stars 0 forks source link

Expand to include the Dirichlet-multinomial #2

Open Cole-Monnahan-NOAA opened 1 month ago

Cole-Monnahan-NOAA commented 1 month ago

Some of us are using the D-M likelihood and that requires new features to this package.

I use the following code:

 if(model=='Dirichlet-multinomial'){
    ## recreate the alpha matrix, must match the cpp side, here
    ## it is linear form
    alpha <- rowSums(o)*p*theta
    o2 <- cbind(o[,-ind], o[,ind])
    alpha <- cbind(alpha[,-ind], alpha[,ind])
    resid <- compResidual::resDirM(t(o2), t(alpha))
  }

where theta is equal to the exponentiated parameter estimated by the model and is used like this vector<Type> alphas = sum(otmp) * etmp * exp(log_DM_pars(0));

And an effective sample size is calculated as plogis(log(theta))*N where N is the input sample size.

This is the "linear" form (recommended), so we need to be careful because there is another form that I think may be used by SS3.