---
title: "Risk Equivalence Dashboard"
format:
  html:
    code-fold: true
    code-summary: "Show code"
vignette: >
  %\VignetteIndexEntry{Risk Equivalence Dashboard}
  %\VignetteEngine{quarto::html}
  %\VignetteEncoding{UTF-8}
---

```{css, echo=FALSE}
/* Use 95% of viewport width */
.main-container { max-width: 95vw !important; }
body .container-fluid { max-width: 95vw; }
```

```{r setup, include=FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = ""
)

if (requireNamespace("micromort", quietly = TRUE)) {
  library(micromort)
} else {
  pkgload::load_all(quiet = TRUE)
}

library(targets)
library(DT)

# Shared safe_tar_read with RDS fallback (see inst/vignette_utils.R)
source(file.path(tryCatch(rprojroot::find_root(rprojroot::is_r_package),
  error = function(e) "."), "inst", "vignette_utils.R"))
```

Micromorts provide a **common currency** for comparing risks that otherwise seem incommensurable. How dangerous is a CT scan compared to a skydive? How many chest X-rays equal a long-haul flight?

This dashboard explores these questions using **atomic risk decomposition** --- breaking composite activities into their individual risk components so you can see exactly what you're exposed to, and what you can mitigate.

## Everyday Risk Budget {.tabset}

### Table

How risky are the mundane things we do every day?

```{r everyday-table}
#| echo: false
#| results: asis
show_target("vig_equiv_everyday")
```

### Chart

Everyday activities expressed in chest X-ray equivalents:

```{r everyday-chart, fig.width=8, fig.height=5}
#| fig-cap: "Everyday activities expressed in chest X-ray equivalents, showing that a long-haul flight equals ~50 chest X-rays while a banana is negligible."
#| fig-alt: "Horizontal bar chart comparing everyday activities to chest X-ray dose equivalents. Activities ordered from least to most radiation-equivalent, with blue bars."
#| echo: false
#| results: asis
show_target("vig_equiv_everyday_chart")
```


## Flight Risk Decomposition {.tabset}

Flying is a composite risk: crash + deep vein thrombosis (DVT) + cosmic radiation. The **atomic decomposition** reveals which components dominate at each duration, and which you can mitigate.

### By Duration

```{r flight-duration, fig.width=9, fig.height=5}
#| fig-cap: "Cleveland dotplot decomposing flight risk into crash, DVT, and cosmic radiation components across 2h, 5h, 8h, and 12h flights, ordered by total micromorts."
#| fig-alt: "Dotplot showing flight micromorts by duration and component. Each row is a flight duration ordered by total risk. Dots are coloured by component: crash, DVT, and cosmic radiation."
#| echo: false
#| results: asis
show_target("vig_equiv_flight_duration_chart")
```

Key observations:

- **Crash risk** is roughly constant per flight (~1 mm) regardless of duration --- dominated by takeoff and landing phases (~80% of fatal accidents per Boeing Statistical Summary) --- and is NOT hedgeable
- **DVT risk** is zero below 4 hours, then grows nonlinearly --- and IS hedgeable (compression socks reduce risk ~65%)
- **Cosmic radiation** is linear (~0.05 mm/hour) and NOT hedgeable
- For an 8-hour flight, DVT is the dominant hedgeable component

### By Health Status

How does DVT risk status change the total?

```{r flight-health}
#| echo: false
#| results: asis
show_target("vig_equiv_flight_components")
```

### Components

```{r flight-components}
#| echo: false
#| results: asis
show_target("vig_equiv_flight_duration_chart")
```


## Landmark Equivalences {.tabset}

### Surprise Table

```{r landmarks}
#| echo: false
#| results: asis
show_target("vig_equiv_landmarks")
```

### Interactive Explorer

Full risk equivalence table with every activity expressed relative to a chest X-ray:

```{r explorer}
#| echo: false
#| results: asis
show_target("vig_equiv_explorer")
```


## Medical Radiation {.tabset}

### Comparison Table

Medical imaging procedures vary enormously in radiation dose:

```{r medical-radiation}
#| echo: false
#| results: asis
show_target("vig_equiv_medical_focus")
```

### Exchange Chart

How many chest X-rays equal one CT scan?

```{r medical-exchange, fig.width=8, fig.height=4}
#| fig-cap: "Medical procedures ranked by chest X-ray equivalents, showing that a CT abdomen equals ~200 chest X-rays."
#| fig-alt: "Horizontal bar chart of medical radiation procedures in chest X-ray equivalents. Red bars show procedures from dental X-ray (lowest) to CT abdomen (highest, ~200 equivalents)."
#| echo: false
#| results: asis
show_target("vig_equiv_medical_exchange_chart")
```


## Hedgeability Analysis {.tabset}

### By Activity

Which activities have hedgeable risk components?

```{r hedgeable}
#| echo: false
#| results: asis
show_target("vig_equiv_hedgeable_summary")
```

### Stacked Components

Flight risk decomposition showing hedgeable vs non-hedgeable portions:

```{r hedgeable-plot, fig.width=9, fig.height=5}
#| fig-cap: "Flight risk decomposition by hedgeability: DVT risk (green, hedgeable via compression socks) vs crash and radiation (red, not hedgeable), ordered by total micromorts."
#| fig-alt: "Dotplot of flight micromorts by duration, coloured green for hedgeable components (DVT) and red for non-hedgeable (crash, cosmic radiation), ordered by total risk per flight duration."
#| echo: false
#| results: asis
show_target("vig_equiv_hedgeable_chart")
```


## Radiation Exposure Profiles {.tabset}

How does occupational radiation exposure compare across careers, and how do patient X-ray doses stack up? This section uses annual dose data from UNSCEAR and the LNT model (0.05 micromorts per mSv) to answer these questions.

### Occupational Comparison

Annual and cumulative radiation exposure across 11 profiles --- occupational, passenger, and environmental:

```{r radiation-profiles}
#| echo: false
#| results: asis
show_target("vig_radiation_profiles")
```

Key insight: A 40-year airline pilot career accumulates ~6 micromorts of radiation --- equivalent to just 60 chest X-rays.

### Patient vs Occupational

How many patient X-rays equal a career of occupational exposure?

```{r radiation-patient-vs-occ}
#| echo: false
#| results: asis
show_target("vig_radiation_patient_vs_occ")
```

Key insight: 100 lifetime chest X-rays (10 micromorts) exceeds a 40-year X-ray technician career (2 micromorts) by 5x.

### Timeline

Cumulative radiation exposure over a 40-year career:

```{r radiation-timeline, fig.width=9, fig.height=6}
#| fig-cap: "Cumulative radiation micromorts over a 40-year career for different exposure profiles, showing that 100 lifetime chest X-rays exceeds occupational exposure."
#| fig-alt: "Line chart of cumulative micromorts vs years of exposure. Multiple lines for different radiation scenarios (dental, X-ray tech, CT patient, annual cosmic). Lines diverge over time showing compounding differences."
#| echo: false
#| results: asis
show_target("vig_equiv_radiation_timeline_chart")
```

### Regulatory Context

How do actual doses compare to ICRP regulatory limits?

```{r radiation-regulatory}
#| echo: false
#| results: asis
show_target("vig_radiation_regulatory")
```

Key insight: Actual doses are typically 5-20x below regulatory limits.


## Cross-Activity Matrix

Exchange rates between 10 diverse activities. Read as: "one row-activity equals X column-activities."

```{r matrix}
#| echo: false
#| results: asis
show_target("vig_equiv_matrix")
```


## Methodology & Caveats

**Atomic vs composite risks.** The `atomic_risks()` function returns ONE row per risk component per activity. Activities not yet decomposed use `component = "all_causes"` (an honest placeholder indicating the breakdown is unknown).

**Conditional risks.** Some components depend on health profile (e.g., DVT risk varies by whether you have risk factors). The default profile assumes "healthy" values; use `common_risks(profile = list(health_profile = "dvt_risk_factors"))` for alternatives. Geographic conditioning can change equivalences dramatically: a snake bite is 0.5 mm in the US but 18.5 mm in rural Africa (37x). See the [Data Reliability](data_reliability.html) vignette for details.

**Duration bucketing.** Rather than encoding rate functions, flight risks are pre-computed at standard duration buckets (2h, 5h, 8h, 12h). Every number is directly citable --- no hidden formulas.

**DVT literature.** DVT risk below 4 hours is negligible. Above 4 hours, risk rises nonlinearly. Compression socks + hydration + movement reduce DVT risk by approximately 60--70%. Sources: Lancet Haematology, Cochrane Reviews.

**Medical radiation.** The "(radiation)" label indicates that the radiation dose IS the risk. For invasive procedures (e.g., coronary angiogram), procedural risks (infection, bleeding) are separate components not yet decomposed.

**Confidence levels.** Each component carries a confidence rating: "high" (published meta-analyses), "medium" (single studies or expert consensus), "low" (extrapolated), "estimated" (order-of-magnitude).

## Reproducibility

```{r risk_equivalence-session-info, eval=TRUE}
sessionInfo()
```

```{r build-info}
#| echo: false
#| results: asis
cat(safe_tar_read("vig_build_info") %||% "")
```
