You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a stock that has no catch numbers at age 0 but i do have a tuning index at age 0. I cannot have a stock object that has fewer ages than the index, so need to include age 0 in the stock object and set the catch.n to NA.
You can then fit the SAM model but when SAM2FLR tries to populate the harvest slot it breaks.
Below is some example code to illustrate the problem:
library(FLSAM)
data(NSH)
data(NSH.sam)
what if you have no catch at age 0 but you do have a tuning index:
the model fits but when it tries to convert it into an FLSAM object it fails
sam <- FLSAM(NSH,NSH.tun,NSH.ctrl)
this bit does work
sam <- FLSAM(NSH,NSH.tun,NSH.ctrl,return.fit=T)
this doesn't
SAM2FLR(sam,NSH.ctrl)
the problem is here in the SAM2FLR function where it tries to pupulate the harvest slot
it uses the ctrl@states to get the f at each age, but if your state is -1 for age 0
and age0 does exist in your FLstock object, it doesnt put NA's in for that first age
res@harvest <- FLQuant(
exp(fit$pl$logF[ctrl@states[grep("catch", rownames(ctrl@states)), ] + 1, ]),
dimnames = list(age = ctrl@range["min"]:ctrl@range["max"],
year = ctrl@range["minyear"]:ctrl@range["maxyear"],
unit = "unique", season = "all", area = "unique",
iter = 1))
the stockassessment package has some handy functions the do the right thing, e.g fatable()
could be used like below
res@harvest <- FLQuant(t(stockassessment::faytable(fit)),
dimnames = list(age = ctrl@range["min"]:ctrl@range["max"],
year = ctrl@range["minyear"]:ctrl@range["maxyear"],
unit = "unique", season = "all", area = "unique",
iter = 1))
Similarly, the stock.n slot could be populated using ntable()
Finally, SAM2FLR does not update the catch.n and catch with the fitted values, is this by design? I think it would be nice to get those out as well
The text was updated successfully, but these errors were encountered:
Good suggestion to use the newly available faytable and ntable functions.
However, conceptually I'm less sure about the hack you are suggesting (of course, technically it can be solved, but if we should is a different story).
I don't have a solution for it, so I pushed the technical solution.
Wrt catch and catch.n, it is by design and modelled catch can be obtained from catch(sam). However, catch.n was not a function yet and this has been added so you can call catch.n(sam)
I have a stock that has no catch numbers at age 0 but i do have a tuning index at age 0. I cannot have a stock object that has fewer ages than the index, so need to include age 0 in the stock object and set the catch.n to NA.
You can then fit the SAM model but when SAM2FLR tries to populate the harvest slot it breaks.
Below is some example code to illustrate the problem:
what if you have no catch at age 0 but you do have a tuning index:
you dont want to estimate F for age 0
the model fits but when it tries to convert it into an FLSAM object it fails
this bit does work
this doesn't
the problem is here in the SAM2FLR function where it tries to pupulate the harvest slot
it uses the ctrl@states to get the f at each age, but if your state is -1 for age 0
and age0 does exist in your FLstock object, it doesnt put NA's in for that first age
the stockassessment package has some handy functions the do the right thing, e.g fatable()
could be used like below
Similarly, the stock.n slot could be populated using ntable()
Finally, SAM2FLR does not update the catch.n and catch with the fitted values, is this by design? I think it would be nice to get those out as well
The text was updated successfully, but these errors were encountered: