Skip to content

Commit

Permalink
docs: add performance metric example, table of contents
Browse files Browse the repository at this point in the history
  • Loading branch information
k-doering-NOAA committed Sep 5, 2020
1 parent c9532c5 commit 553b626
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 11 deletions.
55 changes: 50 additions & 5 deletions README.Rmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
---
title: "README"
output: github_document
output:
github_document:
toc: true
toc_depth: 2
---

<!-- README.md is generated from README.Rmd. Please edit README.Rmd -->
Expand All @@ -27,11 +30,12 @@ master:

**************

## This is a repository for the Stock Assessment Tool: SSMSE
**This is a repository for the Stock Assessment Tool: SSMSE**

- Supported by the NOAA Fisheries Integrated Toolbox


## Disclaimer
**Disclaimer**

“The United States Department of Commerce (DOC) GitHub project code is provided on an ‘as is’ basis and the user assumes responsibility for its use. DOC has relinquished control of the information and no longer has responsibility to protect the integrity, confidentiality, or availability of the information. Any claims against the Department of Commerce stemming from the use of its GitHub project will be governed by all applicable Federal law. Any reference to specific commercial products, processes, or services by service mark, trademark, manufacturer, or otherwise, does not constitute or imply their endorsement, recommendation or favoring by the Department of Commerce. The Department of Commerce seal and logo, or the seal and logo of a DOC bureau, shall not be used in any manner to imply endorsement of any commercial product or activity by DOC or the United States Government.”

Expand Down Expand Up @@ -69,7 +73,7 @@ Still having trouble installing SSMSE? Please don't hesitate to open an [issue](

## An SSMSE example

Suppose we want to look at 2 scenarios, one where Steepness (H) is specified correctly and one where it is specified incorrectly in an estimation model (EM):
Suppose we want to look at how well we are able to achieve a specified management procedure under uncertainty in the operating model. We will look 2 scenarios, one where Steepness (H) is specified correctly and one where it is specified incorrectly in an estimation model (EM):

1. **H-ctl**: Cod operating model (H = 0.65) with correctly specified cod model EM (fixed H = 0.65)
2. **H-1**: Cod operating model (OM; H = 1) with misspecified cod model EM (fixed H = 0.65)
Expand Down Expand Up @@ -200,6 +204,10 @@ sample_struct_list <- list("H-ctl" = sample_struct, "H-1" = sample_struct)

Process error can be added through the recruitment deviations. In this case, `rec_dev_pattern = "rand"` in the call to `run_SSMSE` is used to use random recruitment deviations with the same standard deviation as the historical recruitment deviation pattern. Set `scope = 2` so that the same recruitment deviation patterns are used across scenarios, but different patterns are use across iterations in the same scenario.

### Performance metrics

Quantitative performance metrics should be specified before conducting an MSE. Typically, a suite of performance metrics will be examined; however, for simplicity in this example, we will only look at what the achieved relative biomass was for the last 3 years of projection in the MSE to determine how it compares to the intended management target of 40% of unfished Spawning Stock Biomass. Note that we are only running our MSE projectsion for 6 years, but longer projections are typical in MSE analyses.

### Run SSMSE

Now, use `run_SSMSE` to run the MSE analysis loop (note this will take some time to run, ~ 20 min):
Expand All @@ -226,7 +234,7 @@ run_SSMSE(scen_name_vec = c("H-ctl", "H-1"),# name of the scenario
```
Here, only 5 iterations are run per scenario; However, in a real MSE analysis, running 100+ iterations would be preferred, so that the full range of uncertainty (given observation and process errors) is visible in the results.

### Summarize results and view output
### Summarize results

The function `SSMSE_summary_all` can be used to summarize the model results in a list of dataframes.

Expand Down Expand Up @@ -268,6 +276,43 @@ ggplot2::ggplot(data = subset(summary$ts, model_run %in% c("cod_OM", "cod-1_OM",
ggplot2::theme_classic()
```

Now, calculate and plot the performance metric.
```{r plot_rel_SSB}
get_rel_SSB_avg <- function(summary, min_yr, max_yr) {
OM_vals <- unique(summary$ts$model_run)
OM_vals <- grep("_OM$", OM_vals, value = TRUE)
B_unfished <- summary$scalar %>%
filter(model_run %in% OM_vals) %>%
select(iteration, scenario,SSB_Unfished)
SSB_yr <- summary$ts %>%
filter(year >= min_yr & year <= max_yr) %>%
select(iteration, scenario, year, SpawnBio)
SSB_yr <- left_join(SSB_yr, B_unfished) %>%
mutate(Rel_SSB = SpawnBio/SSB_Unfished) %>%
group_by(iteration, scenario) %>%
summarize(avg_SSB = mean(Rel_SSB), .groups = "keep") %>%
ungroup()
SSB_yr
}
rel_SSB <- get_rel_SSB_avg(summary, min_yr = 104, max_yr = 106)
# function to summarize data in plot
data_summary <- function(x) {
m <- mean(x)
ymin <- m-sd(x)
ymax <- m+sd(x)
return(c(y=m,ymin=ymin,ymax=ymax))
}
ggplot(data = rel_SSB, aes(x = scenario, y = avg_SSB)) +
geom_hline(yintercept = 0.4, color = "gray") +
stat_summary(fun.data = data_summary,
position = position_dodge(width = 0.9), color = "blue") +
scale_y_continuous(limits = c(0, 0.8)) +
labs(title = "Long-term average relative SSB\n(years 101-106)",
x = "Scenario", y = "SSB/SSB_unfished") +
theme_classic()
```

If you wish to delete the files created from this example, you can use:
```{r, eval = FALSE}
unlink(run_SSMSE_dir, recursive = TRUE)
Expand Down
75 changes: 69 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
README
================

- [(SSMSE) Management Strategy Evaluation for Stock Synthesis
(SS)](#ssmse-management-strategy-evaluation-for-stock-synthesis-ss)
- [Installing the SSMSE R
package](#installing-the-ssmse-r-package)
- [Troubleshooting Installation](#troubleshooting-installation)
- [An SSMSE example](#an-ssmse-example)
- [How can I contribute to SSMSE?](#how-can-i-contribute-to-ssmse)
- [Roadmap: Where is SSMSE headed
next?](#roadmap-where-is-ssmse-headed-next)

<!-- README.md is generated from README.Rmd. Please edit README.Rmd -->

# (SSMSE) Management Strategy Evaluation for Stock Synthesis (SS)
Expand All @@ -17,11 +27,11 @@ status](https://ci.appveyor.com/api/projects/status/github/nmfs-fish-tools/SSMSE

-----

## This is a repository for the Stock Assessment Tool: SSMSE
**This is a repository for the Stock Assessment Tool: SSMSE**

- Supported by the NOAA Fisheries Integrated Toolbox

## Disclaimer
**Disclaimer**

“The United States Department of Commerce (DOC) GitHub project code is
provided on an ‘as is’ basis and the user assumes responsibility for its
Expand Down Expand Up @@ -90,9 +100,10 @@ Still having trouble installing SSMSE? Please don’t hesitate to open an

## An SSMSE example

Suppose we want to look at 2 scenarios, one where Steepness (H) is
specified correctly and one where it is specified incorrectly in an
estimation model (EM):
Suppose we want to look at how well we are able to achieve a specified
management procedure under uncertainty in the operating model. We will
look 2 scenarios, one where Steepness (H) is specified correctly and one
where it is specified incorrectly in an estimation model (EM):

1. **H-ctl**: Cod operating model (H = 0.65) with correctly specified
cod model EM (fixed H = 0.65)
Expand Down Expand Up @@ -338,6 +349,17 @@ the historical recruitment deviation pattern. Set `scope = 2` so that
the same recruitment deviation patterns are used across scenarios, but
different patterns are use across iterations in the same scenario.

### Performance metrics

Quantitative performance metrics should be specified before conducting
an MSE. Typically, a suite of performance metrics will be examined;
however, for simplicity in this example, we will only look at what the
achieved relative biomass was for the last 3 years of projection in the
MSE to determine how it compares to the intended management target of
40% of unfished Spawning Stock Biomass. Note that we are only running
our MSE projectsion for 6 years, but longer projections are typical in
MSE analyses.

### Run SSMSE

Now, use `run_SSMSE` to run the MSE analysis loop (note this will take
Expand Down Expand Up @@ -369,7 +391,7 @@ analysis, running 100+ iterations would be preferred, so that the full
range of uncertainty (given observation and process errors) is visible
in the results.

### Summarize results and view output
### Summarize results

The function `SSMSE_summary_all` can be used to summarize the model
results in a list of dataframes.
Expand Down Expand Up @@ -446,6 +468,47 @@ ggplot2::ggplot(data = subset(summary$ts, model_run %in% c("cod_OM", "cod-1_OM",

![](man/figures/README-plot_SSB-1.png)<!-- -->

Now, calculate and plot the performance metric.

``` r
get_rel_SSB_avg <- function(summary, min_yr, max_yr) {
OM_vals <- unique(summary$ts$model_run)
OM_vals <- grep("_OM$", OM_vals, value = TRUE)
B_unfished <- summary$scalar %>%
filter(model_run %in% OM_vals) %>%
select(iteration, scenario,SSB_Unfished)
SSB_yr <- summary$ts %>%
filter(year >= min_yr & year <= max_yr) %>%
select(iteration, scenario, year, SpawnBio)
SSB_yr <- left_join(SSB_yr, B_unfished) %>%
mutate(Rel_SSB = SpawnBio/SSB_Unfished) %>%
group_by(iteration, scenario) %>%
summarize(avg_SSB = mean(Rel_SSB), .groups = "keep") %>%
ungroup()
SSB_yr
}
rel_SSB <- get_rel_SSB_avg(summary, min_yr = 104, max_yr = 106)
## Joining, by = c("iteration", "scenario")

# function to summarize data in plot
data_summary <- function(x) {
m <- mean(x)
ymin <- m-sd(x)
ymax <- m+sd(x)
return(c(y=m,ymin=ymin,ymax=ymax))
}
ggplot(data = rel_SSB, aes(x = scenario, y = avg_SSB)) +
geom_hline(yintercept = 0.4, color = "gray") +
stat_summary(fun.data = data_summary,
position = position_dodge(width = 0.9), color = "blue") +
scale_y_continuous(limits = c(0, 0.8)) +
labs(title = "Long-term average relative SSB\n(years 101-106)",
x = "Scenario", y = "SSB/SSB_unfished") +
theme_classic()
```

![](man/figures/README-plot_rel_SSB-1.png)<!-- -->

If you wish to delete the files created from this example, you can use:

``` r
Expand Down
Binary file added man/figures/README-plot_rel_SSB-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 553b626

Please sign in to comment.