Using PyStan to fit a model with X and Y errors

less than 1 minute read

Published:

After writing my first post. I was recommended Stan to fit more complicated models to data with X and Y uncertainties. Stan and Hamiltonian Monte Carlo (HMC) is naturally suited to problems like this as the simplest way to treat X errors is to sample over the true x values and then marginalise. This adds a dimension for each data point which breaks most samplers, except HMC. This example is for a simple problem like in the first post, but instead using Stan to sample. Shoutout to Andy Casey for help with Stan.

Jupyter notebook to run through the problem here.