-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OSA residuals #1
Comments
I added the OSA example I wrote to the repo here. https://github.com/pbs-assess/renewassess/blob/main/code/OSA/OSA_Multinomial.R Feel free to edit it please if it's wrong! |
At nearly the same time(!) I added some notes in https://github.com/pbs-assess/renewassess/blob/main/osa-notes.Rmd on what's happening within the TMB machinery to calculate OSA oneStepGeneric residuals. It's pretty crazy to wrap your head around... data become parameters and you profile over them. |
@seananderson I need to digest that a bit. |
Well that was an enlightening exercise... I got your R script @paul-vdb to match the TMB OSA residuals exactly here. Partly I did the calculations matching TMB so I could check my calculations as I went and that solidified some of my understanding about how the observation likelihoods accumulate as you step through the data. I also edited your original script to vectorize the |
Thanks @seananderson |
@seananderson I dug deeper. The way I wrote the original OSA was correct. It didn't match the set.seed argument because they (RTMB) simulate the runif for the full set of observations and then subset. I subset from the outgo and so that length difference in the argument was the difference maker. Thank goodness since when I went through the maths of your OSA2 file it was exactly mine. Looking at the output from the onesteppredict function it also was calculating the same Fx and px values as I was too! So in short, original function is technically correct for the multinomial with no other complexity. From Equation 8 in Thygesen, What makes life easy for the multinomial, is that when you write it as conditional binomials, then they are independent and as a result, Their way of calculating z, |
Discussion on OSA residuals
Here are a couple more links on OSA residuals:
Slides by Cole Monnahan on using OSA Residuals in stock assessment: Slide 1 (npfmc.org)
An R package for calculating OSA Residuals for compositions: https://github.com/fishfollower/compResidual
Papers:
Trijoulet et al 2023
Li et al. 2024
Thygesen et al. 2017
The text was updated successfully, but these errors were encountered: