pbs-assess / gfiscam

:cyclone: Groundfish integrated catch-age model
1 stars 5 forks source link

Missing term in multivariate logistic likelihood? #24

Open quang-huynh opened 2 years ago

quang-huynh commented 2 years ago

I was working through the derivation of Tech Doc equation 11, which seems to be missing a 0.5 term.

If the log-likelihood is -(A-1) * T * log(tau) - 0.5 * sum(eta^2)/tau^2, then substitution of the equation just above no. 11 should result in -0.5 * (A - 1) * T * log(tau^2) + constant since log(tau) = 0.5 * log(tau^2). Schnute and Richards (1995) also seem to be missing this 0.5 term in Table 4, L14, but the derivation is analogous to Appendix D of the ADMB manual which does have this 0.5 term.

Does the ADMB code have the 0.5 in the likelihood?

cgrandin commented 2 years ago

Which document are you looking at? i.e. which doc is where "Tech doc equation 11" is from? Can you put a link here..

quang-huynh commented 2 years ago

It's in iSCAMTechDoc.pdf

cgrandin commented 2 years ago

OK, where are you getting this equation from: -(A-1) * T * log(tau) - 0.5 * sum(eta^2)/tau^2

quang-huynh commented 2 years ago

That's equation L.9 in Table 3 of Richards and Schnute (1995), after taking the log

cgrandin commented 2 years ago

I'm having a hard time getting what you have from Eq 9, I get this after logging it:

-T * log(sqrt(2pi) * tau)    + T/2 * log(A)   - (1/(2 * tau ^2) + sum(sum(eta ^ 2))

So log(A) would have to be equal to log(sqrt(2pi) * tau) to subtract the T's in the first two terms, am I missing something?

quang-huynh commented 2 years ago

I have -T * (A-1) * [log(sqrt(2pi)) + log(tau)] for the first term.

Both log(sqrt(2pi)) and T/2 * log(A) can be dropped since they are constants

cgrandin commented 2 years ago

The ADMB source code is completely undocumented and convoluted, and every time I look at it I feel a little sick.

I think it could be this: https://github.com/admb-project/admb/blob/baf480ffe84bc8c1054a3334d15a9885d0bceed1/contrib/statslib/dmultinom.cpp#L50

quang-huynh commented 2 years ago

I think that's the link to the multinomial likelihood. I see the dmvlogistic call in iscam.tpl for the multivariate logistic likelihood.

Looks like dmvlogistic is also distributed in ADMB: https://github.com/admb-project/admb/blob/main/contrib/statslib/dmvlogistic.cpp