Closed brianlangseth-NOAA closed 2 years ago
Here is a figure showing the years and fleets with age data based on the incorrect entering, where the colors correspond to the correct fleets (black = 1, gold = 7). Code for this figures is provide
dummy_FeachY <- dummy_FeachY<- matrix(0, nrow = dat$endyr*dat$Nfleet, ncol = 2)
dummy_FeachY[(dat$Nfleet * (agecomp_yr[,"Yr"] - 1) + agecomp_yr[,"FltSvy"]),] <- agecomp_yr[,c(1,2)] #Assign for just the years and fleets in YFT data. Each year for all fleets.
dummy_FallY[(dat$endyr * (agecomp_yr[,"FltSvy"] - 1) + agecomp_yr[,"Yr"]),] <- agecomp_yr[,c(1,2)] #Assign for just the years and fleets in YFT data. All years for each fleet.
model_read <- cbind("Flt" = rep(1:7,256), "Yr" = unlist(lapply(c(1:256),FUN=rep,times=7))) #how the model reads
master <- cbind(model_read,
"Yr_prev" = dummy_FallY[,1], "Flt_prev" = dummy_FallY[,2],
"Yr_cor" = dummy_FeachY[,1], "Flt_cor" = dummy_FeachY[,2])
#Show difference between the data and what the model read
plot(x = master[master[,"Yr_prev"] > 0,"Yr"], y = master[master[,"Yr_prev"] > 0,"Flt"], col = master[master[,"Yr_prev"] > 0,"Flt_prev"], xlab = "Fleet", ylab = "Year", main = "How model previously read in age comps")
and here based on the correct entering
plot(x = master[,"Yr_cor"], y = master[,"Flt_cor"], xlab = "Fleet", ylab = "Year", main = "How agecomps really are")
This does improve estimates of selectivity when they are estimated but does not improve run time nor does it solve estimation of high F values.
This becomes more complicated with multiple areas (#39). If the same order as above is repeated for each area, then the setup for the comp calculations can be tested using
#Test how to set up comp order with different fleets for each year (all fleets for year 1,
#then all fleets for year 2....) and then repeating for each area
yy = rep(1:dat$endyr,dat$Nfleet*dat$N_areas)
ff = rep(unlist(lapply(seq(1:dat$Nfleet), rep, dat$endyr)),4)
aa = unlist(lapply(seq(1:dat$N_areas), rep, dat$endyr*dat$Nfleet))
set = data.frame(yy,ff,aa,(dat$Nfleet*(yy-1 + (aa-1)*dat$endyr) + ff))
ord_set = set[order(set$aa,set$yy),]
head(ord_set)
ord_set[(256*4-2):(256*4+2),] #check next area
For four area model with four fleets here is the set up of comps by year (x axis), new fleet structure (y axis) and panelled by area
ggplot(dat$lencomp, aes(Yr, newfltsvy)) + geom_point(color="steelblue") + facet_wrap(~ area)
and model output in the .tpl of the following matches the above structure
cout << "Region = " << r << endl;
cout << "Year = " << y << endl;
cout << "Fleet = " << z << endl;
cout << "catch at age " << OBS_catch_at_age_fleet_prop(1,r,y,z) << endl;
So Age comps are read in correctly
I have entered age comps in as every year for each fleet (meaning 256 entries for fleet 1, followed by 256 entries for fleet 2, etc), however the model is expecting age comps as every fleet for each year (meaning 7 entries for year 1, followed by 7 entries for year 2, etc).
I did a test and added
right after the fish_age_like calculations, and the first entry with non-zero values is the 93rd entry, which I had originally expected to the 93rd year for fleet 1 but which the model says is for year 14 in fleet 2 (and 13*7 + 2 = 93).
I need to make changes in the data_loading.R script for age comps for the fleet and survey and check whether it affects any other entries. Hopefully, this will speed up our progress.