knitr::opts_chunk$set(echo = FALSE)

library(dplyr)
library(DT)
library(flexdashboard)
library(ggplot2)
library(plotly)
library(shiny)
library(viridis)

load("app_data.RData")
source("helper_fxns.R")
#source("exposure.R")
#source("fatality.R")

prior <- curve(dgamma(x, shape = 11.81641,  
                      rate = 9.765625),
               from = 0.5,
               to = 3)

collision <- curve(dbeta(x, shape1 = 1.638029, shape2 = 290.0193), 
                   from = 0, 
                   to = 0.04)

act <- mean(Bay16$FLIGHT_MIN)/mean(Bay16$EFFORT)

scale <- glm(data = Bay16, (COLLISIONS/(FLIGHT_MIN/EFFORT))/0.002895415 ~ RISK_HA + I(RISK_HA^2))

Inputs {.sidebar}

The U.S. Fish and Wildlife Service uses a Bayesian model to estimate the number of eagles likely to be killed by proposed wind projects. This approach combines prior information about eagle collision and activity rates across existing wind farms, with surveys of eagle activity at proposed sites to estimate the likely number of fatalities.

This dashboard allows you to explore how priors interact with survey data to produce predicted eagle fatalities at a set of wind energy sites.

selectInput("sites", 
            "Choose a Site", 
            choices = c("", levels(Bay16$SITE)), 
            selected = "Combine Hills, Oregon")

cur_min <- reactive({Bay16$FLIGHT_MIN[Bay16$SITE == input$sites]})

cur_effort <- reactive({Bay16$EFFORT[Bay16$SITE == input$sites]})

cur_scale <- reactive({Bay16$SCALE[Bay16$SITE == input$sites]})

a <- reactive({11.81641 + cur_min()})
b <- reactive({9.765625 + cur_effort()})
actionButton("update", "Update Distributions")

r hr()

actionButton("calculate", "Calculate Fatalities")

r hr()

helpText("Note: Calcuating predicted fatality distributions takes time.  Please allow several seconds for the graph to load.")

Column {data-width = 500}

Prior Probabilities of Eagle Collision Rates

renderPlotly({
  plot_ly()%>%
  add_trace(x = ~collision$x, y = ~collision$y, type = "scatter", mode = "lines",
            fill = "tozeroy", name = "Prior", line = list(color = "grey"),
            text = ~paste("Prior probability of Collision Rate = ",
                          round(collision$x, 3),
                          "<br> is ",
                          round(collision$y, 3),
                          sep = ""),
            hoverinfo = "text")%>%
      layout(#title = "Prior Collision Rates",
             xaxis = list(title = "Collision Rate (per Exposure)",
                          range = 0, 0.01),
             yaxis = list(title = "Probability Density"))
})

#ggplot(Bay16, aes(x = EFFORT, y = OBS_MIN))+
#  geom_point()
#renderPlotly({
#ggplotly()
#})

Eagle Activity (Click 'Update Distributions')

observeEvent(input$update, {
  act <- isolate({cur_min()/cur_effort()})
  obs <- isolate({density(rgamma(10000, 
                                 shape = a(), 
                                 rate = b()
                                 )
                          )
    })

output$exposure <- renderPlotly({ 
    plot_ly()%>%
      add_trace(x = ~c(act, act), y = ~c(0,max(c(prior$y,obs$y))),
                type = "scatter", mode = "lines",
                name = "Observed", line = list(color = vir_col(3)[2]),
                text = ~paste("Observed Activity<br>at site = ",
                              round(act,2),
                              sep = ""),
                hoverinfo = "text")%>%
      add_trace(x = prior$x, y = prior$y,
                type = "scatter", mode = "lines", fill = "tozeroy",
                name = "Prior", line = list(color = vir_col(3)[1]),
                text = ~paste("Prior Activity<br>estimate = ",
                              round(prior$x, 2),
                              sep = ""),
                hoverinfo = "text")%>%
      add_trace(x = ~obs$x, y = ~obs$y,
                type = "scatter", mode = "lines", fill = "tozeroy",
                name = "Combined", line = list(color = vir_col(3)[3]),
                text = ~paste("Combined Activity<br>estimate = ",
                              round(obs$x, 2),
                              sep = ""),
                hoverinfo = "text")%>%
      layout(#title = "Eagle Exposure",
             xaxis = list(title = "Eagle Activity (min/km<sup>3</sup>*hr)",
                          range = c(0,3)),
             yaxis = list(title = "Probability Density"))
   })

})

plotlyOutput("exposure")

Activity is the number of minutes eagles are observed flying within survey areas, per hour.

Predicted Fatalities (Click 'Predict Fatalities')

observeEvent(input$calculate,{
  if(input$sites != ""){
    out <- isolate({prediction(10000, a(), b())})
    fatality <- isolate({density(out$fatality*cur_scale())})
    q80 <- isolate({quantile(out$fatality, c(0.1, 0.9))})

    out2 <- isolate({prediction(10000, a()-mean(Bay16$FLIGHT_MIN),
                                b()-mean(Bay16$EFFORT))})
    fatality2 <- isolate({density(out2$fatality*cur_scale())})
    q82 <- isolate({quantile(out2$fatality, c(0.1, 0.9))})

output$fatality <- renderPlotly({
        plot_ly()%>%
          add_trace(x = ~fatality$x, y = ~fatality$y, type = "scatter", mode = "lines",
                    fill = "tozeroy",
                    name = "Incl. Prior Exposure", line = list(color = vir_col(3)[3]),
                    text = ~paste("Predicted fatalities<br>incorporating prior = ",
                                  round(fatality$x, 2),
                                  sep = ""),
                    hoverinfo = "text")%>%
          add_trace(x = ~fatality2$x, y = ~fatality2$y, type = "scatter", 
                    mode = "lines",
                    fill = "tozeroy",
                    line = list(color = vir_col(3)[2]), 
                    name = "Using Site Survey Only",
                    text = ~paste("Predicted fatalities<br>from site survey = ",
                                  round(fatality2$x, 2),
                                  sep = ""),
                    hoverinfo = "text")%>%
          layout(##title = "Predicted Annual Eagle Fatalities",
                 xaxis = list(title = "Fatalities per Year",
                              range = c(0,20)),
                 yaxis = list(title = "Probability Density"),
                 legend = list(x = 0.7,
                               y = 1))
    })
  }
})
plotlyOutput('fatality')

Column {data-width=500}

Survey Data

tab <- select(Bay16, 
                    SITE, TURBINES, 
                    EFFORT, FLIGHT_MIN)
DT::renderDataTable({
dt <- DT::datatable(tab,
                    fillContainer = TRUE,
                    selection = list(mode = 'single', 
                                     selected = which(Bay16$SITE == input$sites), 
                                     target = 'row'),
                    colnames = c("Site", "Turbines", "Survey Effort (hr*km3)",
                                 "Eagle Obs (min)"),
                  options = list(rownames = FALSE,
                                 pageLength = nrow(tab),
                                 dom = 'tip'
                                 )
                )%>%
  formatRound("EFFORT", 2)
})

Data taken from Appendix S1 in Bay et al. (2016). The Journal of Wildlife Management 80(6): 1000-1010.



mjevans26/eaglesFWS documentation built on Dec. 29, 2021, 1:35 a.m.