Generate fixed sum positive random numbers with a distribution (Scripts) Publisher's description
from Chris Choi
Intro: This function generates random samples for k Xi's where Xi>=0 and the sum Xi is fixed at g
Intro: This function generates random samples for k Xi's where Xi>=0 and the sum Xi is fixed at g. We assume that X's are independent and follow an identical distribution with a CDF function myCDF(x) and an inverse CDF function myICDF(p). I needed a function that works for Xi>=0. So here it is. Within this function, we assumed that our pdf is a truncated norm that is defined where >=0.
Disclaimer: This function worked for me. (Saved a ton in simulation time.) But not sure it it is theoretically correct. I will give it more thoughts. Please let me know if you find any mistakes or possible improvements.
Theory: If you put this problem in the right perspective, it can be somewhat simple. Suppose that we have k Xi as descrived above. Based on our assupmtion, the probability
P[X1<=X2<=X3 ...<=Xk] is identical for any order, say P[Xk<=Xk-1<= ... <=X1]. Therefore, we can assume without loss of generality that
X1 <= X2 <= X3 <= ... <= Xk ( we can always suffle it later in a random
Now, consider selecting a number for Xk, the largest one.
Then Xk has to satisfy a certain condition such as Xk >= g/k and Xk <= g.
because if Xk < g/k, we have X1+X2+...Xk < g and Xk cannot be greater
than g because we get X1+X2+...Xk > g.
Select Xk conditionally where Xk >= g/k and Xk <= g according to its its conditional probability distribution. It is okay to do this? Doesn't it ruin probability? Of course not. Remember degree of freedom lecture from your underdraduate stat. (I have my fingers crossed.) Then, we can not proceed and select Xk-1 using its conditional probability where (g-Xk)/(k-1) <= Xk-1 <= min(g- Xk, Xk) and so forth. Now, all that we need to to is to continue and set X1 = g-X2-X3 ... - Xk. One more step left. Random shuffle it baby =)
System Requirements:MATLAB 7.6 (R2008a)
Program Release Status: New Release
Program Install Support: Install and Uninstall