gadget-framework / gadget3

TMB-based gadget implemtation
GNU General Public License v2.0
8 stars 6 forks source link

equivalent to prey aggregation file #162

Closed vbartolino closed 1 week ago

vbartolino commented 1 week ago

I'm unsure about an equivalent of the g2 prey aggregation file to be used when specifying the stomach likelihood.

In practice, one of the stomach likelihoods will focus on prey species composition in the stomachs, and we need to tell the model that some preys are the results of aggregating several g3_stock. For instance, vendace in the dataset below would be the aggregation of ven_imm and ven_mat

expand.grid(
    year = 2000:2005,
    predator_length = c(40,160),
    stock = c('vendace', 'otherfood'),
    number = 0 )
lentinj commented 1 week ago

This is where the stock_re column comes in, if you replace the stock column in the above with stock_re = c('^ven_', 'otherfood'), then you'll compare against an aggregate of ven_imm & ven_mat.

bthe commented 1 week ago

If I'm not mistaken you can use regex by using the stockre column, instead of stock, and specifying the prey stock as "ven*" to capture both "ven_imm" and "ven_mat".

lentinj commented 1 week ago

Snap :)

Maybe it'd be nicer to say stock_alias = list(vendace = c('ven_imm', 'ven_mat')) somewhere separate to the data, but the stock_re column is how to do it today.

vbartolino commented 1 week ago

This is where the stock_re column comes in

brilliant! thanks

bthe commented 1 week ago

Yes, or figure out a way to use the stock name parts in the likelihood.

lentinj commented 1 week ago

Using the stock name parts is easily do-able actually---I think the stock_re mechanism predates name parts, which is why we ended up with it.

The only downside is that you might be mislead into having a stock column with both ven & ven_imm, which won't do what you want (ven_imm won't be duplicated across both), but that's already a problem with stock_re anyway.

vbartolino commented 1 week ago

when making the likelihood for the prey size composition in the stomachs I find that g3l_catchdistribution complains when the prey length groups are defined with "len"

preyLenGrp <- mfdb_interval("len", seq(...
...
> g3l_catchdistribution(
+         'rin_stom_ven_len',
+         rin.stom.ven.len,
+         fleets = pred_stocks,
+         # NB: Only referenceing stocks included in observation data
+         stocks = list(stocks_ven[[1]], stocks_ven[[2]]),
+         g3l_distribution_sumofsquares(),
+         nll_breakdown = TRUE,
+         report = TRUE )
Error in stop("Unknown form of ", var_name, " levels, see ?cut for formatting: ",  : 
  argument "var_name" is missing, with no default

while I've no problem with preyLenGrp <- mfdb_interval("", seq(...

g3l_catchdistribution does not complain in the same way for the predator_length

lentinj commented 1 week ago

Are you renaming the column from MFDB, but not renaming the attribute? It's not found the "length" attribute, and falling back to trying to parse the column character values.

gadget3:::parse_levels() doesn't know how to parse columns with "len(x)" in, we could add it admittedly, but then we'd loose the upper value that MFDB may have set.

vbartolino commented 1 week ago

Are you renaming the column from MFDB, but not renaming the attribute?

yes, that must be the problem. I was doing that because g3l_catchdistributionwas complaining for the column name prey_length