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)
<- readRDS("data/res_chap6")
res = 2
c <- res$marginals.fitted.values[[1]] # first county in DF
marg 1 - inla.pmarginal(q = c, marginal = marg)
## [1] 0.9975785
We want it for every counties:
<- sapply(res$marginals.fitted.values,
exc FUN = function(marg){1 - inla.pmarginal(q = 2, marginal = marg)})
$exc <- exc map
Then we add it to our labels:
<- colorNumeric(palette = "YlOrRd", domain = map$exc)
pal
<- sprintf("<strong> %s </strong> <br/>
labels Observed: %s <br/> Expected: %s <br/>
AFF: %s <br/> SIR: %s <br/> RR: %s (%s, %s) <br/> P(RR>2): %s",
$county, map$Y, round(map$E, 2),
map$AFF, round(map$SIR, 2), round(map$RR, 2),
mapround(map$LL, 2), round(map$UL, 2), round(map$exc, 2) ## <- here
%>% lapply(htmltools::HTML)
)
<- leaflet(map) %>%
lexc 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