Reputation: 31
I need to generate a skewed distribution for a given range (eg: low= 1, high =10) and size = 100. stats.skewnorm can produce a skewed distribution, but it does not take in the parameter for lower and upper bound. Can someone please help me with it.
def skewed_data(low, high, number):
skew_parameter = 5
data = skewnorm.rvs(skew_parameter, loc=1, scale=1, size=number)
data = np.round(data,0).astype(int)
return data
result_data = skewed_data(1, 10,100)
bins = np.linspace(0, 10, 10)
plt.hist(response, bins, alpha=1, label='histogram')
plt.legend(loc='upper right')
plt.show()
the histogram plot of the result data is shown below (all the result data are between 1 to 5, whereas I would like it to be distributed between 1 to 10 and right skewed.
Upvotes: 1
Views: 2690
Reputation: 19854
There are lots of skewed distributions, an infinite number in fact. If you want one with guarantees on the min and max, a simple and easy-to-generate possibility is the triangular distribution. Triangles are parameterized by specifying the min, max, and mode (most likely outcome). Any value for mode other than the mid-point between min and max will yield skewness. If you want results that are right-skewed between 1 and 10, use values like 1, 10, and 3 as the min, max, and mode, respectively.
Triangular distributions are available through the random module or numpy.
If the triangular distribution is too piecewise linear and pointy for you, another alternative might be the beta distribution. Betas are defined on the range [0,1], so you would need to scale and shift to get other ranges.
The beta distribution is available through numpy/scipy.
Upvotes: 4