Generate Random Number in Range from Single-Tailed Distribution with Python

taurus

I want to generate a random float in the range [0, 1) from a one-tailed distribution that looks like this enter image description here

The above is the chi-squared distribution. I can only find resources on drawing from a uniform distribution in a range, however.

Maurits Evers

You could use a Beta distribution, e.g.

import numpy as np

np.random.seed(2018)
np.random.beta(2, 5, 10)
#array([ 0.18094173,  0.26192478,  0.14055507,  0.07172968,  0.11830031,
#        0.1027738 ,  0.20499125,  0.23220654,  0.0251325 ,  0.26324832])

Here we draw numbers from a Beta(2, 5) distribution

enter image description here

The Beta distribution is a very versatile and fundamental distribution in statistics; without going into any details, by changing the parameters alpha and beta you can make the distribution left-skewed, right-skewed, uniform, symmetric etc. The distribution is defined on the interval [0, 1] which is consistent with what you're after.


A more technical comment

While the Kumaraswamy distribution certainly has more benign algebraic properties than the Beta distribution I would argue that the latter is the more fundamental distribution; for example, in Bayesian inference, the Beta distribution often enters as the conjugate prior when dealing with binomial(-like) processes.

Secondly, the mean and variance of the Beta distribution can be expressed quite simply in terms of the parameters alpha, beta; for example, the mean is simply given by alpha / (alpha + beta).

Lastly, from a computational and statistical inference point of view, fitting a Beta distribution to data is usually done in a few lines of code in Python (or R), where most Python libraries like numpy and scipy already include methods to deal with the Beta distribution.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Generate a random even number inside a range?

From 5 dice rolls, generate a random number in the range [1 - 100]

Generate random number outside of range in python

Generate random number in range(java)

Generate random number in range in iOS?

Generate a random number, excluding a single number

Generate random number from custom distribution

Generate random numbers from lognormal distribution in python

Generate random number in range excluding some numbers

Generate each column of the numpy array with random number from different range

Generate a random number from normal distribution in J

Generate random numbers from exponential distribution and model using python

generate a random number in powershell from a range but exclude 1

Python - Generate random real number between range with a step size

How to generate a random number in a list from a range

Generate random bytearray from a distribution

How to generate different random number in a range in Swift?

Generate random variables from a probability distribution

How to generate random number 1 & 2 instead of 0 & 1 from binomial distribution?

How to generate a unique single random number each time in a loop in Python?

Generate random number belonging to exponential distribution

Generate random number in range with SecRandomCopyBytes

How to generate a random number within a range in D

Generate random date ranges where range size is decided from discrete distribution

Generate a random number with a seed between a range in ruby

Python generate random permutations of number in range

Generate random numbers from a normal distribution

Generate random numbers from a distribution given by a list of numbers in python

Generate secure random number in range Swift