Reputation: 8585
I'm trying to define a Pareto distribution using scypi in Python. I have values of alpha and xm in mind like they are in the classic definition of the distribution, for example in wikipedia: https://en.wikipedia.org/wiki/Pareto_distribution Let's say I want to have alpha = 4 and xm = 3. How do I initialize scipy.stats.pareto with those parameters?
import scipy.stats as sts
pareto_alpha = 4
pareto_xm = 3
pareto_rv = sts.pareto(???)
Here is the docs page of the pareto function https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.pareto.html#scipy.stats.pareto I can't find a clear description of the constructor there.
Upvotes: 3
Views: 7253
Reputation: 41
Since I wasn't entirely conviced, I've run some tests.
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import pareto
def my_pareto_pdf(x, a, x_m):
"""
Returns the value of the pareto density function at
the point x.
"""
if x >= x_m:
pdv = a
pdv *= x_m**a
pdv /= x**(a+1)
return pdv
else:
return 0
x = np.linspace(0, 10, 100)
plt.plot(x, pareto.pdf(x, b=1.3), color='k', label='Scipy: b=1.3')
plt.plot(x, [my_pareto_pdf(val, a=1.3, x_m=1) for val in x], color='tab:blue', alpha=0.5, lw=5, label='Mypdf: a=1.3 x_m=1')
plt.plot(x, pareto.pdf(x, b=1.7, scale=3), color='k', label='Scipy: b=1.7 scale=3')
plt.plot(x, [my_pareto_pdf(val, a=1.7, x_m=3) for val in x], color='tab:blue', alpha=0.5, lw=5, label='Mypdf: a=1.7 x_m=3')
plt.plot(x, pareto.pdf(x, b=2.3, scale=6), color='k', label='Scipy: b=2.3 scale=6')
plt.plot(x, [my_pareto_pdf(val, a=2.3, x_m=6) for val in x], color='tab:blue', alpha=0.5, lw=5, label='Mypdf: a=2.3 x_m=6')
plt.legend(loc='best')
plt.title('Pareto PDFs')
plt.show()
And this is the output.
So in scipy the parameter b works as the alpha, and scale as the xm, of the classic definition.
Upvotes: 4
Reputation: 4904
You could plot the pdf for different values of b (the shape parameter) like so:
import numpy as np
from matplotlib import pyplot as plt
from scipy.stats import pareto
xm = 1 # scale
alphas = [1, 2, 3] # shape parameters
x = np.linspace(0, 5, 1000)
output = np.array([pareto.pdf(x, scale = xm, b = a) for a in alphas])
plt.plot(x, output.T)
plt.show()
Upvotes: 5