vendredi 5 mars 2021

Generate random numbers for a non-standard beta distribution

I need to generate random numbers wich follows a beta distribution with the following parameters. X between [0.2,2], mean = 0.60 and std = 0.15.

I already had this code but when I summarized the mean and the std of the generated vector they do not agree with the imput parameters. I am afraid that something is not working properly, can someone help?

This is the code:

ac,bc=0.2,2.0
mc,sc=0.6,0.15
mc = (mc-ac)/(bc-ac)
sc = (sc**2/(bc-ac)**2)**0.5
alpha_C_Crit = mc*(mc*(1-mc)/sc**2-1)
beta_C_Crit = (1-mc)*(mc*(1-mc)/sc**2-1)
C_crit= beta.rvs(alpha_C_Crit,beta_C_Crit,loc=0.2,scale=2.0,size=100000)

The summary of the generated vector C_crit.mean()=0.6445875200893583 (not close to 0.60) and C_crit.std()=0.16723411402825206 not that close to 0.15.

Thank you!




Aucun commentaire:

Enregistrer un commentaire