Open data and brms code for soil carbon spectroscopy prediction

We just published a paper in the European Journal of Soil Science using Stan to fit a spectroscopy prediction model. Code and data using brms and targets is here.

In this problem the predictor is a spectroscopy scan, e.g. one of the curves in figure 1d:

Each curve consists of 257 points. Partial least squares (PLSR) is the classic approach for this setting, with a lot of machine/deep learning these days. I was curious if a Bayesian regression would do. Turns out it does! And also addresses two important problems: uncertainty quantification and predicting in new groups (“model transfer”) using a multilevel structure.

It’s a textbook multilevel model. To abuse R formula syntax:

log1p(y) ∼ 1 + Z + X +Z : X + (1 + X | farm + field + layer + field:layer)

where y is soil carbon, Z are 4 group-level predictors, X are 64 spectroscopy predictors [1], and farm, field, and layer are the groupings.

The only twist is those 64 spectroscopy predictors and 256 interactions. Since the predictors form a continuous signal, I tried a bunch of interesting things (random walk and GP priors, wavelet transform). In the end I settled for a simple hierarchical shrinkage (see paper and supplement for full priors)!

Let me know if you have any feedback. Spectroscopy is really popular and practical in everything from soil science to crop breeding. I’m hoping this approach can be deployed. Thanks for reading and thank you to the stan and brms developers!

[1] I had to downsample from 257 to 64 to get it to fit in a reasonable amount of time. But I’m guessing/hopeful this was just a side-effect of using brms to code the model. Brms treats each predictor as a separate Stan real instead of using a vector.

4 Likes