Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 2022update #44

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft

Fix 2022update #44

wants to merge 10 commits into from

Conversation

kellijohnson-NOAA
Copy link
Contributor

Implements

Still need to add

kellijohnson-NOAA and others added 8 commits April 15, 2022 14:16
Some of the entries in `model[["data_list"]]` have the class
"units" which makes performing operations on them difficult.
Using `as.vector(...)` around the vectors with this class removes
the errors that I was getting. See below

```
Error in Ops.units(model[["data_list"]][["b_i"]], 0) :
  both operands of the expression should be "units" objects
```
Before, if there were no standard errors the model would continue
instead of entering the early return. Errors/Warnings would arise
because in the plotting of the index the standard errors are needed.
We should not be doing diagnostics on models without inverted hessian
matrices; so, now `VAST_do()` will exit early if the model did not
converge rather than erroring out.
if `fit = NULL` which is the default, then the function doesn't work.
This change provides the model output, which is labelled `out`,
to the `fit` input argument.

Closes #41
Changes to VAST and FishStatsUtils that create the file
Index rather than Table_for_SS3 led to column name changes.
These legacy columns are easily recreated and saved similar to
the old table in Table_for_SS3.csv to allow downstream code to work.
This change was discussed in #39 with great changes made by
@chantelwetzel-noaa but we decided to go with the simpler change here
rather than changing the column names of everything in VASTWestCoast
which would also lead to code changes that would be needed for
assessment purposes.
use_anisotropy = TRUE is the default in make_settings(),
which was previously used by VASTWestCoast, now
users can put FALSE in their get_settings() input list if
they want to chagne it. This turns off the estimation of the
H matrix that allows for spatial rotation, i.e., rotation
of the axis to be slanted rather than perpindicular to the coast.
@kellijohnson-NOAA kellijohnson-NOAA force-pushed the fix_2022update branch 2 times, most recently from 3537e84 to 00a9fec Compare April 21, 2022 20:58
@kellijohnson-NOAA
Copy link
Contributor Author

@chantelwetzel-noaa I compared runs for sablefish to those done for the 2019 stock assessment and the biomass estimates were within 12%. I think this is pretty good because it was with a different kmeans file. I need to check I get the same results when using the same kmeans file and then I think we can merge this into main/master. What do you think?

@kellijohnson-NOAA
Copy link
Contributor Author

@chantelwetzel-noaa I have been thinking about this and do we need to exponentiate the log(sd) and convert the units then take the log again because I for sure did NOT do that.

@chantelwetzel-noaa
Copy link
Contributor

Thanks for the reminder about this pull request. Initially, I did not think we would need to but I just compared results ran in 2019 for petrale sole and now I am not so sure. The biomass estimates from the new run are consistently lower ~6% using which are not that concerning since a different kmeans file was use, but the standard errors in the "converted" results are a fair bit lower (30-50%). This makes me wonder if there is a conversion issue. Have you done a comparable sablefish run with the same kmeans file?

@kellijohnson-NOAA
Copy link
Contributor Author

I think the best thing to do would be to roll the code for {VAST} back to a version that had output in mt and see how Jim originally did the conversion compared to what is being done now. Then mimic that rather than just trying to match output. I can do that today.

@chantelwetzel-noaa
Copy link
Contributor

I agree. Thank you for working on this.

@kellijohnson-NOAA
Copy link
Contributor Author

Here are the sections of code that are doing the calculations. {VAST} and {FishStatsUtils} assume that the units are kg unless otherwise stated. Thus we can use

subdata[, "Catch_mt"] <- subdata[, "Catch_KG"] / 1000
units(subdata[, "Catch_mt]) <- "t"

and change line 107 of VAST_do to

b_i = subdata[, "Catch_mt"],

This just scales the estimates in Index.csv by 1000 for Estimate and Std. Error of Estimate. Std. Error for ln(Estimate) is not changed at all.

Current James-Thorson-NOAA/FishStatsUtils@92a2cd9

Table = cbind(
  expand.grid(dimnames(par_hat[[index_name]])),
  "Units" = make_unit_label( u=units(par_hat[[index_name]]), lab="", parse=FALSE ),
  "Estimate" = as.vector(par_hat[[index_name]]),
  "Std. Error for Estimate" = as.vector(par_SE[[index_name]]),
  "Std. Error for ln(Estimate)" = as.vector(par_SE[[log_index_name]])
)
write.csv( Table, file=paste0(DirName,"/Index.csv"), row.names=FALSE)

James-Thorson-NOAA/FishStatsUtils@80d5cbe

Table = NULL
  for( cI in 1:TmbData$n_c ){
    Tmp = data.frame(
      "Year"=year_labels,
      "Unit"=1,
      "Fleet"=rep(strata_names,each=TmbData$n_t),
      "Estimate_metric_tons"=as.vector(Index_ctl[cI,,,'Estimate']),
      "SD_log"=as.vector(log_Index_ctl[cI,,,'Std. Error']),
      "SD_mt"=as.vector(Index_ctl[cI,,,'Std. Error'])
    )
    if (TmbData$n_c>1) {
      Tmp = cbind( "Category"=category_names[cI], Tmp)
    }
    Table = rbind( Table, Tmp )
  }
  if (!is.null(total_area_km2)) {
    Table = cbind(Table, "Naive_design-based_index"=Design_t)
  }
  write.csv( Table, file=paste0(DirName,"/Table_for_SS3.csv"), row.names=FALSE)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error in amend_output(fit = NULL) fit is missing
2 participants