This might be a very niche Problem. I have a modified Dataset – based on the 4th downloadlink with 105572 elements – and want to know how I can model it in the best way. I had to use Arena Software from Rockwell Software. I got the following as a result for a distribution: “816 + LOGN(198, 439)” In the picture bellow on the left side you can see the fit. From the Documentation the Output should be: “Lognormal (mu, sigma): LOGN (LogMean, LogStd) or LOGNORMAL (LogMean, LogStd)”. However, I would like to reconstruct it in Python.
import matplotlib.pyplot as plt import scipy.stats as stats import numpy as np plt.hist(dataset, bins=bins, density=True, color='c', alpha=0.75, label="original Data") xmin = dataset.min() #816 xmax = dataset.max() #1672 x = np.linspace(xmin, xmax, 100) pdf = stats.lognorm.pdf(x, s=439, scale=np.exp(198), loc=816)#816 + LOGN(198, 439) plt.plot(x, pdf, 'r', label="Lognormal") plt.legend() plt.show()
I have no idea how I can make them the same size or look nice. I can’t reale use the picture from Arena Software because i would like to plot multiple distributions into one picture. With a scipy.stats.fit I get somewhat better results. As in this post I tried following code:
s, loc, scale = stats.lognorm.fit(system20, floc=0) #-> 0.19860417 0.0 967.8363
Advertisement
Answer
Solution:
The Output in Arena Software for the Lognormal distribution is in the form of (LogMean LogStd). In the docs there is actually a transformation to get the normal mean and std for easy replication of the distribution.
#Input: LogMean, LogStd from Arena Software #Output: Mean, Std def logNReal (mean, sigma): return np.log( mean**2 / np.sqrt(sigma**2 + mean**2) ), np.sqrt( np.log( (sigma**2 + mean**2) / mean**2) )
If you want to plot it with scipy.stats.lognorm:
stats.lognorm.pdf(x, s=std, scale=np.exp(mean), loc=a) #you can find a in the output of Arena: a + LOGN(LogMean, LogStd)