class: right, middle, my-title, title-slide # Conceptual Modeling with R ## An R Markdown Project Example
September 24, 2020 ### Geret DePiper, Sarah Gaichas, Brandon Muffley
Summer Flounder Conceptual Modeling Team --- class: top, left # Mid-Atlantic Fishery Management Council Request: <br /> <br /> <br /> ## [A conceptual model for summer flounder fishery-ecosystem interactions, inventory of data availability and gaps, applicable models, and example management questions which could be addressed with this knowledge base.](https://gdepiper.github.io/Summer_Flounder_Conceptual_Models/sfconsmod_riskfactors_subplots.html) Transition from risk assessment to Management Strategy Evaluation Credit where credit is due: Sarah Gaichas at NEFSC developed most of the R Markdown code & made the conceptual model interactive ??? --- # Orientiation ## What this talk will do: - Walk through decision points which facilitated use of R & R Markdown ## What this talk won't do: - Review every line of code used to develop the HTML file + That code can be found here: <br /> https://github.com/gdepiper/Summer_Flounder_Conceptual_Models.git - Serve solely as an introduction to R Markdown + Better resources available + e.g. https://rmarkdown.rstudio.com/lesson-1.html ## The hope is to present the utility of collaborating in R, particularly for projects with ill-defined needs and products, necessitating substantial collaboration, or with recurring production needs. ??? --- # First thing first...what is R Markdown? .pull-left[R port of Markdown language - Plain text HTML editor with added functionality + Extended to generate PDF & Word documents + Some LaTeX, BibTeX, & Beamer functionality + Code can be executed directly in the markdown file] .pull-right[ ```r n=1000 y=rnorm(n) #Drawing 1,000 random observations ~ N(0,1) y_density <- density(y) plot(y_density,main="Integrating code is extremely useful!") ``` <img src="index/figure-html/RMarkdownfig-1.png" style="display: block; margin: auto;" /> ] ??? --- # Our team was asked specifically for a conceptual model .pull-left[Many software available - [Used Dia](http://dia-installer.de/) + Free + Fast + Can easily import adjacency matrix into R using the [Qpress Package](https://github.com/SWotherspoon/QPress) + Increases functionality immensely + Need [devtools package](https://cran.r-project.org/web/packages/devtools/index.html) ] .pull-right[ ![Dia software gui interface image.](RWorkshopImages/Dia.png) .image-cap[Dia software user interface. ] ] ??? --- # Model linkages quickly became hard to trace .pull-left[Work Group decided a few steps would facilitate communication - Fix 1: Sub-models to focus on key relationships + Based on pre-determined focal components + Function pulls relevant linkages only] .pull-right[ ![Code chunk that subsets data.](RWorkshopImages/Submodel_code_chunk.png) .image-cap[Submodel function easily creates subsets of data for submodel rendering. ] ] ??? --- # Model linkages quickly became hard to trace .pull-left[Work Group decided a few steps would facilitate communication - Fix 2: Interactive model + [chorddiag package](https://github.com/mattflor/chorddiag) + Need [devtools package](https://cran.r-project.org/web/packages/devtools/index.html) + More easily trace linkages + Added benefit: reproducible in html slides! ] .pull-right[ ![Full conceptual model with discards highlighted](RWorkshopImages/discards.png) .image-cap[Static conceptual model image. ] ] ??? ---
??? In this interactive circular graph visualization, model elements identified as important by the Council (through risk assessment) and by the working group (through a range of experience and expertise) are at the perimeter of the circle. Elements are defined in detail in the last section of [this page](https://gdepiper.github.io/Summer_Flounder_Conceptual_Models/sfconsmod_riskfactors_subplots.html). Relationships between elements are represented as links across the center of the circle to other elements on the perimeter. Links from a model element that affect another element start wide at the base and are color coded to match the category of the element they affect.Hover over a perimeter section (an element) to see all relationships for that element, including links from other elements. Hover over a link to see what it connects. Links by default show text for the two elements and the direction of the relationship (1 for relationship, 0 for no relationship--most links are one direction).For example, hovering over the element "Total Landings" in the full model shows that the working group identified the elements affected by landings as Seafood Production, Recreational Value, and Commercial Profits (three links leading out from landings), and the elements affecting landings as Fluke SSB, Fluke Distributional Shift, Risk Buffering, Management Control, Total Discards, and Shoreside Support (6 links leading into Total Landings). ??? --- ## Our team was asked specifically for a gap analysis ## Documentation is also key to scientific method - Transparency & Reproducibility + Each link documented #### Allocation <table class="table table-striped table-hover table-condensed" style="margin-left: auto; margin-right: auto;"> <thead> <tr> <th style="text-align:left;"> Model Element </th> <th style="text-align:left;"> Justification for Inclusion </th> <th style="text-align:left;"> Data to support (Y/N/M) </th> <th style="text-align:left;"> Data - if yes, identify and list out all data sources (including temporal resolution and series length), analyses, model, Council project etc. </th> <th style="text-align:left;"> Spatial Component (North/South; Inshore/Offshore; Other - specify) </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> Biomass distributional shifts (North/South) and Fluke SSB </td> <td style="text-align:left;"> Many of the current allocation discussions have focused on reallocation scenarios that are being driven, in part, due to distribution shifts or range expansion of biomass. As the summer flounder biomass changes over time due to climate and/or stock rebuilding, consideration of biomass distribution in any allocation scheme will be needed. Current commercial summer flounder amendment considered, although not selected, stock distribution changes for potential reallocation schemes. </td> <td style="text-align:left;"> Y </td> <td style="text-align:left;"> NEFSC trawl survey and other state and multistate (i.e., NEAMAP) survey information; commercial ammendment DEIS; 2018 benchmark stock assessment </td> <td style="text-align:left;"> North/South </td> </tr> <tr> <td style="text-align:left;"> Fishery distributional shift (Inshore/offshore and north/south) </td> <td style="text-align:left;"> Center of commercial fishery effort/landings - coastwide and within many states - has shifted north and east. In 1990's off southern Delmarva and now off northern NJ. Potential changes and shifts between small and large boat operations. Differences in the recreational fishery inshore vs offshore access. Timing of when fish arrive and size differences of fish inshore vs offshore. States establishing shore-based programs with smaller size limits to increase access. </td> <td style="text-align:left;"> Y </td> <td style="text-align:left;"> Commercial VTRs (harvest/effort locations; vessel size); Social Sciences Branch Fishing Footprint maps; MRIP information; annual staff recreational memos; publications (e.g. Pinsky et. al. 2017; Dubik et. al. 2018) </td> <td style="text-align:left;"> North/South and Inshore/Offshore </td> </tr> <tr> <td style="text-align:left;"> Data quality/availability </td> <td style="text-align:left;"> Types of data sources and quality of information available will play a role in determining an allocation and ability to make future changes. Are the data representative of stock availability. Consider data sources outside of com/rec/sector area (e.g., census data, social/economic factors). </td> <td style="text-align:left;"> Y </td> <td style="text-align:left;"> Commercial and recreational landings information with associated uncertainty. Other data sources - census information, boat registration, shoreside support businesses </td> <td style="text-align:left;"> NA </td> </tr> <tr> <td style="text-align:left;"> Management control </td> <td style="text-align:left;"> The summer flounder FMP specifies the sector specific and the recreational and commercial state-by-state allocations. The Council and Board recently made adjustments to the commercial allocation depending upon the total commercial quota. Future adjustments to any allocation scheme are under the purview of management and, therefore, directly affects allocation outcomes. </td> <td style="text-align:left;"> Y </td> <td style="text-align:left;"> Summer flounder FMP; recent EIS on the commercial summer flounder amendment; recently initiated sector allocation amendment; see data sources identified under other allocation elements (below) </td> <td style="text-align:left;"> NA </td> </tr> <tr> <td style="text-align:left;"> Recreational/commercial allocation </td> <td style="text-align:left;"> 60% commercial, 40% recreational allocation split part of FMP and based on landings from 1980-1989. Is this split optimal/accurate, especially with new MRIP estimates. Potential sector allocation considerations. </td> <td style="text-align:left;"> Y </td> <td style="text-align:left;"> Council funded allocation review project (Hicks & Schnier); MRIP data and commercial landings. Historical allocation across sectors/states are available at http://www.mafmc.org/sf-s-bsb. Recreatinal/commercial. </td> <td style="text-align:left;"> NA </td> </tr> <tr> <td style="text-align:left;"> State-level allocation </td> <td style="text-align:left;"> Both commercial (1980-1989) and recreational (1998; no longer used as explicit allocation target) state-by-state allocations are part of the Council and ASMFC FMP and perceived to be outdated and not reflective of history or current situation. Potential sector allocation considerations. Consideration and identification of shoreside businesses. </td> <td style="text-align:left;"> Y </td> <td style="text-align:left;"> Commercial landings data and VTR information; MRIP data; commercial amendment EIS document; fishery independent data (NEFSC trawl survey, NEAMAP and other state surveys); NEFSC community vulnerability index </td> <td style="text-align:left;"> North/South and Inshore/Offshore </td> </tr> </tbody> </table> ??? --- ## Our team was asked specifically for a gap analysis ## Documentation is also key to scientific method .pull-left[Google Sheets used to develop documentation - Facilitates collaborative development - Can easily import Google Sheets into R using the [googledrive](https://googledrive.tidyverse.org/) package + Change Google Sheet, then automatically propogates + Authorize by typing drive_find(n_max=30) into command line after package installation ] .pull-right[ ![Code chunk that reads in google sheet information data.](RWorkshopImages/googlesheetcode.png) .image-cap[Code pulling Google Sheet into memory, savig it as an Excel file, and then creating HTML table from the Excel file. ] ] ??? --- ## After preliminary presentation to the Council, a list of definitions was requested [DT Package](https://rstudio.github.io/DT/)
??? --- # Collaboration facilitated through GitHub [GitHub is integrated into RStudio](https://happygitwithr.com/rstudio-git-github.html) - Allows version control + Everyone works off of the same version of the code + Including all files needed to create products + Ensures the code can always be reverted to a point at which it worked - GitHub will also host your web pages for free! + [GitHub Pages](https://pages.github.com/) + Code pushed to site, and with some file folder housekeeping, HTML is rendered + Near-real time product updating + Warning: Not intuitive for those unfamiliar with HTML ??? --- # Ease of customization for alternate needs [Presentation of the results of the work group to the MAFMC used different visual representation of the conceptual model](https://gdepiper.github.io/Summer_Flounder_Conceptual_Models/sfconsmod_final_2col.html) Allowed work group to walk through top 3 questions with visual representation to discuss relevant ecosystem linkages. FYI - the Council chose question 3 to develop a Management Strategy Evaluation around. Work is currently underway. ??? --- ## Added benefits of using R and R Markdown .pull-left[Seamless integration of analysis and final products + Great for reports, etc. which need to be updated regularly + Offshore Wind in the Northeast Atlantic LME + Currently 27 lease areas + Frequent requests for information + Standardized & Automated (Dynamic) reporting for Impact Analysis + Alternative text for 508 compliance (HTML) ] .pull-right[ ![Bar graph of revenue generated by top 5 FMPs historically fished in Fairways North Wind Energy Area between 2012 - 2016, by year, and summary table for total revenue by FMP across those five years.](RWorkshopImages/OffshoreWind.png) ] ??? --- # In Conclusion... R and R Markdown are great resources, particularly for: - Recurring reporting needs - Collaboration - Projects with undefined products However, there's still value in other software/languages ??? --- # Questions? Thank you! * [Mid-Atlantic Council Summer Flounder conceptual model, support tables](https://gdepiper.github.io/Summer_Flounder_Conceptual_Models/sfconsmod_riskfactors_subplots.html) * [Management questions and conceptual model](https://gdepiper.github.io/Summer_Flounder_Conceptual_Models/sfconsmod_final_2col.html) * Slides available at https://gdepiper.github.io/RWorkshopSocialsci_GD/ .pull-left[ Contacts: ] .pull-right[ geret.depiper@noaa.gov sarah.gaichas@noaa.gov bmuffley@mafmc.org ]