# Selecting prior distributions for Cauchy as likelihood distibution

**URL:** <https://discourse.pymc.io/t/selecting-prior-distributions-for-cauchy-as-likelihood-distibution/8563>\
**Category:** Questions\
**Tags:** prior\
**Created:** [January 10, 2022, 8:50am UTC](https://discourse.pymc.io/t/selecting-prior-distributions-for-cauchy-as-likelihood-distibution/8563 "2022-01-10T08:50:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mojo\_ild](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/mojo_ild/32/4703_2.png) [@Mojo\_ild](https://discourse.pymc.io/u/Mojo_ild)\
**Post date:** [January 10, 2022, 8:50am UTC](https://discourse.pymc.io/t/selecting-prior-distributions-for-cauchy-as-likelihood-distibution/8563/1 "2022-01-10T08:50:52Z")

</div>

I came across a dataset where I checked which distributions fits the new dataset and it turns out to be Cauchy Distribution. I already know that there is a Cauchy function in PYMC3, but, what I am wondering is what type of priors to use where Cauchy is the likelihood distribution?

I looked into wikepedia and understood that scale parameter is greater than 0 so I am thinking halfnorm for the scale/beta parameter. but with location/alpha parameter, mmy questions are the following:

- is it possible to assume to use norm distribution for alpha?
- input the values into Cauchy likelihood distribution?
- what are possible distribution to use as prior?
- is it possible to use exponential instead of halfnorm?

I have created the following model:

```auto
with pm.Model as model:
            # Prior Distributions for unknown model parameters from posterior distriution:
            sigma = pm.HalfNormal('sigma', sigma=1)
            mu = pm.Normal('mu', mu=0, sigma=1)

            # Observed data is from a likelihood distributions (Likelihood (sampling distribution) of observations):
            observed_data = Cauchy('observed_data', alpha=mu, beta=sigma, observed=data)
            # obtain starting values via MAP
            # startvals_P = pm.find_MAP(model=model_P)
            
            # instantiate sampler
            # step = pm.Metropolis() ## Best one
            # step = pm.HamiltonianMC()
            # step = pm.NUTS()
            # step = pm.sample_smc(n_steps=10, cores=2,progressbar=True)
            
            # Printing the result of log_likelihood:
            # print('log_likelihood result:', model)
            
            # draw 5000 posterior samples
            trace = pm.sample(draws=1000, tune=1000, chains=3, cores=1, progressbar=True)
            # trace = pm.sample(start=startvals, draws=1500, step=step, tune=500, chains=3, cores=1, progressbar=True)
            
            # Obtaining Posterior Predictive Sampling:
            post_pred = pm.sample_posterior_predictive(trace, samples=1000)
            # post_pred = pm.sample_posterior_predictive(trace, samples=1500)
            print(post_pred['observed_data'].shape)
            print('\nSummary: ')
            print(pm.stats.summary(data=trace))
            print(pm.stats.summary(data=post_pred))
########################################################################################################################
    return trace, post_pred

```

---

<div class="post-metadata">

**Author:** ![junpenglao](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/junpenglao/32/8_2.png) [@junpenglao](https://discourse.pymc.io/u/junpenglao)\
**Post date:** [January 10, 2022, 9:39am UTC](https://discourse.pymc.io/t/selecting-prior-distributions-for-cauchy-as-likelihood-distibution/8563/2 "2022-01-10T09:39:58Z")

</div>

I think you can choose similar parameter to a gaussian likelihood (a location parameter and a scale parameter).  
However, Cauchy likelihood is pretty rare choice as it indicates you can observe inf and -inf. If you just want to model heavy tail observation a student t likelihood is probably better.

---

<div class="post-metadata">

**Author:** ![Mojo\_ild](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/mojo_ild/32/4703_2.png) [@Mojo\_ild](https://discourse.pymc.io/u/Mojo_ild)\
**Post date:** [January 10, 2022, 9:51am UTC](https://discourse.pymc.io/t/selecting-prior-distributions-for-cauchy-as-likelihood-distibution/8563/3 "2022-01-10T09:51:07Z")

</div>

> [@junpenglao](#):
>
> However, Cauchy likelihood is pretty rare choice as it indicates you can observe inf and -inf. If you just want to model heavy tail observation a student t likelihood is probably better.

So, if I will go with StudentT distribution should I keep the same prior distributions?

---

<div class="post-metadata">

**Author:** ![junpenglao](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/junpenglao/32/8_2.png) [@junpenglao](https://discourse.pymc.io/u/junpenglao)\
**Post date:** [January 10, 2022, 10:26am UTC](https://discourse.pymc.io/t/selecting-prior-distributions-for-cauchy-as-likelihood-distibution/8563/4 "2022-01-10T10:26:03Z")

</div>

Yes, you also need to assign a prior on degree of freedom `df`.

---

<div class="post-metadata">

**Author:** ![Mojo\_ild](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/mojo_ild/32/4703_2.png) [@Mojo\_ild](https://discourse.pymc.io/u/Mojo_ild)\
**Post date:** [January 10, 2022, 10:29am UTC](https://discourse.pymc.io/t/selecting-prior-distributions-for-cauchy-as-likelihood-distibution/8563/5 "2022-01-10T10:29:33Z")

</div>

Okay, I will give it a try. Thanks

---

<div class="post-metadata">

**Author:** ![Mojo\_ild](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/mojo_ild/32/4703_2.png) [@Mojo\_ild](https://discourse.pymc.io/u/Mojo_ild)\
**Post date:** [January 11, 2022, 4:16pm UTC](https://discourse.pymc.io/t/selecting-prior-distributions-for-cauchy-as-likelihood-distibution/8563/6 "2022-01-11T16:16:04Z")

</div>

I am sill waiting the results of using StudentT distribution, but, I have a question, when I ran the Cauchy distribution, I keep on getting an error with the sigma part where the error I that I got is:

```auto
ValueError: Mass matrix contains zeros on the diagonal. 
The derivative of RV `sigma_P_log__`.ravel()[0] is zero.

```

What’s the cause of getting this error and how can I solve this error?
