pbs-assess / sdmTMB

:earth_americas: An R package for spatial and spatiotemporal GLMMs with TMB
https://pbs-assess.github.io/sdmTMB/
183 stars 26 forks source link

Interactions with get_index #255

Closed MikkoVihtakari closed 12 months ago

MikkoVihtakari commented 12 months ago

I am trying to make a model where sex of fish is represented using an interaction allowing sexes to have different trends over time: sdmTMB(value ~ 0 + fyear * sex + poly(log(depth), 2), ...)

I can do ggeffects::ggeffect(fit, terms = c("fyear", "sex")) to get the marginal effects, but is there a way to split indices to sexes using the get_index() function? When I run the function, I get the index with both sexes I presume. At least it is not split by the interaction.

My prediction grid has both sexes replicate_df'd.

ericward-noaa commented 12 months ago

I think the issue is similar to when people have multiple sub-regions that they want to develop indices for? For those cases, there hasn't been a easy way to produce multiple indices simulteneously, and we've recommended (1) subsetting the prediction grid with each area (or in your case sex) of interest, and (2) calling get index for each subsetted prediction grid

MikkoVihtakari commented 12 months ago

Ah, I see now that when I subset one of the sexes from the prediction grid, I get index for that sex and when I won't subset, I get the summed-up index. Brilliant! Thanks a lot for help Eric. This issue can be closed from my part.

ericward-noaa commented 12 months ago

Ok great - glad it worked!