How maisiedaisie/toronto-shelter-opioid-risk works
This repository is a reproducible R-based geospatial analysis pipeline, not an application server. Its purpose is to estimate how many suspected opioid-poisoning events in Toronto occur near shelter sites, then convert those raw proximity counts into population-adjusted risk measures.
The main inputs are public CSV datasets in data-files/:
• TPaS suspected overdose events linked to intersections and neighbourhoods for 2025
• Toronto Shelter & Support Services shelter site locations
• 2021 census tract populations for Toronto
The code assumes additional external datasets may be downloaded separately, as described in the setup docs. That creates a clear boundary between bundled inputs and user-supplied source files.
The repository is organized as a staged R workflow in R-code/. The scripts are intended to run in order:
1. 01-data-environment.R loads packages, establishes the R environment, and transforms raw CSVs into analysis-ready spatial data.
2. 02-data-validation.R checks that those derived dataframes/objects were created correctly and fails loudly if something is missing or malformed.
3. 03-simple-analysis.R performs the core proximity count analysis, tallying overdose events within 200 m and 500 m buffers around each shelter.
4. 04-data-analysis.R performs the more advanced statistical layer, using census population data to derive standardized incidence ratio / risk ratio style estimates.
run-simple-analysis.R is a convenience entry point for the simpler workflow, while the markdown files in information-and-notes/ provide the operational boundary for users: QUICKSTART.md for a lightweight reproducible path, FULLSETUP.md for the full analysis, and DATANOTES.md for provenance and limitations.
The dependency boundary is explicit: renv.lock pins the R package versions needed to reproduce the analysis. The README also states R 3.5.4 as the expected runtime, which matters for compatibility of the spatial/statistical packages used.
The primary data flow is:
raw public health / shelter / census inputs -> R environment setup -> spatial transformation and validation -> buffer-based event counting -> population-adjusted risk estimation -> tabular outputs written to the working directory.
The dominant analytical concept is spatial proximity. Shelter locations act as anchor points, and overdose events are counted within fixed-radius catchments. The census tract population file supplies the denominator for adjusted risk calculations, so the pipeline crosses from simple location counting into epidemiologic comparison.
The repository’s outputs are analytical artifacts, not interactive services: ranked shelter-level event counts, risk estimates, and associated uncertainty/statistical summaries. The README also references mapping and spatial statistics such as Moran’s I and kernel density as part of the broader analysis scope.
A useful architecture diagram would show three layers:
• source data and external downloads
• sequential R processing/validation/statistical scripts
• generated CSV outputs and downstream figures/reports
The key implementation boundary is that each stage depends on the previous one, so the scripts are intentionally linear rather than independent. This is reinforced in the README’s warning not to mix the quickstart and full-setup workflows, since they would duplicate steps and potentially corrupt the working state.
Main entry points: 01-data-environment.R Environment setup · 03-simple-analysis.R Simple analysis · 04-data-analysis.R Advanced analysis · 02-data-validation.R Data validation
Components 18
Source data
Bundled CSV inputs plus separately downloaded source files used by the analysis.
- Overdose events · Toronto suspected opioid-poisoning events linked to intersections.
data-files/toronto-ems-calls-suspected-overdose-2025-by-intersection.csv - Neighbourhood events · Suspected overdose events aggregated by neighbourhood.
data-files/tpas-suspected-overdose-2025-by-neighbourhood.csv - Shelter sites · Toronto shelter and support services site locations used as spatial anchors.
data-files/toronto-shelter-sites-apr26.csv - Census populations · 2021 Toronto census tract populations used as denominators for adjusted risk estimates.
data-files/toronto-census-tract-populations-2021.csv - External data · Additional source files expected to be obtained separately during setup.
R workflow
Linear staged scripts that prepare data, validate it, and run the proximity and risk analyses.
- Environment setup · Loads packages, establishes the runtime, and reshapes raw inputs into analysis-ready spatial objects.
R-code/01-data-environment.R - Data validation · Checks that derived objects exist and are structurally sound before analysis continues.
R-code/02-data-validation.R - Simple analysis · Counts overdose events within fixed-radius buffers around each shelter.
R-code/03-simple-analysis.R - Advanced analysis · Combines proximity counts with census denominators to estimate standardized risk measures.
R-code/04-data-analysis.R - Simple runner · Convenience script for the simpler workflow path.
run-simple-analysis.R - Runtime pin · Pinned R package versions for reproducibility.
renv.lock
Setup notes
User-facing instructions and provenance notes that define the operational boundary.
- Quickstart · Lightweight reproducible setup path for the simple workflow.
information-and-notes/QUICKSTART.md - Full setup · Complete setup and execution instructions for the full analysis.
information-and-notes/FULLSETUP.md - Data notes · Source notes, limitations, and interpretation guidance.
information-and-notes/DATANOTES.md
Results
Generated analytical artifacts written to the working directory.
- Shelter counts · Shelter-level event counts within 200 m and 500 m catchments.
- Risk estimates · Population-adjusted risk ratios or standardized incidence style estimates.
- Figures · Maps and spatial-statistics figures referenced by the analysis narrative.
- Summary tables · Derived tables and uncertainty summaries written to the working directory.
Connections 18
- Overdose events → Environment setup: raw input · Event records are loaded into the analysis environment.
- Neighbourhood events → Environment setup: raw input · Neighbourhood-level event data is transformed alongside intersection records.
- Shelter sites → Environment setup: raw input · Shelter locations become spatial anchor points.
- Census populations → Environment setup: raw input · Population denominators are prepared for later adjustment.
- External data → Environment setup: optional input · External source files may be incorporated during setup.
- Runtime pin → Environment setup: pins packages · The locked dependency set constrains the runtime environment.
- Environment setup → Data validation: derived objects · Validation checks the objects created by environment setup.
- Data validation → Simple analysis: validated data · Simple analysis depends on passing data checks.
- Data validation → Advanced analysis: validated data · Advanced analysis uses the same validated spatial objects.
- Simple runner → Simple analysis: invokes · Convenience entry point for the simple workflow.
- Quickstart → Simple runner: instructions · Quickstart points users at the lightweight runner.
- Full setup → Environment setup: instructions · Full setup describes the staged workflow and environment preparation.
- Simple analysis → Shelter counts: writes · Buffer-based event tallies are emitted as tabular results.
- Simple analysis → Summary tables: writes · The simple pipeline also produces summary tables.
- Advanced analysis → Risk estimates: writes · Population-adjusted risk measures are generated here.
- Advanced analysis → Summary tables: writes · Advanced statistics and uncertainty summaries are written out.
- Advanced analysis → Figures: writes · Broader spatial-statistics outputs include mapping and figure artifacts.
- Data notes → Simple analysis: context · Provenance notes frame interpretation of the analytical outputs.