项目作者: danStich

项目描述 :
An R package for hosting data & code, and for running the Dam Impact Analysis (DIA) developed by Nieland et al. (2015)
高级语言: CSS
项目地址: git://github.com/danStich/dia.git
创建时间: 2021-07-06T22:02:17Z
项目社区:https://github.com/danStich/dia

开源协议:GNU General Public License v3.0

下载


dia

An R package for the National Oceanic and Atmospheric Administration dam impact analysis

DOI
License: GPL v3
DOI

Table of Contents

Overview

An R package for hosting code and data, and running the Atlantic salmon Dam Impact Analysis (DIA) model. This package was designed to provide a transparent, open-source version of the National Oceanic and Atmospheric Administration’s Dam Impact Analysis (DIA) model for Atlantic salmon (Salmo salar) in the Penobscot River, Maine, USA, that was previously hosted as an @RISK add on for Microsoft Excel. We created the package for use by fisheries scientists, managers, and decision makers as a transparent tool to support decision-making related to conservation of Atlantic salmon in this priority waterbody that hosts the majority of adult returns to the USA each year. It uses life-history data, flow-specific survival rates and other empirical estimates to simulate the response of Atlantic salmon in the Penobscot River over multiple generations to key conservation and restoration decisions such as supplemental fish stocking and passage through hydropower dams. A number of example uses are provided below that build in complexity.

The full details of the model parameterization, including background information about the Atlantic salmon life cycle and the Penobscot River, are available from Nieland et al. (2013), with a specific case study by Nieland et al. (2015) and updated biological data and a second case study in Nieland and Sheehan (2020). Below is a comparison of the original model parameterized by Nieland et al. (2013) and the core workflow of the dia package. Helper functions and built-in data sets are used to simulate a population through space in a single generation using the run_one_gen() function, which is then wrapped in the run_dia() function that facilitates stochastic simulation over a user-specified number of generations.

We are actively working to generalize the functions in the dia package and others to facilitate use for other efforts. While many of the data sets, population vital-rate simulation routines, and helper functions are relatively generalizable among populations or even to other species, the underlying production_units table and associated default straying_matrix for natal
homing are currently river-specific. For this reason, we welcome contributions that would help generalize the approach to creating structural river systems that underly population models in this package. You can learn more about contributing to this package in Contributing.md in this GitHub repository.



**Figure**: Graphical overview of the *dia* work flow (right) compared to the original Atlantic salmon *Salmo salar* lifecycle model presented by Nieland et al. (2013, 2015, 2020). Rounded rectangles are Atlantic salmon life stages, ovals are additions to population, and rectangles are subtractions from populations. Dashed rectangles indicate stochastic dynamics that are implemented within the model but that are neither additions nor subtractions. In the *dia* workflow, some noteable helper functions are shown in bold and have trailing parentheses (e.g., **`smolt_stocking()`**), built-in datasets are in bold with no trailing parentheses (e.g., **`life_stage_survival`**), and user-specified arguments to `run_dia()` are in plain font. You can learn more about these and other user-facing functions by running `help("dia")` after you've installed the package. The source code for `run_dia()` and all helper functions can be exposed by running, for example, `print(run_dia)` to further clarify workflows.

Installation

The development version of dia can be installed with devtools in R using the repository url:

devtools::install_github("danStich/dia")

To install dia, you will need to have devtools installed ahead of time in R, but that requires some special tools. To install on Windows, you will need to download and install the appropriate version of Rtools. To install on Mac, you will need to have the XCode command-line tools installed. And, if running from Linux, you will need to install the developer version of R (r-base-dev) if you have not already.

Directories

data/ Contains built-in data sets for the package

man/ help files and documentation

R/ R functions in scripts

inst/images includes images used in this README

inst/shiny-examples/dia_shiny includes server and ui files for run_dia_shiny(), a shiny-based user interface

tests/ Includes package tests for default parameter accuracy conducted on package build

Getting started

There are two primary user-facing functions within the dia package. The run_dia() function can be called within an Rscript to run the Dam Impact Analysis (DIA) model using default or user-defined inputs. The run_dia_shiny() function launches a graphical user interface (GUI) that opens in a web browser and is written with the shiny package. The former provides functionality for large-scale simulation studies in R whereas the latter provides an intuitive interface for running smaller numbers of management scenarios.

run_dia()

The run_dia() function provides the primary user-facing function for the dia package. The purpose of the function is to run the Dam Impact Analysis for some number of generations (15 by default). The output of this function is a dataframe (i.e., data table) containing number of wild and hatchery-origin adult returns in each generation. All default argument values (model inputs) are based on the most-recent version of the NOAA Dam Impact Analysis Excel-based model (v67, Nieland et al. 2013; Nieland et al. 2015; Nieland and Sheehan 2020).

The run_dia() function allows users to specify number of generations, number of starting wild and hatchery adults, whether stocking is turned on or off, how many fish are stocked in each production unit of the river, upstream and downstream dam passage rates, and other life-history or dam-related vital rates.

You can find the help file for the run_dia() function in R by running: ?dia::run_dia. This file contains all accepted user arguments, explanations of what they mean and what are default values, and examples of how to use
the run_dia() function. Examples are shown at the bottom of this page. You can browse a list of all helper functions called by run_dia() as well as all built-in datasets and their metadata by running help("dia") or ?dia.

run_dia_shiny()

The run_dia_shiny() function provides an intuitive user interface for running the DIA model. Though more limited in flexibility than run_dia(), the simplified interface should allow full exploration of management scenarios. The primary difference is that run_dia_shiny() does not allow the user to input custom distributions or values for some input parameters such as the straying_matrix or inefficiency_matrix implemented in the run_dia() function.

Currently, the shiny interface for the DIA model can only be called directly from R or Rstudio by running the following lines of code:

  1. library(dia)
  2. run_dia_shiny()

This will open the user-interface in a local instance of the default web browser on the computer where further instructions are provided.

Examples

We provide a range of examples for using the run_dia() function below to demonstrate flexibility in application for predicting population response to restoration scenarios or uncertainty and variability in biological parameters.

We build complexity from single-use cases, to small simulation studies, to large parallel computations that can be used to explore restoration scenarios or model uncertainties further by the users. To do this, we use the default model parameters for the first three examples to demonstrate a single realization, a small run of 100 iterations, and a larger simulation of hundreds or thousands of iterations in parallel. We then use the parallel framework, which we prefer for simulation studies, to demonstrate how the user can specify custom argument values to provide concrete applications of this tool to answer restoration questions.

Most of the arguments passed to run_dia() can accept custom user input, for a near infinite number of potential scenarios that could be assessed for a wide variety of questions. We have selected two common examples for demonstration: 1) simulating outcomes of hypothetical dam removals, and 2) testing sensitivity of restoration outcomes to biological uncertainty or variability.

Single simulation using default values

An example of a single simulation using run_dia() is demonstrated below, using the default values based on Nieland et al. (2013, 2015) and Nieland and Sheehan (2020). Each of these default values can be modified by the user, as we demonstrate in later examples. They each have default values and do not need to be explicitly specified unless changing the value, but all are shown here so we can see what they are.

The output is a dataframe with 1 observation of 2 sea-winter spawning females (abundance) reaching each production unit in the watershed in each generation, by rearing origin ('hatchery' or 'wild'). Graphically, we’ll need to run more simulations to summarize these results in a meaningful way. That is the objective of the next several examples.

  1. library(dia)
  2. # For reproducibility: comment out the next line if you wish to sample stochastically
  3. set.seed(7475)
  4. run_dia(
  5. n_generations = 15,
  6. n_wild = 31,
  7. n_hatchery = 306,
  8. stocking = 1,
  9. n_stocked = rep(545000, 15),
  10. upstream = list(
  11. medway = 0,
  12. mattaceunk = 0.9,
  13. west_enfield = 0.95,
  14. upper_dover = 0.92,
  15. browns_mills = 0.92,
  16. sebec = 0,
  17. milo = 0,
  18. howland = 0.95,
  19. lowel = 0.92,
  20. stillwater = 0,
  21. milford = 0.95,
  22. great_works = 1,
  23. orono = 0,
  24. veazie = 1,
  25. frankfort = 1),
  26. downstream = list(
  27. medway = 0,
  28. mattaceunk = 1,
  29. west_enfield = 0.96,
  30. upper_dover = 0.9215,
  31. browns_mills = NA,
  32. sebec = NA,
  33. milo = NA,
  34. howland = 1,
  35. lowell = NA,
  36. stillwater = 0.96,
  37. milford = 0.96,
  38. great_works = 1,
  39. orono = 0.96,
  40. veazie = 1,
  41. frankfort = NA),
  42. in_river_s = NA,
  43. mattaceunk_impoundment_mortality = 0.072,
  44. p_stillwater = NA,
  45. indirect_latent_mortality = 0.06,
  46. p_female = 0.6,
  47. new_or_old = "new",
  48. marine_s_hatchery = NA,
  49. marine_s_wild = NA,
  50. straying_matrix = NULL,
  51. p_mainstem_up = 1,
  52. n_broodstock = 150)

Multiple simulations using default values

An example of a single simulation using run_dia() is demonstrated below, using the default values based on Nieland et al. (2013, 2015) and Nieland and Sheehan (2020). This example demonstrates serial, looped execution using the foreach package, although we do not recommend this approach for large numbers of simulations (see subsequent examples about parallel execution for these). This example includes code for processing serial list output, summarizing results through tidy workflows using the tidyverse, and visualization of results with ggplot2 and related utilities.

  1. library(foreach)
  2. library(tidyverse)
  3. library(dia)
  4. # For reproducibility: comment out the next line if you wish to sample stochastically
  5. set.seed(7475)
  6. # Choose number of iterations
  7. n <- 100
  8. # Create a list holding model output
  9. outlist <- foreach(1:n) %do%
  10. run_dia(
  11. n_generations = 15,
  12. n_wild = 31,
  13. n_hatchery = 306,
  14. stocking = 1,
  15. n_stocked = rep(545000, 15),
  16. upstream = list(
  17. medway = 0,
  18. mattaceunk = 0.9,
  19. west_enfield = 0.95,
  20. upper_dover = 0.92,
  21. browns_mills = 0.92,
  22. sebec = 0,
  23. milo = 0,
  24. howland = 0.95,
  25. lowel = 0.92,
  26. stillwater = 0,
  27. milford = 0.95,
  28. great_works = 1,
  29. orono = 0,
  30. veazie = 1,
  31. frankfort = 1),
  32. downstream = list(
  33. medway = 0,
  34. mattaceunk = 1,
  35. west_enfield = 0.96,
  36. upper_dover = 0.9215,
  37. browns_mills = NA,
  38. sebec = NA,
  39. milo = NA,
  40. howland = 1,
  41. lowell = NA,
  42. stillwater = 0.96,
  43. milford = 0.96,
  44. great_works = 1,
  45. orono = 0.96,
  46. veazie = 1,
  47. frankfort = NA),
  48. in_river_s = NA,
  49. mattaceunk_impoundment_mortality = 0.072,
  50. p_stillwater = NA,
  51. indirect_latent_mortality = 0.06,
  52. p_female = 0.6,
  53. new_or_old = "new",
  54. marine_s_hatchery = NA,
  55. marine_s_wild = NA,
  56. straying_matrix = NULL,
  57. p_mainstem_up = 1,
  58. n_broodstock = 150
  59. )
  60. # Collect results into a single dataframe
  61. names(outlist) <- paste0("run_", seq(1, length(outlist)))
  62. out_df <- do.call(rbind, outlist)
  63. # Summarize results across number of runs
  64. plotter <- out_df %>%
  65. group_by(generation, origin, production_unit) %>%
  66. summarize(abund = median(abundance),
  67. lwr = quantile(abundance, 0.025),
  68. upr = quantile(abundance, 0.975)
  69. ) %>%
  70. group_by(generation, origin) %>%
  71. summarize(abundance = sum(abund),
  72. lwr = sum(lwr),
  73. upr = sum(upr)
  74. )
  75. # Plot results
  76. ggplot(plotter, aes(x = generation, y = abundance,
  77. color = origin, fill = origin)) +
  78. geom_line() +
  79. geom_ribbon(aes(x = generation, ymin = lwr, ymax = upr, color = NULL),
  80. alpha = 0.1)

Parallel execution of multiple simulations using default values

This example demonstrates execution of multiple simulations in parallel to make better use of local or remote compute clusters. We rely primarily on the snowfall package, but this approach is transferrable to any parallel back-end in R as far as we know. This example includes code for processing parallel output, summarizing results through tidy workflows using the tidyverse, and visualization of results with ggplot2 and related utilities.

  1. # Libraries ----
  2. library(tidyverse)
  3. library(snowfall)
  4. library(dia)
  5. library(data.table)
  6. # For reproducibility: comment out this line if you wish to sample stochastically
  7. set.seed(7475)
  8. # Parallel settings ----
  9. # Get number of nodes (cpu cores - 1) for the sfInit() function from snowfall
  10. ncpus <- parallel::detectCores() - 1
  11. # Initialize snowfall socket cluster to register the parallel back-end
  12. sfInit(parallel = TRUE, cpus = ncpus, type = "SOCK")
  13. # Define a wrapper function that will be deployed to parallel nodes ----
  14. sim <- function(x){
  15. # Run the dia function once per deployment on a parallel node
  16. # and save the result to an output object that can be returned
  17. # locally in a list of results from the parallel process
  18. output <- run_dia(n_generations = 15,
  19. n_wild = 31,
  20. n_hatchery = 306,
  21. stocking = 1,
  22. n_stocked = rep(545000, 15),
  23. upstream = list(
  24. medway = 0,
  25. mattaceunk = 0.90,
  26. west_enfield = 0.95,
  27. upper_dover = 0.92,
  28. browns_mills = 0.92,
  29. sebec = 0,
  30. milo = 0,
  31. howland = 0.95,
  32. lowel = 0.92,
  33. stillwater = 0,
  34. milford = 0.95,
  35. great_works = 1,
  36. orono = 0,
  37. veazie = 1,
  38. frankfort = 1),
  39. downstream = list(
  40. medway = 0,
  41. mattaceunk = 1,
  42. west_enfield = 0.96,
  43. upper_dover = 0.9215,
  44. browns_mills = NA,
  45. sebec = NA,
  46. milo = NA,
  47. howland = 1,
  48. lowell = NA,
  49. stillwater = 0.96,
  50. milford = 0.96,
  51. great_works = 1,
  52. orono = 0.96,
  53. veazie = 1,
  54. frankfort = NA),
  55. mattaceunk_impoundment_mortality = 0.072,
  56. p_stillwater = NA,
  57. indirect_latent_mortality = 0.06,
  58. p_female = 0.60,
  59. new_or_old = "new",
  60. marine_s_hatchery = NA,
  61. marine_s_wild = NA,
  62. straying_matrix = NULL,
  63. p_mainstem_up = 1,
  64. n_broodstock = 150
  65. )
  66. # Save the output from the call to run_dia() to an element in an
  67. # output list that can be returned locally
  68. out_list <- list(
  69. output = output)
  70. return(out_list)
  71. }
  72. # Parallel execution ----
  73. # . Load libraries on nodes using sfLibrary() from the snowfall package -----
  74. sfLibrary(dia)
  75. # . Distribute to workers -----
  76. # Number of simulations to run
  77. niterations <- 5e3
  78. # . Run the simulation ----
  79. # Record start time for benchmarking
  80. start <- Sys.time()
  81. # Run simulation and return results using the sfLapply() function
  82. # from the snowfall package
  83. result <- sfLapply(1:niterations, sim)
  84. # Calculate total time elapsed for benchmarking
  85. total_time <- Sys.time()-start
  86. total_time
  87. # Result processing ----
  88. # Extract results dataframes by string and rbind all list elements
  89. res <- lapply(result, function(x) x[[c('output')]])
  90. out_df <- data.frame(data.table::rbindlist(res))
  91. # Result summary ----
  92. # Summarize results across replicate stochastic model realizations
  93. plotter <- out_df %>%
  94. group_by(generation, origin, production_unit) %>%
  95. summarize(abund = median(abundance),
  96. lwr = quantile(abundance, 0.025),
  97. upr = quantile(abundance, 0.975)) %>%
  98. group_by(generation, origin) %>%
  99. summarize(abundance = sum(abund),
  100. lwr = sum(lwr),
  101. upr = sum(upr))
  102. # Plot results
  103. ggplot(plotter, aes(x = generation, y = abundance,
  104. color = origin, fill = origin)) +
  105. geom_line() +
  106. geom_ribbon(aes(x = generation, ymin = lwr, ymax = upr, color = NULL),
  107. alpha = 0.1)

Simulating population response to dam removals

This example demonstrates how to simulate, for example, the removal of several dams as part of a hypothetical dam removal fabricated for the sake of demonstration. We use the parallel approach to stochastic sampling demonstrated above to simulate new population abundances when four dams are removed from the Piscataquis River (Upper Dover, Browns Mills, Sebec, Milo, and Howland dams). To do this, we can simply set their list elements in upstream and downstream to 1, indicating that the dams present no impediment to migration. We demonstrate how the parallel simulation outputs can be processed through convenient, tidy workflows using the tidyverse and visualized with ggplot2.

  1. # Example of parallel execution for assessing dam removals ----
  2. # . Libraries ----
  3. library(tidyverse)
  4. library(snowfall)
  5. library(dia)
  6. library(data.table)
  7. # For reproducibility: uncomment the line below to sample stochastically
  8. set.seed(7475)
  9. # . Parallel settings ----
  10. # Get number of nodes (cpu cores - 1)
  11. ncpus <- parallel::detectCores() - 1
  12. # Initialize snowfall socket cluster
  13. sfInit(parallel = TRUE, cpus = ncpus, type = "SOCK")
  14. # . Wrapper function for worker nodes ----
  15. sim <- function(x){
  16. # Replace upstream and downstream passage rates
  17. # with "1" to indicate removal of dam. In this example,
  18. # we'll assess influence of removing all dams in the
  19. # Piscataquis River (upper_dover, browns_mills, sebec, milo,
  20. # and howland).
  21. output <- run_dia(n_generations = 15,
  22. n_wild = 31,
  23. n_hatchery = 306,
  24. stocking = 1,
  25. n_stocked = rep(545000, 15),
  26. upstream = list(
  27. medway = 0,
  28. mattaceunk = 0.90,
  29. west_enfield = 0.95,
  30. upper_dover = 1,
  31. browns_mills = 1,
  32. sebec = 1,
  33. milo = 1,
  34. howland = 1,
  35. lowel = 0.92,
  36. stillwater = 0,
  37. milford = 0.95,
  38. great_works = 1,
  39. orono = 0,
  40. veazie = 1,
  41. frankfort = 1),
  42. downstream = list(
  43. medway = 0,
  44. mattaceunk = 1,
  45. west_enfield = 0.96,
  46. upper_dover = 1,
  47. browns_mills = 1,
  48. sebec = 1,
  49. milo = 1,
  50. howland = 1,
  51. lowell = NA,
  52. stillwater = 0.96,
  53. milford = 0.96,
  54. great_works = 1,
  55. orono = 0.96,
  56. veazie = 1,
  57. frankfort = NA),
  58. mattaceunk_impoundment_mortality = 0.072,
  59. p_stillwater = NA,
  60. indirect_latent_mortality = 0.06,
  61. p_female = 0.60,
  62. new_or_old = "new",
  63. marine_s_hatchery = NA,
  64. marine_s_wild = NA,
  65. straying_matrix = NULL,
  66. p_mainstem_up = 1,
  67. n_broodstock = 150)
  68. out_list <- list(
  69. output = output)
  70. return(out_list)
  71. }
  72. # . Parallel execution ----
  73. # .. Load libraries on workers -----
  74. sfLibrary(dia)
  75. # .. Distribute to workers -----
  76. # Number of simulations to run
  77. niterations <- 1e4
  78. # .. Run the simulation ----
  79. # Record start time
  80. start <- Sys.time()
  81. # Run simulation and return results
  82. result <- sfLapply(1:niterations, sim)
  83. # Calculate total time elapsed for benchmarking
  84. total_time <- Sys.time()-start
  85. total_time
  86. # . Result processing ----
  87. # Extract results dataframes by string and rbind all list elements
  88. res <- lapply(result, function(x) x[[c('output')]])
  89. out_df <- data.frame(data.table::rbindlist(res))
  90. # . Result summary ----
  91. # .. By generation ----
  92. # Summarize results across replicate stochastic model realizations
  93. plotter <- out_df %>%
  94. group_by(generation, origin, production_unit) %>%
  95. summarize(abund = median(abundance),
  96. lwr = quantile(abundance, 0.025),
  97. upr = quantile(abundance, 0.975)) %>%
  98. group_by(generation, origin) %>%
  99. summarize(abundance = sum(abund),
  100. lwr = sum(lwr),
  101. upr = sum(upr)) %>%
  102. mutate(origin = str_to_sentence(origin))
  103. # Plot results by generation
  104. generations <- ggplot(plotter, aes(x = generation, y = abundance,
  105. color = origin, fill = origin)) +
  106. geom_line() +
  107. geom_ribbon(aes(x = generation, ymin = lwr, ymax = upr, color = NULL),
  108. alpha = 0.25) +
  109. xlab("Generation number") +
  110. ylab("Abundance") +
  111. labs(color = "Origin", fill = "Origin") +
  112. annotate("text", x = 1, y = 3500, label = "(a)")
  113. # .. By production unit ----
  114. # Summarize results across replicate stochastic model realizations
  115. plotter <- out_df %>%
  116. filter(generation == 15) %>%
  117. mutate(production_unit = substr(production_unit, 4, 5)) %>%
  118. mutate(origin = str_to_sentence(origin))
  119. # Plot results by generation
  120. pus <- ggplot(plotter, aes(x = production_unit, y = abundance,
  121. color = origin, fill = origin)) +
  122. geom_boxplot(alpha = 0.25) +
  123. xlab("Production unit") +
  124. ylab("Abundance") +
  125. labs(color = "Origin", fill = "Origin") +
  126. annotate("text", x = 1, y = 5000, label = "(b)")
  127. gridExtra::grid.arrange(generations, pus)

Assess sensitivity of restoration outcomes to uncertainty or variability

This example demonstrates how to simulate population sensitivity to underlying model parameters using the parallel approach to stochastic sampling demonstrated above. In this example, we run the model under a wide range of marine survival rates for wild fish to investigate how uncertainty or variability in this parameter could influence predicted outcomes of restoration efforts. We continue to demonstrate how to summarize simulation outputs using tidy workflows from the tidyverse and visualization with ggplot2. We recommend copying the code below into an editor such as RStudio to view syntax highlighting and make use of code-folding tabs.

  1. # Example of parallel execution for assessing marine survival ----
  2. # . Libraries ----
  3. library(tidyverse)
  4. library(snowfall)
  5. library(dia)
  6. library(data.table)
  7. # For reproducibility: uncomment the line below to sample stochastically
  8. set.seed(7475)
  9. # . Parallel settings ----
  10. # Get number of nodes (cpu cores - 1)
  11. ncpus <- parallel::detectCores() - 1
  12. # Initialize snowfall socket cluster
  13. sfInit(parallel = TRUE, cpus = ncpus, type = "SOCK")
  14. # . Wrapper function for worker nodes ----
  15. sim <- function(x){
  16. # Here, we use the default values for everything except marine survival
  17. # of wild fish and then plot the results to determine sensitivity of
  18. # species recovery to changes in marine survival.
  19. # Simulate marine survival from a truncated normal distribution
  20. # using the make_marine_s() function from the dia package
  21. # like this (uncomment to run).
  22. # marine_s_wild <- dia::make_marine_s(n = 1, a = 0, b = 0.25,
  23. # hatchery = FALSE)
  24. # Alternatively, we could just specify a sample from a range of values:
  25. marine_s_wild <- sample( seq(0, 0.025, 0.001), 1, replace = TRUE)
  26. output <- run_dia(marine_s_wild = marine_s_wild)
  27. output$marine_s_wild <- marine_s_wild
  28. out_list <- list(
  29. output = output)
  30. return(out_list)
  31. }
  32. # . Parallel execution ----
  33. # .. Load libraries on workers -----
  34. sfLibrary(dia)
  35. # .. Distribute to workers -----
  36. # Number of simulations to run
  37. niterations <- 1e3
  38. # .. Run the simulation ----
  39. # Record start time
  40. start <- Sys.time()
  41. # Run simulation and return results
  42. result <- sfLapply(1:niterations, sim)
  43. # Calculate total time elapsed for benchmarking
  44. total_time <- Sys.time()-start
  45. total_time
  46. # . Result processing ----
  47. # Extract results dataframes by string and rbind all list elements
  48. res <- lapply(result, function(x) x[[c('output')]])
  49. out_df <- data.frame(data.table::rbindlist(res))
  50. # . Result summary ----
  51. # .. Sensitivity to marine s ----
  52. # Summarize results across replicate stochastic model realizations
  53. # to examine variability in abundance in generation 15 compared to
  54. # variability in marine survival
  55. plotter <- out_df %>%
  56. filter(generation == 15) %>%
  57. mutate(marine_s_wild = round(marine_s_wild, 3)) %>%
  58. group_by(production_unit, origin, marine_s_wild) %>%
  59. summarize(abund = median(abundance),
  60. lwr = quantile(abundance, 0.025),
  61. upr = quantile(abundance, 0.975)) %>%
  62. group_by(origin, marine_s_wild) %>%
  63. summarize(abundance = sum(abund),
  64. lwr = sum(lwr),
  65. upr = sum(upr)) %>%
  66. mutate(origin = str_to_sentence(origin))
  67. # Plot results by generation
  68. ggplot(plotter, aes(x = marine_s_wild,
  69. y = abundance,
  70. color = origin,
  71. fill = origin)) +
  72. geom_line() +
  73. geom_ribbon(aes(xmax = marine_s_wild, ymin = lwr, ymax = upr, color = NULL),
  74. alpha = 0.50) +
  75. xlab("Generation number") +
  76. ylab("Abundance") +
  77. labs(color = "Origin", fill = "Origin")

References

Nieland JL, Sheehan TF. 2020. Quantifying the Effects of Dams on Atlantic Salmon in the Penobscot River Watershed, with a Focus on Weldon Dam. US Department of Commerce, Northeast Fisheries Science Center Reference Document 19-16, Woods Hole, MA. URL: https://repository.library.noaa.gov/view/noaa/23714.

Nieland JL, Sheehan TF, Saunders R. 2015. Assessing demographic effects of dams on diadromous fish: a case study for Atlantic salmon in the Penobscot River, Maine. ICES Journal of Marine Science 72:2423–2437. URL: https://academic.oup.com/icesjms/article/72/8/2423/2458708.

Nieland JL, Sheehan TF, Saunders R, Murphy JS, Trinko Lake TR, Stevens JR. 2013. Dam Impact Analysis model for Atlantic salmon in the Penobscot River, Maine. US Department of Commerce, Northeast Fisheries Science Center Reference Document 13-09, Woods Hole, MA. URL: https://repository.library.noaa.gov/view/noaa/4559.