numpyro icon indicating copy to clipboard operation
numpyro copied to clipboard

Working example for Bayesian Quantile Regression and AsymmetricLaplace Distribution

Open d-diaz opened this issue 3 years ago • 7 comments

I've prepared a simple working example of Bayesian Quantile Regression using an implementation of an AsymmetricLaplace distribution in a Colab Notebook here. I'd like to offer this up as an example for numpyro documentation, but am not sure whether this needs to be converted to script or if it can be utilized as a notebook.

d-diaz avatar Feb 03 '22 23:02 d-diaz

Hi @d-diaz I think it is best to have asymmetric laplace distribution in the library and a tutorial (which might be best to explain how quantile regression works and how to use numpyro to such problem) or an example script with current content. Using asymmetric parameter will match wikipedia article but you can make a wrapper like a function make_lilelihood(..., quantile) for your convenience in example/tutorial. Thanks for contributing!

fehiepsi avatar Feb 04 '22 04:02 fehiepsi

In terms of adopting a wrapper, I was struggling to figure out how to translate Wikipedia’s version of parameters for asymmetric Laplace to or from the parameters commonly used and cited in Bayesian quantile regression.

It might be easier (at least for me) to try and contribute the quantile parameterization to the Wikipedia page rather than attempt a direct translation in code.

d-diaz avatar Feb 10 '22 17:02 d-diaz

Alternatively, I could extend the Pyro version of the ALD class to except either the Pyro/Wikipedia or quantile parameterization… such as

def __init__(self, loc=0, scale=1, asymmetry=None, quantile=None):
    …

d-diaz avatar Feb 10 '22 18:02 d-diaz

In case it's relevant, I've now added the alternative parameterization to the Wikipedia page.

d-diaz avatar Feb 10 '22 19:02 d-diaz

It seems to me that the scale parameter lambda in the main wikipedia article should be the rate. Scipy also uses asymetry parameterization. If you find quantile argument useful, you can define a new distribution named AssymetryLaplaceQuantile or something like that. :) I did google search and found that asymmetry is commonly used for AssymetryLaplace. ~Note that we also have quantile methods in Pyro distributions so you might also want to rename it to something like~

fehiepsi avatar Feb 10 '22 20:02 fehiepsi

I think it seems most sensible to implement an AsymmetricLaplace class following the Scipy and Pyro and Wikipedia pattern and a distinct AsymmetricLaplaceQuantile class following the Bayesian quantile regression pattern. I don’t know the use cases for the AsymmetricLaplace with asymmetry parameterization, but did run into a the need for this quantile regression version in my own work. I’ll expand the minimal working example in Colab into a notebook tutorial around quantile regression and add these two classes into the library. Will report back here when that’s done.

d-diaz avatar Feb 10 '22 21:02 d-diaz

That's an awesome plan, thanks @d-diaz!

fehiepsi avatar Feb 10 '22 21:02 fehiepsi