🇬🇧 English | 🇪🇸 Español
Bayesian spatial extreme value analysis of daily precipitation across Andalucía, Spain, using the Max-and-Smooth two-stage framework with Matérn(5/2) Gaussian process spatial smoothing and penalised complexity (PC) priors.
Extreme daily precipitation is a key input for flood risk assessment, infrastructure design, and water resource planning. Estimating how rare a given rainfall event is — and how that rarity varies across space — requires fitting statistical models to observed data. When individual station records are short or sparse, site-by-site estimates can be noisy and spatially inconsistent.
The goal of this project is to provide spatially continuous estimates of return levels (the rainfall amount expected to be exceeded on average once every T years) and exceedance probabilities (the chance of exceeding a critical threshold within a planning horizon) across Andalucía, to support flood risk assessment and hydrological planning in the region. Using daily precipitation records from 127 AEMET stations, the two-stage Max-and-Smooth framework (Hrafnkelsson et al., 2021) fits a GEV distribution at each station independently, then borrows strength across stations through a Matérn Gaussian process prior, producing spatially coherent maps with full uncertainty quantification.
- Source: AEMET (Agencia Estatal de Meteorología) OpenData API
- Coverage: 127 stations across all 8 provinces of Andalucía
- Period: 1950–2024 (varies by station; minimum record length governed by Bayesian borrowing of strength)
- QC: Station-years require ≥90% daily completeness (≥330 days/year)
The analysis follows the Max-and-Smooth approach of Hrafnkelsson et al. (2021) as presented in Hazra, Huser & Jóhannesson (2023, Ch. 7). Annual maximum daily rainfall at each station is modelled by a generalised extreme value (GEV) distribution whose parameters vary smoothly across space through Gaussian process priors.
The GEV distribution function is
with location
where
with constants
At each station, a Poisson point process (PPP) likelihood is maximised over daily observations exceeding a site-specific threshold (the 75th percentile of positive precipitation). Multi-start optimisation over five initial shape values avoids local optima, with interior solutions (
A parametric bootstrap (1000 replicates per station) provides per-station 3 × 3 covariance matrices
The Stage 1 estimates
The location parameter
The design matrix
| Covariate | Description |
|---|---|
| Altitude (DEM) | Elevation from SRTM 90 m DEM, standardised |
| Windward exposure | Mean orographic exposure from Mediterranean SE (135°) and Atlantic WSW (255°) wind directions, computed over 20 km transects |
| Altitude × Exposure | Interaction capturing enhanced orographic precipitation at elevated exposed sites |
Altitude and exposure are standardised to zero mean and unit variance at the station locations. Windward exposure at each station is computed as the difference between the station's elevation and the mean elevation along a 20 km upwind transect sampled from the DEM (see R/10_dem_exposure.R).
The spatial random effects
where
The Stage 1 bootstrap covariances form a block-diagonal precision matrix
which decouples the computationally expensive per-station PPP fits from the spatial smoothing.
To improve HMC sampling efficiency, all three GPs are parameterised as
Following Fuglstad et al. (2019), the GP hyperparameters receive PC priors. The
| Parameter |
|
|
|---|---|---|
|
|
||
|
|
||
|
|
Covariate coefficients adapt_delta = 0.9.
Return levels and exceedance probabilities at unobserved locations are obtained by sampling from the posterior predictive distribution of the conditional GP. For each posterior draw, the predicted GEV parameters at a new location
At each grid point, altitude and windward exposure are extracted from the DEM and used to form the prediction design matrix
The station network extends up to approximately 1500 m elevation, but grid points reach the summit of Mulhacén (3479 m). Below the highest station, the DEM altitude enters the design matrix directly. Above it, the altitude effect is attenuated using the Clausius-Clapeyron moisture decay:
where
The GP hyperparameters
where
with
The shape parameter
Predictions are computed on a 0.005° (~500 m) grid across Andalucía. Grid-level altitude and windward exposure are precomputed from the SRTM DEM (R/11_grid_covariates.R).
Posterior mean return levels at T = 10, 20, 50, and 100 years, interpolated across Andalucía on a 0.005° grid.
Posterior standard deviation of the return level estimates, reflecting uncertainty from both the GEV parameter estimation and the spatial interpolation.
Posterior mean probability that the annual maximum daily rainfall exceeds a given threshold (100, 150, 200 mm) at least once within a planning horizon (20, 50, 100 years).
Posterior standard deviation of the exceedance probabilities, capturing uncertainty in both the tail behaviour and the spatial prediction.
Return level curves at 6 selected stations. Points show observed annual maxima (Gringorten plotting positions). The dashed red line is the site-only MLE fit; the solid blue line is the spatially smoothed posterior mean with 90% credible band.
- R (≥ 4.2)
- Stan: CmdStan (≥ 2.33)
- R packages: cmdstanr, bayesplot, ggplot2, patchwork, sf, terra, rnaturalearth, rnaturalearthdata, dplyr, lubridate, Matrix, climaemet
Pre-computed results are in data/stage1_results.rds and data/stage2_matern_pc_results.rds (gitignored; regenerate with steps 2–3 below).
Rscript R/00_station_map.R # Station network map (Figure 0)
Rscript R/01_acquire_data.R # Download AEMET daily precipitation
Rscript R/02_stage1_mle.R # Stage 1: per-station PPP GEV MLEs (~10 min)
Rscript R/10_dem_exposure.R # DEM download + station windward exposure
Rscript R/03_stage2_smooth.R # Stage 2: spatial GP smoothing in Stan (~45 min)
Rscript R/11_grid_covariates.R # Precompute altitude + exposure on prediction grid
Rscript R/04_return_level_maps.R # Return level maps (Figure 1)
Rscript R/05_exceedance_maps.R # Exceedance probability maps (Figure 2)
Rscript R/06_station_diagnostics.R # Station return level curves (Figure 3)
Rscript R/07_convergence_diagnostics.R # MCMC convergence diagnostics (diagnostics/)
Rscript R/08_spanish_figures.R # Figuras en español (figures/es/)-
Hrafnkelsson, B., Siegert, S., Huser, R., Bakka, H. & Jóhannesson, Á. V. (2021). Max-and-Smooth: a two-step approach for approximate Bayesian inference in latent Gaussian models. Bayesian Analysis, 16(2), 611–638. doi:10.1214/20-BA1219
-
Hazra, A., Huser, R. & Jóhannesson, Á. V. (2023). Bayesian spatial modelling of extreme precipitation return levels. In: Hrafnkelsson, B. (ed.) Bayesian Latent Gaussian Models. Chapman & Hall/CRC, Ch. 7. doi:10.1007/978-3-031-39791-2_7
-
Fuglstad, G.-A., Simpson, D., Lindgren, F. & Rue, H. (2019). Constructing priors that penalize the complexity of Gaussian random fields. Journal of the American Statistical Association, 114(525), 445–452. doi:10.1080/01621459.2017.1415907
-
Formetta, G., Marra, F. & Dallan, E. (2022). Modelling the dependence between short-duration precipitation intensity and duration as a function of altitude. International Journal of Climatology, 42, 3268–3282. doi:10.1002/joc.7418
-
Carpenter, B. et al. (2017). Stan: A probabilistic programming language. Journal of Statistical Software, 76(1). doi:10.18637/jss.v076.i01
The Stage 2 Stan implementation — in particular the sparse Cholesky surrogate likelihood (normal_prec_chol_lpdf) and the non-centered spatial parameterisation — is adapted from Brynjólfur Gauti Guðmundsson's maxandsmooth R package. The Stage 1 fitting code (vendor/max_and_smooth/) is from the companion repository to Hazra, Huser & Jóhannesson (2023): arnabstatswithR/max_and_smooth.





