Closed iantaylor-NOAA closed 7 years ago
regarding request 5 - just putting my quick and crude code here that I used to build the first version table and extract to excel...
setwd("C:/Users/Aaron.Berger/Documents/GitHub/hake-assessment/models/45_BasePreSRG_v4") wdir=getwd() library(r4ss) model <- SS_output(dir=wdir) c_age<-model$catage[model$catage[,"Yr"]>1965,] n_age<-model$natage[model$natage[,"Beg/Mid"]=="M",] n_age<-n_age[n_age[,"Yr"]<2017,] n_age<-n_age[n_age[,"Yr"]>1965,] exp_age <- (c_age[,11:31] / n_age[,12:32])*100 dimnames(exp_age)[[1]] <- seq(1966,2016,1) exp_age <- cbind(c(seq(1966,2016,1)),exp_age) dimnames(exp_age)[[2]] <- c("Year",seq(0,20,1)) write.csv(exp_age, file = "C:/Users/Aaron.Berger/Documents/AMB/Hake/2016.2017/Runs/Exp-at-age.csv")
just putting this on here per Chris ask at this time...
I can make the table up in the tables section. Thanks for the code
We can likely augment or copy make.est.numbers.at.age.table in tables-age.r to do these calcs.
Trying to think about the tables to add, the following seem like they could all be useful and maybe fulfill the requests, we could include
I'm having a look at this now, will do my best to complete
Do we want these tables (or some subset of them) in an appendix or the main document. I could go either way. I guess because they are mostly just reorganized or translated output that is already in the main tables section, I was originally thinking these could go in an appendix. When we build these, let's also automatically save the tables as csv files (or similar) in a subfolder so that we can send folks the data to 'play with' as I'm expecting folks will want to do given history...
I was thinking of adding them to the main tables section just to follow the estimated numbers-at-age table. That would probably be easiest at this point. Making them csv files as well is a good idea. I'll make an output directory for those that gets populated when the document builds.
I have done these in commits 510fcf991b8a6153a53f5fb2b3e0004f2cf829a1 and a4cd1f73d365d35154c7ef7f0c8e82f19d56bb19. Please check the captions for units and beginning/middle of year. I think they are correct but would be great if they were double-checked. Also, the biomass-at-age shows all ages unlike the numbers-at-age table because I wasn't sure how to apply the weights-at-age for a plus group. I would think maybe the mean of the plus-group ages but we can discuss or leave as-is. All these tables are made using the make.est.numbers.at.age.table() function with table.type argument set in r-functions/tables-age.r as Ian suggested. Also, if we want to move to an appendix it is just cut-and-paste from the main-tables.rnw file.
Good job. I think the tables are best where they are, since they follow on naturally from the numbers-at-age. I was wondering why they go up to 20, not 15+, but you've explained the reasoning in the above comment - I think fine for now not to try and fiddle with them. I can try and add some text to the main text.
I'm not clear whether Table 23 [24] captions should be 'catch-at-age in numbers [biomass] at the beginning of the year' or '... in the middle of the year.' The code doesn't specify (unlike the exploitation rate table), but if catch is assumed to occur in the middle of the year then presumably it should be middle? Ian/Aaron?
Sorry for not giving input on the new tables yet. Thanks for getting them added. I'm building the doc now to take a look and will then chime in on this issue and any other related ones soon.
Or is it simpler to just leave out 'at the beginning of the year' for Table 22-24. Table 21 is correctly the biomass at the beginning of each year, but the next three are all to do with catches in each year, and so maybe just: 'for each year'. i.e. numbers and biomass are are the start of a year, but anything to do with catch is for that whole year (doesn't really matter what the model actually calculates).
**Okay, I never actually did this. I think I'm right (!) so will do it now, just updating the captions - to me they don't quite read right.
Ian - I just edited one caption in 55055bd
Tables are really useful. They look correct to me (I've only taken a quick look at the code, but the numbers in the tables seem to make sense). You can nicely see the cohorts growing in biomass and then declining.
Added some brief text, just alerting the reader to the tables. Don't think we need to add much interpretation (could maybe point out that the exploitation-rate-at-age values stay constant for ages 6 and above because selectivity is constant there - may be better to squeeze that into the caption).
I think the new tables look great and a a really valuable addition. Thanks @cgrandin for putting these together. We should probably have thought to add these years ago.
Two ideas that I'm happy to let go of if they don't sound appealing:
Regarding the timing of the exploitation rate, I think we should just take out the "middle of the year" phrase from Table 22. The assumption in SS (for a model configured like ours) is that 50% of the natural mortality is applied prior to the fishery to get middle-of-year numbers, then the fishery removals occur in a single pulse, then the remaining fishing mortality is applied afterwards. But I think going into any of that detail.
I'm adding a bit more to the caption in Table 11 and can edits any other captions as needed.
I forgot to mention that the numbers all seem to check out. I added up the catch-at-age in biomass for 2016 and got the same value (with 1 t rounding difference) as our reported catch for 2016. And the sum of the 2016 row in the biomass-at-age table adds to the value of total biomass in the base model (again with rounding differences): base.model$timeseries$Bio_all[base.model$timeseries$Yr==2016] (which differs from the Total Biomass value in Table 18 which is MCMC median)
And the numbers match up with the table I made at the SRG....
On Tue, Feb 21, 2017 at 5:12 PM, Ian Taylor notifications@github.com wrote:
I forgot to mention that the numbers all seem to check out. I added up the catch-at-age in biomass for 2016 and got the same value (with 1 t rounding difference) as our reported catch for 2016. And the sum of the 2016 row in the biomass-at-age table adds to the value of total biomass in the base model (again with rounding differences): base.model$timeseries$Bio_all[ base.model$timeseries$Yr==2016] (which differs from the Total Biomass value in Table 18 which is MCMC median)
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/cgrandin/hake-assessment/issues/283#issuecomment-281535644, or mute the thread https://github.com/notifications/unsubscribe-auth/AHk_-o6naV-Txe0OWr9fq0xT_wEhfG2Kks5re4twgaJpZM4MDaZ2 .
--
Aaron M. Berger, Ph.D. Research Mathematical Statistician Fishery Resource Analysis and Monitoring Division Northwest Fisheries Science Center 2032 SE OSU Dr. Bldg. 955 Newport, OR 97365-5275
aaron.berger@noaa.gov aaron.berger@noaa.gov541.867.0562
Great that all the numbers work out.
Regarding Ian's number 1, I find that % signs just add tons of clutter (in future we could maybe leave them out of other tables, I find them cluttery). The caption says %, which is fine.
Regarding 2 - I think my slight preference is to leave as is. Things like 0.065 million get a bit unintuitive. And as you say will add zeros all over the place.
Tables look great. I think we still need to address SRG request 6, correct? SRG request 6 states: prepare a table for the major cohorts of catch weight, natural mortality weight and surviving weight by age for inclusion in the final assessment document going to the JMC.
I don't think this has been done yet, has it? I had originally thought something like the below, but then reading Ian's email about the timing of M (half before fishery and half after fishery) makes me think it isn't so straight forward to get the M weight removed.
Ian, I recall you had a thought at the SRG meeting about this one....
Upon further thought, I guess you could subtract out 'early' M using (1-exp(-M)), then subtract out biomass due to fishing (the catch) and then subtract out the 'late' M.
So the steps would be: N(initial) (1-exp(-M))^0.5 = Loss from M(early) [N(initial) - Loss from M(early) - catch] (1-exp(-M))^0.5 = Loss from M(late) M(total) = Loss from M(early) + Loss from M(late)
But when does 'growth' occur? Must be at end of time period when switching to next year's weight at age, correct?
Andy and I were thinking that the new tables (21 and 24) cover the catch weight and surviving weight. So, we only need the natural mortality weight, right? They ask for "major cohorts" but we have them all in the tables so it seems that it would be ok.
I agree. I just wonder as it was an explicit request that we provide it this year (in SRG request appendix) and not again next year because as you say it mostly in the new tables. We could even just .eps into the SRG request appendix. Thoughts?
Another way might be to make a new table of natural mortality weights which looks like the others and is with them in the main document. How did you build the table above? If there is code I/we can incorporate it into the assessment. We aren't sure how to extract the natural mortality weights.
I just saw issue #287 and it is overlapping this. If M is just biomass-at-age - catch-weight-at-age then I can do this now. But what about growth?
Ian, can you comment on when/how growth works. I figured it must be instantaneous at the year break with new weight at age vector. I don't think M is just biomass-at-age - catch-weight-at-age because M acts on just the biomass at age at the beginning of the year until mid-year and then it acts on what remains from that minus catches (occur instantaneously at mid-year) for the 2nd half of the year. As in: So the steps would be: N(initial) (1-exp(-M))^0.5 = Loss from M(early) [N(initial) - Loss from M(early) - catch] (1-exp(-M))^0.5 = Loss from M(late) M(total) = Loss from M(early) + Loss from M(late)
Honestly, this is just my best guess, but I could be wrong...
Trying to reply but messages keep arriving.
Sorry for replying out of order. This thread is more complete. Aaron's format matches what I had imagined and I think would make it easier for folks to compare impacts of fishing vs. mortality.
I think that representing growth in the switch from surviving biomass at the end of the year to beginning of year biomass makes the most sense. That's the simplification that's assumed with the empirical weight-at-age setup.
I think the simplest way to get surviving biomass, would be to the beginning of year numbers at age and multiply them by the weight at age for the previous age.
That is, surviving biomass at end of year at age 2 would be estimated as the numbers at age at the beginning of age 3 multiplied by the average weight of age 2 from the previous year. So we assume no change in numbers from Dec 31 to Jan 1, just magically increasing in weight. Then the loss due to M would be the start year biomass - end year biomass - catch.
Just so everyone knows, I am trying to create this table.
Thank you!
Done in commit 7ec533891bf5280f9cd7d7cd83c5937f637ce086. We can add more cohorts in the call to the function, and reduce font size if it's worth showing more. I haven't tested that but it should work. Check the values and hopefully this is a wrap.
Maybe keep open until Ian/Aaron can confirm the values. I'm just updating the caption, and then will try and understand it more.
Table looks really good and I think will be useful. This is essentially what Shannon was trying to get at but will be useful to many others as well.
The values in the M column aren't quite right so am looking at the code in /r-functions/tables-age.r. Will report again soon.
Though it seems that Start Biomass - catch weight = Mortality so that seems correct to me. The Surviving Biomass not matching the following year's Start Biomass is kind of strange, but makes sense in terms of the empirical weight-at-age figure (I'm just looking at that trying to understand it). But the M seems to make sense. I guess you're saying it's not quite what the model does (but close enough?).
My first attempt to change didn't come out right so I'm debugging.
The M column is just natural mortality, so should be whatever part of the different from starting to surviving biomass isn't included in the catch column. Therefore, I think it should be Start Biomass - Surviving Biomass - Catch Weight = Mortality
I would have thought loss in weight due to M would have been more similar to the table I inserted in this issue earlier. I guess I'm not clear as to why all the starting biomass would be attributed to M (other than catch)? Maybe its just the way its calculated (using the what's leftover part to equal M after accounting for growth via weight-age), whereas I was attempting to calculate M directly and whatever was left over was surviving...
Oh yes, I was completely wrong - was trying to do it too quick. Yes, M seems to be wrong as currently implies there would be no fish left. Have printed out the tables to take a look, but, yes, something is very wrong....
Chris was working pretty intensely on it and has gone home, but will check in again soon-ish (I think). The code is pretty complex!
I think with either direct or indirect calculations of M and surviving biomass you should get identical answers. I think I'm getting to understand Chris's code so will attempt a fix soon.
Doing it by hand just to confirm that I'm making sense:
For 2014 cohort, in 2014 at age 0, they were 10,501 million numbers (Table 20). At 0.0148 kg each, that's 155 thousand t. Catch is assumed to be zero on age-0 fish due to no selection. The beginning of 2015 has 8,465 million remaining. If we assume that at the end of 2014 (the day before), these fish still weighed 0.0148 kg, then this is 125 thousand t surviving to the end of the year, with a difference of 30 thousand t that is all attributed to M. If there were a catch it would be removed from the 30 to get M.
I knew there would be some issues - just got it out so there are 4 of us looking at it instead of 1. The M values are calculated as biomass at age (baa) - catch at age (caa), where baa is numbers at age (naa) * weight at age (waa) and caa is directly from the catch-at-age matrix.
I'm also thinking that the survived biomass is wrong. I removed the age-0 from the previous year's weight-at-age which I believe is the wrong way to shift it. I'll work on fixing that one.
I think I've got a fix in the works, by defining a matrix of numbers at age in the following year (needs to include 2017). However, if stress of approaching deadline is too much for folks we can just give up and put off until next year.
Let's see if your fix works Ian and go with it if it does, otherwise if we get too close to 5PM let's stop and compare docs and then submit.
On Wed, Feb 22, 2017 at 3:28 PM, Ian Taylor notifications@github.com wrote:
I think I've got a fix in the works, by defining a matrix of numbers at age in the following year (needs to include 2017). However, if stress of approaching deadline is too much for folks we can just give up and put off until next year.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/cgrandin/hake-assessment/issues/283#issuecomment-281839546, or mute the thread https://github.com/notifications/unsubscribe-auth/AHk_-goaFZvoMSNTEvmoNIgd5HE2CjYqks5rfMSlgaJpZM4MDaZ2 .
--
Aaron M. Berger, Ph.D. Research Mathematical Statistician Fishery Resource Analysis and Monitoring Division Northwest Fisheries Science Center 2032 SE OSU Dr. Bldg. 955 Newport, OR 97365-5275
aaron.berger@noaa.gov aaron.berger@noaa.gov541.867.0562
I think I've got it sorted out. Building doc to check and will commit in a minute.
I think the table now looks OK as of fix in 26e94ce:
Looks good Ian, I am close to a fix for the surviving biomass.
I think I got both M and Surviving biomass columns fixed together in that commit.
Or rather, I fixed surviving biomass and then used that to figure out what M had to be to get there.
The numbers seem to add up where I checked them. For 2014 cohort, the age-2 Start Biomass value of 1,661.3 matches Table 21 value for age-2 in 2016: 1,661. The Catch Weight value of 99.1 matches the Table 24 value for age-2 in 2016: 99,146, and the Start Biomass - Catch - M = Surviving biomass.
It would have taken me a long time to write such nice generalized code to make the table in the first place, but I think I was able to modify the existing function in the correct way thanks to all the work Chris did to make it.
Thanks Ian, I looked more closely at your code and see that. The values make more sense now also. Nice work
As noted in SRG requests 5 and 6 from 2017: