Joint Probability
Tags: devops, tutorial, datascience
Published: 2021-05-01 13:28:41

## Joint Probability Mass Function (PMF)
Remember that for a discrete random variable Xx, we define the PMF as PX(x)=P(X=x)PX(x)=P(X=x). Now, if we have two random variables Xx and Yy, and we would like to study them jointly, we define the joint probability mass function as follows:

The joint probability mass function of two discrete random variables Xx and Yy is defined as

PXY(x,y)=P(X=x,Y=y).PXY(x,y)=P(X=x,Y=y).
Note that as usual, the comma means "and," so we can write
PXY(x,y)=P(X=x,Y=y)=P((X=x) and (Y=y)).PXY(x,y) = P(X=x,Y=y) = P((X=x) and (Y=y)).
Let me explain in word. let say an event X could occur with different outcome and event Y could Occur with different outcomes. we might ask to find the probability of each one of the out come happened for any of the event X or Y. 
To find the probability of the outcome of any one of them is as easy as we find the normal probabilty. 
Example.
let say Event X is all about A fair dice and event Y is a coin. for event X we all know that the possible outcome are : 1,2,3,4,5,6. Now the examiner might now ask a logical question to define X. like asking the probability of gotten even number or prime.
Event Y is all about coin which can only give Head or Tail.So to find the probability of the two event seperately will not be a problem. the problem arises whent the question join the two event. Let us take a look at some examples

Example1
A balanced coin and a fair die were rolled once.
Let X be the event of a head and Y be the outcome of a roll
of a die.
(i) Obtain the marginal distribution of X and Y separately.
(ii) Obtain the joint probability density function for X and Y.
(iii) Show that events X and Y are independent.
 Solution.
 Remember I said it is important to know all possible outcome for an event before we even proceed to probability.
 Now we know that the nature of coin is either Head or Tail. same thing for die. rolling a die will give us 6 possible out come.
the table below show our positble result for the nature of coin we are using.

|Coin(X)|Head |Tail |
|-----|------|---------|

|Coin(X)|Head |Tail |
|-----|------|---------|
|Pr(X)|1/2|1/2

the table above shows that the prob. of an event X will always be 1/2.
Now let check for the Y outcome.

|Die(Y)|1 |2 |3|4|5|6|
|-----|------|---------|---------|---------|---------|---------|
|Pr(X)|1/6|1/6|1/6|1/6|1/6|1/6|

the Table above show the probability of each of the outcome for Y.
Now with the table it is very easy to find the probability of any each of them. But the problem is what if both Die and coin were toss together what are the possible outcome??? just think logically if I pick a die and coin I can get either H with(1-6) or Tail with (1-6). so my table look like this
ii. 
### Joint Value
|Die(Y)| |1 |2 |3|4|5|6|
|---|---|-----|-----|-----|---|------|---|
|Coin|Head|H1|H2|H3|H4|H5|H6|
| |Tail|T1|T2|T3|T4|T5|T6|

Can you see?? the table just show all the possible outcome if we join the two event together where H denote Head and T denote Tail. To construct Joint table is very easy just label the row as all possible out come for the firs event and the columns for all possible outcome for the second event and start matching them together. Now let's construct the probability table for Joint event.
### The Joint Probabilty
|Die(Y)| |1 |2 |3|4|5|6|
|---|---|-----|-----|-----|---|------|---|
|Coin|Head|1/12|1/12|1/12|1/12|1/12|1/12|1/12|
| |Tail|1/12|1/12|1/12|1/12|1/12|1/12|1/12|

You might wanna ask how will get 1/12 and I would say ask you how many total possible outcome do we have?? you will answer 12 looking at the Joint value table. and How many times does H1 appeared?? Yes 1, that give prob of 1/12.do the same thing for others. 

### what exactly the table is saying??
well it is telling you the probability of joining event Y and X when the outcome of X and Y are changing.
Recall PXY(x,y)=P(X=x,Y=y)
For Column3,
PXY(X=Head,Y=1) =1/12
PXY(X=Tail,Y=1) =1/12
For Column 4,
PXY(X=Head,Y=2) =1/12
PXY(X=Tail,Y=2) =1/12
etc.
So if you study the table and the result we can derived a formular that 
PXY(X=x,Y=y) =1/12 for all value of X=x, Y=y.
iii. Here we are to prove independent.
let me say the we said the two event are independent if and only if 
PXY(X=x,Y=y)= PX(X=x)* PY(Y=y)
what is meaning of that formula?? well the formula means the probability when we join the two event must equal to the product of the probability of the two event when seperate.
Now let's prove.
Pr(X=head) =1/2. (Probability of tossing Head)
Pr(Y=3)=1/6(Probility of geting 3 from a die)
PXY(X=head,Y=3)= 1/12 (from joint Prob table wheb X is Head and Die is 3 i.e H3)
Now let's check the condition for independent 
PXY(X=x,Y=y)= PX(X=x)* PY(Y=y) means independent.
1/2* 1/6=1/12. this is true.

let's check for another value
Pr(X=head) =1/2. (Probability of tossing Head)
Pr(Y=1)=1/6(Probility of geting 3 from a die)
PXY(X=head,Y=1)= 1/12 (from joint Prob table wheb X is Head and Die is 3 i.e H3)
Now let's check the condition for independent 
if PXY(X=head,Y=1)= PX(X=Head)* PY(Y=1) means independent.
1/2* 1/6=1/12. this is true.
Check for others by yourself when Y=2,4,5,6. you will see that it is true therefore X and Y are independent.

Marginal Distribution.

To calculate the Margingal Distribution of X and Y is quite simple if you understand Partially Differential Calculus.
Here is the logic :If you are to calculate for X just integrate with respect to y and consider x as constant.
If you are to calculate for Y just integrate with respect to x and consider y as constant.
Bellow picture show the important formula.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rwgoxuigpljojrzlulam.JPG)
The first formula is useful when you were ask to calculate the constant value. just solve and equate to 1.
second and third formula for calculating Marginal Distribution of x and Y respectively.
Example 2
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/83cy0z6wy7keawluib7n.JPG)
#### More Explanation:
for Marginal Distribution for X.
we differentiate with respect to y i.e dy.
x turn to xy (just like 3 will turn to 3y if you integrate)
2y turn to y^2 (i.e 2y^2/2).
then we can substitute the upper and lower limit with is the range given for y.

for Marginal Distribution for Y.
we differentiate with respect to x i.e dx.
2y turn to 2xy (just like 3 will turn to 3y if you integrate)
x turn to x^2/2.
then we can substitute the upper and lower limit with is the range given for x.i.e 0 and 1.

### How to Calculate Constant when it's not given
I need to tell you that when ever you are ask to find the constant just do something called double integration everythin equal to 1 and you can get your c
#### Example
Let the joint pdf of (X,Y) be given by
Fxy(x, y) = cxy^2 
0 ≤ x ≤ 2, 0 ≤ y ≤ 2
(i) Find the value of constant c.
(ii) Also obtain the marginal density function of X and Y
respectively.
#### Solution
to find the constant
Fxy(x, y)dydx =1
cxy^2dydx(limit=1,0 and 2,0)
we need to solve the integral one by one.
cxy^2dy = cxy^3/3 + C (with respect to y)
now substitute 1 and 0 then subtract.
cx(1)^3/3 -cx(0)^3/3
cx/3- 0= cx/3

But don't forget we are to do double integral so it remain dx.
cx/3 dx =cx^2/3* 2 = cx^2/6
remembeer the limit is (2,0 from the range.)
cx^2/6 =c(2)^2/6 - c(0)^2/6
2c/3 -0 =2c/3
But
Fxy(x, y)dydx =1
therefore, 2c/3=1 
by cross multiply
2c=3
c=3/2.
Now the now equation is 
Fxy(x, y) = 3xy^2/2

ii. we can easily find the marginal distribution for each by integrating with respect to x and y.

For X
3xy^2/2dy =3xy^3/2* 3  =xy^3/2
since y ranges from 0 to 2. 
therefore, x(2)^3/2 - x(0)^3/2
4x-0 = 4x.

For Y
3xy^2/2dx =3x^2y^2/2* 2  =3x^2y^2/4
since x ranges from 0 to . 
therefore, 3(1)^2y^2/4 - 3(0)^2y^2/4 = 3y^2/4.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kfdq7btduwnt15aul09m.JPG)
 I hope you could find this article helpful. you can chat me up on whatsapp(`07045225718 or 09153036869`) if you have any question or comment below.

Now you can try to do the exercise below: