spclustr
Rendered reports: mape_r-01 · mape_r-01_reto
spclustr is a personal learning lab of standalone R scripts reproducing spatial statistics tutorials, package vignettes, and papers. It is not an R package — each .R/.Rmd file is a self-contained reproduction covering one method or one package, spanning point pattern analysis, areal/disease mapping, geostatistics, GAM-based smoothing, and scan statistics for cluster detection (e.g. via spatstat, spdep, rsatscan).
What’s inside
The scripts are grouped below by the spatial-statistics theme they demonstrate. Each entry lists the script(s) and the key package(s) exercised.
Point pattern analysis
Intensity/density estimation, case-control (bivariate) patterns, spatio-temporal point processes, relative risk mapping.
dc-spatstat-c2.R,dc-spatstat-c2.5.R— DataCamp “Spatial Statistics in R”, ch. 2: bivariate/case-control point patterns, spatio-temporal descriptive & inferential analysis,ppp↔sfconversion. (spatstat, sf, tmap, raster, spatialkernel, splancs, ggspatial, maptools)mape_r-01.R/mape_r-01.Rmd— teaching session on bivariate point pattern density & relative-risk mapping, prepared for Club de Análisis Espacial, Sesión #5 (“mapear”). (spatstat, sf, maptools, tidyverse)- Rendered: html
mape_r-01_reto.Rmd— challenge notebook for the same session: mapping geolocated COVID-19 China case data assf. (sf, ggspatial, googlesheets4, janitor, tidyverse)- Rendered: html
Areal data & disease mapping
Choropleths, cartograms, Moran’s I spatial autocorrelation, spatial GLM regression, Bayesian (BYM/INLA) disease mapping.
dc-spatstat-c3.R— DataCamp ch. 3, London EU referendum data: choropleths, cartograms, Moran’s I, SIR/GLM regression. (sf, tmap, raster, cartogram, rgeos, spdep, R2BayesX)moraga-RJ-2018-036.R— reproduction of Paula Moraga (2018), Small Area Disease Risk Estimation and Visualization Using R: SIR calculation, neighborhood matrix, Bayesian disease mapping with INLA (BYM model). (SpatialEpi, spdep, INLA, sf)
Find a recent implementation of Moran’s Index spatial autocorrelation, as well as High-High and Low-Low clusters (for spatial correlation and incidence rate), for spatiotemporal analysis with
{epiCo}
Geostatistics
Trend surfaces, variograms, kriging.
dc-spatstat-c4.R— DataCamp ch. 4: trend surface analysis, variograms, kriging (manual and viaautomap). (spatstat, gstat, raster, automap, broom)
GAM-based spatial smoothing
Generalized additive models for smoothing spatial risk/odds surfaces.
dc-spatstat-gam_reprex.R— case-control intensity/relative-risk mapping followed by GAM modeling of spatial risk. (spatstat, mgcv, mgcViz, geoR, fields, viridis)gam-mapgam-reprex.R—mapGAM/modgamsmoothing of odds ratios & relative risk over a spatial prediction grid. (mapGAM, PBSmapping, maps, mapproj)gam-reprex.R— general GAM modeling walkthrough: smooths, diagnostics. (mgcv, mgcViz, gamair, broom, MASS)
Scan statistics for cluster detection
Spatial and space-time cluster detection.
satscan-0-vignette.R—rsatscanvignette, wrapping the external SaTScan software: Bernoulli spatial, Poisson space-time/discrete-time, and space-time permutation scan statistics. (rsatscan, spatstat, sf, janitor)scanstatistics-1-vignette.R—scanstatisticspackage vignette: expectation-based Poisson scan statistics for space-time cluster detection. (scanstatistics, sp, tsibble, magrittr)
Supporting utilities
ggmap-0-vignette.R—ggmapvignette: basemap tiles and plotting geolocated crime points. (ggmap, tidyverse)
Installation
This repo is a flat collection of scripts, not an installable R package — there is no DESCRIPTION or renv.lock. To run a script:
# 1. clone the repo, then open spclustr.Rproj in RStudio
# 2. install the packages required by the script you want to run, e.g.:
install.packages(c("spatstat", "sf", "tmap", "spdep", "gstat", "mgcv"))
# some scripts need packages outside CRAN:
# - INLA (used by moraga-RJ-2018-036.R):
install.packages("INLA", repos = "https://inla.r-inla-download.org/R/stable")
# - rsatscan (used by satscan-0-vignette.R) also requires the standalone
# SaTScan desktop application installed separately: https://www.satscan.org/
# 3. run the script
References
- Moraga, P. (2018). Small Area Disease Risk Estimation and Visualization Using R. The R Journal. link
- SaTScan software &
rsatscanpackage: https://www.satscan.org/rsatscan/rsatscan.html scanstatisticspackage vignette: expectation-based scan statistics for space-time cluster detectionmapGAMpackage: GAM-based smoothing for spatial epidemiology- DataCamp, “Spatial Statistics in R” course (chapters 2–4 reproduced here)
Author
- Andree Valle Campos (@avallecam)
Acknowledgements
Some material here was originally prepared for Club de Análisis Espacial, a spatial-analysis study group, as teaching/challenge material for Sesión #5 (“mapear”).