cumulative distribution of a sample from cumulative distribution

37 Views Asked by At

I have been searching for an answer of the following question (please forgive my ignorance in stats):

I have the following cumulative distribution function (CDF): $F(H\leq h)\begin{cases} \alpha_1(H-H_{o1}), & \text{if}\quad 0 \lt H \lt 3\\ \alpha_2(H-H_{o2}), & \text{if}\quad 3 \lt H \lt 7 \\ 4.3425, & \text{if}\quad H \gt 7 \end{cases}$

where $\alpha_1 = 0.15$, $\alpha_2=0.9$, $H_{o1}=-1.95$, and $H_{o2}=2.175$. Please note that the CDF at $F(7) \gt 1$, so I divide it by $4.3425$ as well as the $F(3)$. Now if I sample this CDF, that is I take $10^6$ random variables $R_X=(0,1)$ and get the corresponding $H$, should I expect the cumulative distribution of $H$ to follow the same $F(H\leq h)$ as above? The reason I am asking this is because when I compute the cumulative sum of all $H$ and make a histogram of that cumulative sum, my slopes $\alpha_1 \neq 0.15$ and $\alpha_2 \neq 0.9$. Would you expect that?

I do everything in python: I am not sure if I should post my code here but anyways you could copy and paste it and try it out if you use python!

    nobj = 10**6
#############################################################################
f1 = 0.17097; f2 = 1. - f1; alpha1 = 0.15; alpha2=0.9; ho1 = -1.949484 ; ho2 = 2.175086

h1 = np.linspace(0, 3,500)
h2 = np.linspace(3, 7,500,endpoint=True)

cdf1 = alpha1*(h1-ho1); cdf2 = alpha2*(h2-ho2)

p_h = lambda x,cdf,h : scipy.interp(x, cdf, h)
cnt = 0
hhh = np.zeros(nobj)

while cnt < int(nobj*f1):
    j = cdf1[0]   # first element of the array
    k = cdf1[-1]  # last element of the array
    r = j + (k - j)*np.random.rand()
    hhh[cnt] = p_h(r,cdf1,h1)
    cnt+=1

while cnt < int(nobj*f2):
    j = cdf2[0]   # first element of the array
    k = cdf2[-1]  # last element of the array
    r = j + (k - j)*np.random.rand()
    hhh[cnt] = p_h(r,cdf2,h2)
    cnt+=1

n,be = np.histogram(hhh, bins=1000)
Ncum = n.cumsum(dtype=float)
Ncum /= Ncum.max()

fig,ax = plt.subplots()
ax.bar(be[1:],Ncum,width = -0.007, align='edge')
ax.set_xlim([0.0,7.5])
ax.grid(which='Major',axis='y')
ax.set_xlabel(r'H$_r$'); ax.set_ylabel('Cumulative fraction')
plt.show()

I am really hoping to find the solution or answer here! Your help will be very much appreciated!