← Back to Projects

Soil Nutrient Depth Profiles: Bayesian Hierarchical Modeling

How organic carbon, nitrogen, and phosphorus change with depth across 40 Tanzanian agricultural fields, modeled with multivariate random effects in Stan.

Bayesian Hierarchical Models Stan & MCMC Variable Selection (projpred) Compositional Data (ILR)

Abstract

We modeled the vertical distribution of soil organic carbon, total nitrogen, and total phosphorus across 40 Tanzanian agricultural fields. The final model is a Bayesian hierarchical specification with field-level random intercepts and slopes, modeled jointly as multivariate random effects in Stan via cmdstanr, where a six-dimensional LKJ covariance structure captures the cross-response correlations between them. Model selection relied on LOO-CV, and robustness was assessed through sensitivity to influential observations, a Gaussian process spatial term, and a frequentist re-fit.

Key Takeaway

Fields with higher mean organic carbon show significantly flatter depth profiles: carbon fertility is better preserved at depth. The pattern is absent for nitrogen and only moderate, with wide posterior uncertainty, for phosphorus. Predictive variable selection with projpred identifies fine soil texture (the fine fraction vs. sand ILR contrast) as the dominant within-field predictor, while management practices are not significant once the physical structure of the soil is accounted for.

Visuals

Links