# Some questions about defining a custom distribution

**URL:** <https://discourse.pymc.io/t/some-questions-about-defining-a-custom-distribution/12400>\
**Category:** v5\
**Tags:** bug\
**Created:** [June 29, 2023, 3:07am UTC](https://discourse.pymc.io/t/some-questions-about-defining-a-custom-distribution/12400 "2023-06-29T03:07:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Liu](https://avatars.discourse-cdn.com/v4/letter/l/a88e57/32.png) [@Liu](https://discourse.pymc.io/u/Liu)\
**Post date:** [June 29, 2023, 3:07am UTC](https://discourse.pymc.io/t/some-questions-about-defining-a-custom-distribution/12400/1 "2023-06-29T03:07:05Z")

</div>

Hello,everyone! I am a rookie about pymc,and I’m trying to define a three-parameter log-logistic distribution in pymc.I have referred to the official documents in pymc3.But I have encountered a problem.This is my code:

from pymc3.distributions.dist\_math import bound, logpow  
import numpy as np  
from scipy.stats import fisk

def loglogistic\_logp(alpha,beta,r,value):  
alpha\_r\_value=(value-r)/alpha  
log\_prob=np.log(beta/alpha)+logpow(alpha\_r\_value,beta-1)+logpow(1+alpha\_r\_value\*\*beta,-2)  
return log\_prob

def loglogistic\_rvs(alpha,beta,r,size):  
return fisk.rvs(c=beta,loc=r,scale=alpha,size=size)

class CustomLogLogistic(pm.Continuous):  
def _init_(self,alpha,beta,r,\*args,\*\*kwargs):  
super(CustomLogLogistic,self)._init_(\*args, \*\*kwargs)  
self.alpha=alpha  
self.beta=beta  
self.r=r

```
def logp(self,value):
    alpha=self.alpha
    beta=self.beta
    r=self.r
    return loglogistic_logp(alpha,beta,r,value)

def random(self,alpha,beta,r):
    return fisk.rvs(c=beta,loc=r,scale=alpha,size=size)

```

then i tried this:

b=CustomLogLogistic.dist(beta=3.05,r=0,alpha=1).random()  
print(b)

i got a error:  
**init** () got an unexpected keyword argument ‘beta’

and i don’t know how to fix it.  
English is not my native language, forgive me for my poor expression.  
Thank you all!

---

<div class="post-metadata">

**Author:** ![ricardoV94](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/ricardov94/32/5775_2.png) [@ricardoV94](https://discourse.pymc.io/u/ricardoV94)\
**Post date:** [June 29, 2023, 6:42am UTC](https://discourse.pymc.io/t/some-questions-about-defining-a-custom-distribution/12400/2 "2023-06-29T06:42:18Z")

</div>

Since the fisk is just an exponentiated Logistic, in the new version of PyMC you can actually define it easily with a CustomDist like this:

```python
import pymc as pm

def log_logistic(alpha, beta, size):
  mu = pm.math.log(alpha)
  s = 1/beta
  return pm.math.exp(pm.Logistic.dist(mu=mu, s=s, size=size))

with pm.Model() as m:
  ...
  x = pm.CustomDist("x", alpha, beta, dist=log_logistic)

```

> **[Log-logistic distribution](https://en.m.wikipedia.org/wiki/Log-logistic_distribution)**
>
> In probability and statistics, the log-logistic distribution (known as the Fisk distribution in economics) is a continuous probability distribution for a non-negative random variable. It is used in survival analysis as a parametric model for events whose rate increases initially and decreases later, as, for example, mortality rate from cancer following diagnosis or treatment. It has also been used in hydrology to model stream flow and precipitation, in economics as a simple model of the distribut...

[https://www.pymc.io/projects/docs/en/stable/api/distributions/generated/pymc.CustomDist.html](https://www.pymc.io/projects/docs/en/stable/api/distributions/generated/pymc.CustomDist.html)

---

<div class="post-metadata">

**Author:** ![Liu](https://avatars.discourse-cdn.com/v4/letter/l/a88e57/32.png) [@Liu](https://discourse.pymc.io/u/Liu)\
**Post date:** [June 29, 2023, 12:05pm UTC](https://discourse.pymc.io/t/some-questions-about-defining-a-custom-distribution/12400/4 "2023-06-29T12:05:37Z")

</div>

Thank you sooooo much！  
But I want to use a three-parameter log-logistic distribution,which has another parameter : location parameter,so I still don’t know how to do.  
This is its link,and I’m using its " Alternate parameterization" PDF  
[https://en.wikipedia.org/wiki/Shifted\_log-logistic\_distribution](https://en.wikipedia.org/wiki/Shifted_log-logistic_distribution)

---

<div class="post-metadata">

**Author:** ![ricardoV94](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/ricardov94/32/5775_2.png) [@ricardoV94](https://discourse.pymc.io/u/ricardoV94)\
**Post date:** [June 29, 2023, 12:23pm UTC](https://discourse.pymc.io/t/some-questions-about-defining-a-custom-distribution/12400/5 "2023-06-29T12:23:35Z")

</div>

You can just add a loc parameter!

```python
import pymc as pm

def log_logistic(alpha, beta, loc, size):
  mu = pm.math.log(alpha)
  s = 1/beta
  return pm.math.exp(pm.Logistic.dist(mu=mu, s=s, size=size)) + loc

with pm.Model() as m:
  ...
  x = pm.CustomDist("x", alpha, beta, loc, dist=log_logistic)

```

---

<div class="post-metadata">

**Author:** ![Liu](https://avatars.discourse-cdn.com/v4/letter/l/a88e57/32.png) [@Liu](https://discourse.pymc.io/u/Liu)\
**Post date:** [June 30, 2023, 2:41am UTC](https://discourse.pymc.io/t/some-questions-about-defining-a-custom-distribution/12400/6 "2023-06-30T02:41:34Z")

</div>

Thank you again! 😃  
I have studied the knowledge of distribution too poorly, and I have studied it carefully again, understanding the relationship between them.
