U-shaped Beta distribution

menahg

New Member
Hi,
I have a case in which I want to draw a random probability using beta distribution. I receive a value X between 1 and 5, and I want the probability becomes high if the value is very close to 1 or very close to 5. I thought to use beta distribution U-shaped with beta parameters a=b=0.5, as you can see in the following graph.

I got some help to draw it in R, here is the implementation in python:

Python:
import numpy as np
from scipy.stats import beta
import matplotlib.pyplot as plt
x = np.linspace(1,5,1000)
y= 1/4 * beta.pdf((x-1)/4,a=0.5,b=0.5)
plt.ylim(0,1)
plt.plot(x,y)

Attachments

• 10.1 KB Views: 1
Last edited:

staassis

Active Member
Use the fact that for X ~ Beta(a,b)

E[X] = a / (a + b),

Var[X] = a * b / [(a + b)^2 * (a + b + 1)].

katxt

Active Member
If you are happy working in Excel, =BETAINV(RAND(),0.5,0.5) will generate the random numbers.

Last edited:

menahg

New Member
Thanks all, I can generate values between 0 and 1.
My issue is how to generate values based on a given value. If the given value is close to 0 or close to 10, the generated probability from beta distribution is high?

katxt

Active Member
Sorry, I missed the 10. Try =BETAINV(RAND(),0.5,0.5,0,10) or just use the method you have and multiply the x value by 10.
Or were you wanting to draw the graph? kat

menahg

New Member
Hi, thanks a lot for your help.
I use scipy.stats.beta, so I have for example x = 3.5, how I can put this into the beta distribution, to say generate high probability (closer to one) or generate low (closer to 0) based on x either it's near 0 or 10?

I am not quite sure if BETAINV does the same?

katxt

Active Member
I'm not exactly sure what you mean by x = 3.5.
Do you want the height of the pdf graph at x = 3.5?
Do you want the area to the left of x = 3.5?
Do you want a random beta variable somewhere between 0 and 10 and if so, what does x = 3.5 mean?
As I see it, to generate random variables between 0 and 10 from a scaled beta(0.5, 0.5) you put in a random left area (probability) and the random x is returned.
kat

menahg

New Member
Hi,
Basically, I receive a value x between 0 and 10, and I want to generate a beta distribution based on the given value.

if x is closed to 0, then beta generates value close to 1
if x is closed to 10 then beta generates value close to 1

I hope I explained it clear?

Thank you

hlsmith

Less is more. Stay pure. Stay poor.
Jumping in to confuse things, so do you have a sample of 10 and 3.5 had the event, probably not? How is data generated? Just tell us about what you are doing?

katxt

Active Member
I suspect you might have the problem the wrong way round. The way that generating random numbers usually works is that you receive a number p from 0 to 1. From that you generate a number x (from 0 to 10 in this case.) If p is close to 0 then x is close to 0 and if p is close to 1 then x is close to 10. In addition, if you are generating beta numbers you get lots near 0 and 10, and fewer in the middle. In this case the question might be "if p = 0.35, what is x?" In this case, 2.73

menahg

New Member
Jumping in to confuse things, so do you have a sample of 10 and 3.5 had the event, probably not? How is data generated? Just tell us about what you are doing?
I only have a value(between 0 and 10 and it is computed in different event) and I want to get a beta distribution [0,1] based on that value, beta should give a probability that is larger on the edges.

menahg

New Member
I suspect you might have the problem the wrong way round. The way that generating random numbers usually works is that you receive a number p from 0 to 1. From that you generate a number x (from 0 to 10 in this case.) If p is close to 0 then x is close to 0 and if p is close to 1 then x is close to 10. In addition, if you are generating beta numbers you get lots near 0 and 10, and fewer in the middle. In this case the question might be "if p = 0.35, what is x?" In this case, 2.73
I want the beta should only generate between 0,1. I am asking the question but not sure if it will be possible to use beta distribution. Because beta distribution has U-shaped, I thought it might serve, as I want to get a large probability with values close to the edges.

Dason

It sounds like you have values between (0, 1) as you do with a beta distribution and you want to transform then into the range (a, b). If that's the case and you call your random value from the beta 'x' then simply apply the function f(x)=(x*(b-a) + a)

menahg

New Member
Thanks guys, and sorry for the confusion I made.
I will rephrase my question somehow, how to draw a beta distribution if I have the value of the mean?

Thanks

katxt

Active Member
OK. Try generating beta(0.35,0.65) for a mean of 0.35, then scale it as Dason suggests. (x10 in this case) or =BETAINV(RAND(),0.35,0.65,0,10) in Excel.

menahg

New Member
OK. Try generating beta(0.35,0.65) for a mean of 0.35, then scale it as Dason suggests. (x10 in this case) or =BETAINV(RAND(),0.35,0.65,0,10) in Excel.
What are the values of a and b?

menahg

New Member
The mean that I have is larger than 1, and I want to draw random value from a scaled beta distribution