timjmiller / wham

State-space, age-structured fish stock assessment model
https://timjmiller.github.io/wham
Other
32 stars 16 forks source link

selectivity re="ar1" with model = "age-specific" options to prepare_wham_input function #61

Closed timjmiller closed 4 months ago

timjmiller commented 2 years ago

selectivity$model = "age-specific" without random effects will estimate or fix each age-specific selectivity parameter (estimated as fixed effects) according to specifications of the asap3 dat file or (over-ridden by) selectivity$initial_pars and selectivity$fix_pars arguments. When selectivity$re = "ar1" is added, all of the age-specific selectivity fixed effects are still estimated along with corresponding age-specific random effects. This fit is unlikely to (or will never?) converge properly because there are two parameters for each category. (The variance of these random effects goes to 0).

The appropriate default should be to estimate a single fixed effect parameter as the mean across ages to which the age-specific ar1 random effects are added. This can be done by setting the appropriate input$map$logit_selpars entries to be the same value for all estimated ages in the selectivity block. Some care may be needed for convergence when most or all of the ages are fixed with selectivity$fix_pars.

I expect this would also be problematic for other selectivity$model options.

brianstock commented 2 years ago

AR1 across ages is working now, https://github.com/timjmiller/SSRTWG/commit/3741fded0f0f6c312a1f3a43da80a4982fad112b. Added a warning if no ages are fixed but allow model fitting so you can 1) fit model, 2) find age with highest estimated selectivity, 3) use set_selectivity() to fix that age at 1, and 4) re-estimate model. Not thoroughly tested yet.

Rick-Methot-NOAA commented 2 years ago

How do you handle AR in both age and time such that the age with max selectivity changes over time? Do you have any direct comparisons to the approach as implemented in SAM, or in Ianelli's models?

timjmiller commented 2 years ago

It is a stationary and separable 2D AR1 process on logit scale. The basic usage is to have constant age(s) at full selectivity over time. Those ages and any fixed at 0 are omitted from the AR process. There are undocumented ways of allowing all ages to be included in the process which requires fixing full F or q to be sufficiently large that the selectivity parameters will not hit upper bounds.

I believe SAM uses a time-varying selectivity through MVLN random walk in FAA (not for indices). Not sure what Jim does with AMAK.

On Wed, Jul 13, 2022 at 12:10 PM Richard Methot @.***> wrote:

How do you handle AR in both age and time such that the age with max selectivity changes over time? Do you have any direct comparisons to the approach as implemented in SAM, or in Ianelli's models?

— Reply to this email directly, view it on GitHub https://github.com/timjmiller/wham/issues/61#issuecomment-1183414214, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEIGN7FR5SFBN2QI42WYV3DVT3S6TANCNFSM5WBOCMWQ . You are receiving this because you authored the thread.Message ID: @.***>

-- Timothy J. Miller, PhD (he, him, his) Research Fishery Biologist NOAA, Northeast Fisheries Science Center Woods Hole, MA 508-495-2365

Rick-Methot-NOAA commented 2 years ago

OK. That's what I figured. So a separate AR process is needed to allow the q for that max_sel age to change over time. Still seems illogical to assert 2DAR process, but one age is not allowed to change. I'll touch on this topic in my CAPAM talk on selectivity

timjmiller commented 2 years ago

Configuring AR for fully-selected q as a separate process is an option in WHAM. The undocumented approach allows a full q that can change with age and in magnitude over time. The qAA = q *sel(y,a), so the age and magnitude for full q can be derived from that matrix.

On Wed, Jul 13, 2022 at 1:16 PM Richard Methot @.***> wrote:

OK. That's what I figured. So a separate AR process is needed to allow the q for that max_sel age to change over time. Still seems illogical to assert 2DAR process, but one age is not allowed to change. I'll touch on this topic in my CAPAM talk on selectivity

— Reply to this email directly, view it on GitHub https://github.com/timjmiller/wham/issues/61#issuecomment-1183480616, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEIGN7GQMGOG6YXN77344KTVT32U5ANCNFSM5WBOCMWQ . You are receiving this because you authored the thread.Message ID: @.***>

-- Timothy J. Miller, PhD (he, him, his) Research Fishery Biologist NOAA, Northeast Fisheries Science Center Woods Hole, MA 508-495-2365

Rick-Methot-NOAA commented 2 years ago

OK. That is what SS3 does as well.

Cole-Monnahan-NOAA commented 1 year ago

Why not let the user input a vector of ages at which to normalize in each year? So like c(6,6,6,7,8) or something which can be determined from a previous run by taking the max across ages by year? Then you can have all age:year effects in the AR process.

Rick-Methot-NOAA commented 1 year ago

SS3 and Ianelli's AMAK uses that approach. A consequence can be that the normalized value of selectivity can be >1 for some ages. That is OK, but need to be careful about reporting the resultant F for that year.

Cole-Monnahan-NOAA commented 1 year ago

Sorry I didn't mean normalize, I meant divide by the max. So you divide by max in each year as standard but have the user input it as data to preserve differentiability.

timjmiller commented 1 year ago

@Cole-Monnahan-NOAA how would you know a priori which age to use for scaling if there are RE for each age? It seems like the selectivity>1 issue noted by @Rick-Methot-NOAA could still occur.

Cole-Monnahan-NOAA commented 1 year ago

You'd have to do a two-step process. Fit the model then do y=apply(selAA,1,which.max) and pass y back in and refit the model w/ that data input. Isn't that what WHAM does now but for a single age? The user can specify it?

Does that break the AR1 structure though? Not sure if that's a good idea to do statistically. If there are large changes in selex then dividing by a different age could move things around and makes interpretation of the RE kinda tricky, I think.

timjmiller commented 4 months ago

closing this as fixed thanks to @brianstock a long time ago.