# Bivariate transformation using CDF method

1. Dec 3, 2015

### rabbed

If I have the following relations:
X = sqrt(1-V^2)*cos(U)
Y = sqrt(1-V^2)*sin(U)
Z = V
where (-pi < U < pi) and (-1 < V < 1) are independent random variables, both with uniform distributions.
How do I use the CDF method to find X_pdf(x)?
X_pdf(x) =
X_cdf'(x) =
( P( X < x ) )' =
( P( sqrt(1-V^2)*cos(U) < x ) )' = ?

2. Dec 4, 2015

### haruspex

Can you see how to write that as a condition on V, and hence as an integral wrt u?

3. Dec 5, 2015

### rabbed

As a first step, is this correct?

( P( sqrt(1-V^2) < x/cos(U) ) )' =
( P( 1-V^2 < (x/cos(U))^2 ) )' =
( P( -1+V^2 > -(x/cos(U))^2 ) )' =
( P( V^2 > 1-(x/cos(U))^2 ) )' =
( P( |V| > sqrt(1-(x/cos(U))^2) ) )' =
( P( -V > sqrt(1-(x/cos(U))^2) OR V > sqrt(1-(x/cos(U))^2) ))' =
( P( V < -sqrt(1-(x/cos(U))^2) OR V > sqrt(1-(x/cos(U))^2) ))' = ?

Then i think i should make a 2D graph with V as Y-axis and U as X-axis, drawing:

V1 = sqrt(1-(x/cos(U))^2)
V2 = -sqrt(1-(x/cos(U))^2)

By solving 1-(x/cos(U))^2 < 0
i get that the functions are imaginary when
pi*n + arccos(x) < U < pi*n + arccos(-x) for some n
and real when
pi*(n-1) + arccos(-x) <= U <= pi*n + arccos(x) for some n
For there to be at least one real solution i need to limit (-1 <= x <= 1)

I think the volume i should be calculating is a double integral of the joint distribution
of U and V, which is 1/(1-(-1)) * 1/(pi-(-pi)) = 1/(4*pi)?
And i should get the integration limits by solving some inequality using the 2D graph?

Sorry for my bad skills, my only source is the internet :)

Last edited: Dec 5, 2015
4. Dec 5, 2015

### haruspex

fine up to there, went a bit wrong after that.
But now use that V has a uniform distribution on (-1,1).
You will need to do something with the U, though, Bringing in an integral involving u, the value of U.

5. Dec 5, 2015

### rabbed

Sorry, i'm lost :(
Do you mean that the expression 1-(x/cos(U))^2 also has uniform distribution on (-1,1) and if I evaluate the integral of the expression on U/u within those limits it would equal 1?
Is the graphing i described above another way to do this or have i misunderstood that?

6. Dec 5, 2015

### haruspex

No.
Suppose the value of U is in (u, u+du). You can write down the probability of that. Now 1-(x/cos(u))^2 is just a value, and you know from the uniform distribution of V the probability that |V| exceeds that.
You need to consider, in a sense, all the possible values of U, the probability (density) of that value, and the probability of the value of V meeting that condition. Then you sum these up (integrate).
For any two r.v.s X, Y, $P(Y>X)=\int P(Y>x).dF_X(x)$.

7. Dec 7, 2015

### rabbed

Ok, my interpretation of what you said:

P(u < U < u+du) = U_cdf(u+du)-U_cdf(u) = U_pdf(u)*du

P(|V| > sqrt(1-(x/cos(U))^2)) = 1-V_cdf(sqrt(1-(x/cos(U))^2)) =
1 - integral wrt v from -1 to sqrt(1-(x/cos(U))^2) of V_pdf(v) =
1 - (1/2*(sqrt(1-(x/cos(U))^2)) - 1/2*(-1)) =
1/2*(1 - sqrt(1-(x/cos(U))^2))

integral wrt u from -pi to pi of
1/2*(1-sqrt(1-(x/cos(U))^2)) * U_pdf(u)*du =
1/(4*pi)*(1-sqrt(1-(x/cos(U))^2)) * du

that integral gave me a nasty result.. :)

what am i calculating? the joint probability that U=u and V=v in the relation X = sqrt(1-V^2)*cos(U)?

8. Dec 11, 2015

### rabbed

Hope someone can advice me how to proceed with this?

9. Dec 11, 2015

### haruspex

Sorry, I forgot to come back to this. Thanks for the nudge.
You have a few Us that should be u, but other than that you are on the right lines.
The integral is correct, but gives the CDF of X. You want the PDF. If you could solve the integral then you could find the PDF from the CDF, but there is another route. What can you do instead?

10. Dec 12, 2015

### rabbed

Thanks for coming back :)
I think you are referring to directly derivate the integral without evaluating the integral?

I first checked this page: http://www.mathmistakes.info/facts/CalculusFacts/learn/doi/doi.html
But I guess in this case it's different since I need to derivate a double integral?
I read something about Leibniz integral rule, is that what i should use?

Another thing is bugging me:
P(|V| > sqrt(1-(x/cos(U))^2)) = 1-V_cdf(sqrt(1-(x/cos(U))^2))
I think it's only valid to say that if we have V instead of |V| in the left hand side?
Graphing |y|>sqrt(1-(c/cos(x))^2) with c variable between -1 and 1 on this page: https://www.desmos.com/calculator
the area is both above and below the "circle", so I'm wondering if this is correct:

P(|V| > sqrt(1-(x/cos(U))^2)) =
P(V < -sqrt(1-(x/cos(U))^2) OR V > sqrt(1-(x/cos(U))^2)) =
P(V < -sqrt(1-(x/cos(U))^2)) + P(V > sqrt(1-(x/cos(U))^2)) =
V_cdf(-sqrt(1-(x/cos(U))^2)) + (1-V_cdf(sqrt(1-(x/cos(U))^2)))

with V_pdf(v) = 1/2 (-1 < v < 1) and by symmetry we get
V_cdf(-sqrt(1-(x/cos(U))^2)) = (1-V_cdf(sqrt(1-(x/cos(U))^2)))
so that
P(|V| > sqrt(1-(x/cos(U))^2)) = 2*(1-V_cdf(sqrt(1-(x/cos(U))^2))) ?

11. Dec 12, 2015

### haruspex

It's not a double integral, but yes, it's the Leibniz integral rule you need. The link you posted does not cover it.
So what integral do you get after differentiating? Can you solve it?
Wrt V and |V|, the easiest is to realise that you only care about |V|, and that is uniform on (0,1).

12. Dec 12, 2015

### rabbed

I was thinking it was double generally, including the integral wrt v also.

Hm, seems I failed somewhere:

I(x) = integral wrt u from -pi to pi of 1/(4*pi)*(1-sqrt(1-(x/cos(u))^2)) * du

I'(x) = d[I(x)]/dx =
integral wrt u from -pi to pi of d[1/(4*pi)*(1-sqrt(1-(x/cos(u))^2))]/dx * du =
integral wrt u from -pi to pi of x/(4*Pi*cos^2(u)*sqrt(1-(x/cos(u))^2)) * du =
[ -sqrt(1-(x/cos(u))^2)/(4*Pi) ] wrt u from -pi to pi =
-sqrt(1-(x/cos(pi))^2)/(4*Pi) + sqrt(1-(x/cos(-pi))^2)/(4*Pi) =
0

13. Dec 12, 2015

### haruspex

First, there's a step I missed out. We need to fix up the range of integration. When cos(u)<x the integrand (before differentiation) makes no sense. The probability of |V| being negative is zero, so the integration range should be truncated. Also, by symmetry, we only need to consider positive u. Cos(-u)=cos(u). This leads to an integration for the cdf from 0 to arccos(x) (which I'll call y below).
As a result, when differentiating, you get another term courtesy of the fundamental theorem of calculus. But that term is not an integral, so presents no difficulty.
This leaves us with the core issue of integrating $\int_0^y\frac{\sec^2(u).du}{\sqrt{1-x^2\sec^2(u)}}$.
sec2 plays nicely with tan, both directly and via calculus. So try t=tan(u).

14. Dec 14, 2015

### rabbed

Just to check that we're on the same page.

So first you made a change in the integral range wrt v:
P(|V| > sqrt(1-(x/cos(U))^2)) = 1-V_cdf(sqrt(1-(x/cos(u))^2)) =
1 - integral wrt v from 0 to sqrt(1-(x/cos(u))^2) of V_pdf(v) =
1 - [x/2] wrt v from 0 to sqrt(1-(x/cos(u))^2) =
1 - (sqrt(1-(x/cos(u))^2/2 - 0) = 1-1/2*sqrt(1-(x/cos(u))^2

And then you made a change in the integral range wrt u:
I(x) = integral wrt u from 0 to arccos(x) of 1/(4*pi)*(1-1/2*sqrt(1-(x/cos(u))^2) * du

Which gives us:
I'(x) = d[I(x)]/dx =
integral wrt u from 0 to arccos(x) of d[1/(4*pi)*(1-1/2*sqrt(1-(x/cos(u))^2)]/dx * du =
integral wrt u from 0 to arccos(x) of x*sec^2(u)/(8*pi*sqrt(1-(x/cos(u))^2)) * du

There is a mismatch between our integrals where I have x*sec^2(u) in the nominator, you only have sec^2(u).
Also I assume you moved the constant 8*Pi from the denominator outside the integral sign?

Meanwhile, I'm brushing up my integration skills..

15. Dec 14, 2015

### haruspex

You really will have to get into LaTeX.
Yes, I have an x in the numerator, but it's just a constant as far as the integral is concerned. Same with the pi etc.

16. Dec 15, 2015

### rabbed

17. Dec 15, 2015

### haruspex

I started again from the top and realised we need to be more careful about ranges.
By symmetry, we can restrict U to the range (0,pi/2) and V to the range (0,1). This will give the distribution for |X|.
Doing this, I found that the term that comes from the fundamental theorem of calculus cancels with another term, leaving only the integral:
$\frac 2{\pi}\int_{u=0}^{arccos(x)}\frac{x\sec^2(u).du}{\sqrt{1-x^2\sec^2(u)}}$
t = tan(u):
$\frac 2{\pi}\int_{t=0}^{\frac 1x\sqrt{1-x^2}}\frac{xdt}{\sqrt{1-x^2-x^2t^2}}$
s=xt/sqrt(1-x2):
$\frac 2{\pi}\int_{s=0}^1\frac{ds}{\sqrt{1-s^2}}$
s=sin(theta):
$\frac 2{\pi}\int_{\theta=0}^{\pi/2}1.d\theta = 1$
Sure enough, when I simulate it in a spreadsheet I see a uniform distribution.

18. Dec 15, 2015

### haruspex

I felt there should be a much simpler geometric path to the answer, and there is.
Using the method Archimedes employed to show that the surface area of a sphere is the same as that of the enclosing cylinder, we can see that the given distributions of U and V are equivalent to a uniform distribution over the surface of a sphere with coordinates X, Y and Z=V. Rotating the cylinder's axis around, it follows immediately that X and Y also have uniform distributions.

19. Dec 17, 2015

### rabbed

So you're saying that X_pdf(x) = Y_pdf(y) = Z_pdf(z) = 1/2?
That's awesome, thank you so much for your help!
I will try to calculate Y_pdf(y) by myself, just for the practice. This is one of the trickiest topics i've come across in math so far.
Thanks again!

20. Dec 17, 2015

### haruspex

The pdf of X would normally be written fX(x), etc., but yes. Did you understand the geometry argument? There should be some way to turn it into algebra, but I've not tried.

21. Dec 18, 2015

### rabbed

Yes I understand and it was also valuable. The goal was also to get a feel of a general way of deriving distributions than for just this specific geometry.
The hardest part (except the integration) seems to be to find the limits of the integrals. I'm not sure if graphing it would help and if that will work for all cases.
I'll check some more on my holiday.

Now, without having done the math it should be pretty safe to say that the component distributions would instead be 1/(2*R) if I would have these relations instead?
X = R*sqrt(1-V^2)*cos(U)
Y = R*sqrt(1-V^2)*sin(U)
Z = R*V

My next step is to get a better understanding of the Maxwell velocity distribution.

22. Dec 18, 2015

### haruspex

Yes.

23. Jan 4, 2016

### rabbed

Hi again

Can you say that the integration limits come both of the "outer limits" from the individual variables (-pi < U < pi) and (-1 < V < 1)
and also of the "inner limits" from the outline of the area(s)/volume(s) etc. described by P(f(U, V) < x), if those limits are within the "outer limits"?

24. Jan 4, 2016

### haruspex

No, I don't think that's right.
Consider a sphere cut through the middle by vertical plane Q. View this square on to Q, so the intersection appears as a vertical circle.
Put another vertical plane, R, through the middle of the sphere at an angle theta to Q. You will see this as an ellipse. Q and R intersect in a vertical diameter D of the sphere.
A value of Z picks out four points on the ellipse, all at the same distance (i.e. X) from D.
In the integrals, we ask the probability that X < some x, given theta. The form of the answer depends on whether x exceeds cos(theta). If it does, X < x no matter what the value of Z, so the probability =1; otherwise, the probability depends in a smoother way on theta.
So it would be more accurate to say that the complication in the limits comes from the interaction between the limits on the different variables.
It might help to consider a much simpler example. Suppose X and Y are U(0,1) and we define Z=XY. The range for X is (0,1), but if X=x<1 then as we vary Y the range for Z is only (0,x).

25. Jan 6, 2016

### rabbed

Ok, so sometimes you will have to chop up the answer in several parts?

Is this a correct(ish) procedure in general?
- In a coordinate system where each source RV is given an axis, visualize the source RV limits and also the line(s)/area(s)/volume(s) described by P(Z < z) where Z is the destination RV related to the source RV's by some function f.
- For each axis and its related source RV, use either the RV's limits or solve (f < z) for that RV to find integration-limit expressions that will enclose the line(s)/area(s)/volume(s) described by P(Z < z) in that axis, as you vary the variables in f or z that are not source RV's.
- If no general integration-limits could be found while varying the variables, the answer needs to be split up in several parts (unless you're only interested in a specific answer), each consisting of a different set of integration-limits for the source RV's.
- For a specific set of integration-limits, set Z_CDF(z) to be the product of each source RV's PDF-integral between that RV's integration-limits. Set Z_PDF(z) = d[Z_CDF(z)]/dz and use Leibniz integration rule to simplify.

I tried again to find an answer to the topic question using different integration-limits:

U_PDF(u) = 1/(2*pi)
V_PDF(v) = 1/2
X = sqrt(1-V^2)*cos(U)

X_CDF(x) = Re(integral wrt v from -1 to 1 of V_PDF(v) * (2 * integral wrt u from arccos(x/sqrt(1-v^2)) to pi of U_PDF(u)*du) * dv)
X_PDF(x) = Re(arcsin(1/sqrt(1-x^2))/pi) = 0.5

It gives the correct answer, but is the reasoning correct?

Share this great discussion with others via Reddit, Google+, Twitter, or Facebook