6.5 Exceedance probabilities

Probabilities of RR (\(\theta_i\)) estimates being greater than a given threshold value (\(c\)).

\[P(\theta_i > c) = 1 - P(\theta_i \leq c) \]

# 1 - inla.pmarginal(q = c, marginal = marg)
res <- readRDS("data/res_chap6")
c = 2
marg <- res$marginals.fitted.values[[1]] # first county in DF
1 - inla.pmarginal(q = c, marginal = marg)
## [1] 0.9975785

We want it for every counties:

exc <- sapply(res$marginals.fitted.values,
FUN = function(marg){1 - inla.pmarginal(q = 2, marginal = marg)})

map$exc <- exc

Then we add it to our labels:

pal <- colorNumeric(palette = "YlOrRd", domain = map$exc)

labels <- sprintf("<strong> %s </strong> <br/>
  Observed: %s <br/> Expected: %s <br/>
  AFF: %s <br/> SIR: %s <br/> RR: %s (%s, %s) <br/> P(RR>2): %s",
  map$county, map$Y, round(map$E, 2),
  map$AFF, round(map$SIR, 2), round(map$RR, 2),
  round(map$LL, 2), round(map$UL, 2), round(map$exc, 2) ## <- here
) %>% lapply(htmltools::HTML)

lexc <- leaflet(map) %>%
  addTiles() %>%
  addPolygons(
    color = "grey", weight = 1, fillColor = ~ pal(exc),
    fillOpacity = 0.5,
    highlightOptions = highlightOptions(weight = 4),
    label = labels,
    labelOptions = labelOptions(
      style =
        list(
          "font-weight" = "normal",
          padding = "3px 8px"
        ),
      textsize = "15px", direction = "auto"
    )
  ) %>%
  # in lengend instead of RR
  addLegend(
    pal = pal, values = ~exc, opacity = 0.5, title = "P(RR>2)",
    position = "bottomright"
  )
lexc