# Probability

Now that we gather some data and extracted features from them in form of variables is time to do inference, or educated guess with the data that you have available. In order to do inference we need to first understand probability.

Consider probability as a measure of the likelihood that some event will occur. Where $$P(E)=0$$ means that the probability of this event to occur is "impossible" and $$P(E)=1$$ means that the event will occur with 100% chance.

Probability can be determined experimentally or theoretically

### Theoretically

Consider below a fair dice

$$P(E)=\frac{\text{Possible ways of E}}{\text{Number of possible outcomes}}$$

![](https://2109831662-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LvMRntv-nKvtl7WOpCz%2F-LvMRp9FltcwEeVxPYFs%2F-LvMRvu59e-KMuC6ysz7%2FDiceAllOptions.png?generation=1575572719968670\&alt=media)

Here the probability of tossing the six-sided fair dice and having the value 1 is

$$P(E=1)=\frac{1}{6}=16.7\%$$

On each toss only one value is possible (the dice only give one value at a time) and there are 6 possible values.

In order to make easier to find theoretical probabilities we may need to organize the data on tables or trees.

### Experimentally

$$P(E)=\frac{\text{number events occured}}{\text{number of trials}}$$

Consider that we rolled the dice 12 times with the results: 6,3,4,1,2,2,1,3,1,5,3,5

$$P(E=1)=\frac{3}{12}=25\%$$

Here the experimental value is wrong but as we do more experiments the experimental probability tends to reach the theoretical value.

## Some assumptions

Here we present some assumptions to guide you:

* Probability of A or B $$P(\text{A or B})=P(A)+P(B)-P(\text{A and B})$$
* Probability of A and B $$P(\text{A and B})=P(A).P(B)=P(A \cap B)$$
* Probability of A not happening $$P(\text{Not A})=1-P(A)$$
* The sum of all probabilities is always 1

Sometimes "OR" is substituted by the union symbol $$\cup$$ and the "AND" is substituted by the intersection symbol $$\cap$$

## Conditional Probability

What is the probability of rolling a dice and it's value is less than 4 (B) given that the value is a odd number(A). In other words:

$$P(B|A)$$

As the dice has 6 possible values (1,2,3,4,5,6) it's probability of having a value less than 4 (3,2,1) will be $$P(B)=\frac{3}{6}=0.5$$.

Now about the probability of just having an odd number (1,3,5) will be $$P(A)=\frac{3}{6}=0.5$$

$$P(B|A)=\frac{P(A \cap B)}{P(A)}$$

![](https://2109831662-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LvMRntv-nKvtl7WOpCz%2F-LvMRp9FltcwEeVxPYFs%2F-LvMRvu9xH9G-AJZ2zQg%2FCondProbSmall.png?generation=1575572719976299\&alt=media)

On this case the probability will be:

$$P(A \cap B)=\frac{2}{6}=0.333$$

$$P(A)=0.5$$

$$P(B|A)=\frac{P(A \cap B)}{P(A)}=\frac{0.333}{0.5}=0.666$$

## Dependence/Independence of events

It's important to define if the events has some kind of dependence or not because it will affect the way you calculate the probabilities.

* Independent events: One event does not affect the likelihood of the next event to occur.
* Dependent event: One event does affect the likelihood of the next event to occur.

### Dependent event example:

You have a deck of cards, you shuffle them, then you take one card, and leave it out of the deck, them you take another card again, what is the probability of both been jokers.

First a deck has 52 cards, plus 2 jokers

![](https://2109831662-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LvMRntv-nKvtl7WOpCz%2F-LvMRp9FltcwEeVxPYFs%2F-LvMRvuBEHQ9X5nWAnaw%2FCardsType.png?generation=1575572719925575\&alt=media)

![](https://2109831662-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LvMRntv-nKvtl7WOpCz%2F-LvMRp9FltcwEeVxPYFs%2F-LvMRvuDKWHpv60qYC86%2FCardsDeck.png?generation=1575572720196794\&alt=media)

So the probability of having a joker for the first time will be: (There are 2 jokers available on 54 cards)

$$P(\text{joker})=\frac{2}{54}=0.037$$

Now take the joker out of the deck, shuffle and take one card again... What is the probability of having another joker ...

Now you need to consider the fact that one joker is already out

$$P(\text{joker}_\text{again})=\frac{1}{53}=0.018$$

The complete probability will be:

$$P(\text{joker and joker})_\text{dependent}=P(\text{joker}).P(\text{joker}_\text{again})=\frac{2}{54}.\frac{1}{53}=\frac{1}{1431}$$

### Independent event example:

Now we do the same experiment but after we take the card you put it back again on the deck. On this case observe that the fact that we add the card back again make the events independent.

So the probability of having a joker for the first time will be: (There are 2 jokers available on 54 cards)

$$P(\text{joker})=\frac{2}{54}=0.037$$

Now we but the card again on the deck and shuffle. What is the probability of having the joker again

$$P(\text{joker})=\frac{2}{54}=0.037$$

The complete probability will be:

$$P(\text{joker and joker})_\text{independent}=P(\text{joker}).P(\text{joker})=\frac{2}{54}.\frac{2}{54}=\frac{1}{729}$$

## Random Variables

Random variables are any result of a stochastic system (random process) for example how many heads will occur in a series of 20 flips. The name variable is confusing is more like the output of a stochastic system. There are 2 types of random variables:

* Discrete: Example $$X = P(\text{head})$$
* Continuous: $$Y = \text{mass of random animal at the zoo}$$

Normally all the observations from a process with uncertainties are random variables.

Example: X = Number of heads after 3 flips of a coin, calculate:

* P(X=0)
* P(X=1)
* P(X=2)
* P(X=3)

Adding all possible outcomes of a fair coin tossed 3 times

| HHH | THH |
| --- | --- |
| HHT | THT |
| HTH | TTH |
| HTT | TTT |

On this case:

* $$P(X=0)=\frac{1}{8}$$
* $$P(X=1)=\frac{3}{8}$$
* $$P(X=2)=\frac{3}{8}$$
* $$P(X=3)=\frac{1}{8}$$

So as mention before X is the output of a probabilistic process. Now let's also draw the probabilistic distribution for X

![](https://2109831662-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LvMRntv-nKvtl7WOpCz%2F-LvMRp9FltcwEeVxPYFs%2F-LvMRvuH2HsSwP530mBy%2FProbDistribution.png?generation=1575572720002558\&alt=media)

## Probability Distribution

The probability distribution is a table, graph or function that describe all the probabilities for each possible outcome of a random process. Depending of the type of random variable the Probability distribution has different names:

* Probability mass function: If variable is discrete
* Probability density function: If variable is continuous.

All the values of a probability distribution are non-negative and sum to one.

The importance of the probability distribution is that you can easily infer information from it:

![](https://2109831662-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LvMRntv-nKvtl7WOpCz%2F-LvMRp9FltcwEeVxPYFs%2F-LvMRvuJy8zRr89JZSdO%2FProbDistStats.png?generation=1575572719980576\&alt=media)

* Mode: Gives you the most probable value, is the peak of the probability density function.
* Mean or expected value: Is the weighted average of the possible values, using their probabilities as their weights&#x20;
* Median: The value such that the set of values less/bigger than the median has a probability of one-half.

Also the probability density function tells something about the random process: For example let X be the outcome of a fair dice.

![](https://2109831662-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LvMRntv-nKvtl7WOpCz%2F-LvMRp9FltcwEeVxPYFs%2F-LvMRvuLqi1yyrA_E4Ga%2FFairFicePMF.png?generation=1575572719947437\&alt=media)

On this case it's clear that all possible outcomes are equally probable.

## Expected Value

The expected value is the average of a random variable. Or is a sum of the product between the random variable value and it's probability.

$$E[X]=\sum_{i=1}^{\infty} x_i.p_i$$

$$E[X]=\int_{-\infty}^{\infty} xf(x) dx$$

Example: Let X represent the outcome of a roll of a fair six-sided, calculate the expected value (or expectation) of X

$$E[X]=1.\frac{1}{6}+2.\frac{1}{6}+3.\frac{1}{6}+4.\frac{1}{6}+5.\frac{1}{6}+6.\frac{1}{6}=3.5$$

Another example given the following probability distribution of a discrete random variable X

| x    | 0    | 1    | 2    |
| ---- | ---- | ---- | ---- |
| p(x) | 0.16 | 0.48 | 0.36 |

## Joint probability distribution

The joint probability distribution is the probability space formed by 2 or more random variables.

![](https://2109831662-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LvMRntv-nKvtl7WOpCz%2F-LvMRp9FltcwEeVxPYFs%2F-LvMRvuQOT00WcIrl1Hf%2FJointProbDist.png?generation=1575572719977799\&alt=media)

Things that you can get from Joint probability distributions:

* Check if the variables are independent and get the marginal probability function
* Derive the joint distribution function
* Derive the conditional probability function, conditional expectations, and conditional variance
* Derive the joint expectation (Expected value of the product of 2 random variables]

## References:

* [https://www.youtube.com/watch?v=VqndHpCfUWA](https://www.youtube.com/watch?v=VqndHpCfUWA)
* [https://www.youtube.com/watch?v=JGeTcRfKgBo](https://www.youtube.com/watch?v=JGeTcRfKgBo)
* [https://www.youtube.com/watch?v=OvTEhNL96v0](https://www.youtube.com/watch?v=OvTEhNL96v0)
* [https://www.youtube.com/watch?v=Zxm4Xxvzohk](https://www.youtube.com/watch?v=Zxm4Xxvzohk)
* [https://www.khanacademy.org/math/probability/probability-geometry](https://www.khanacademy.org/math/probability/probability-geometry)
* [https://www.youtube.com/watch?v=H02B3aMNKzE](https://www.youtube.com/watch?v=H02B3aMNKzE)
* [https://www.youtube.com/watch?v=KT726O6gDZY](https://www.youtube.com/watch?v=KT726O6gDZY)
* [https://www.youtube.com/watch?v=jos1yBC\_L8E](https://www.youtube.com/watch?v=jos1yBC_L8E)
* [https://www.youtube.com/watch?v=Ws63I3F7Moc](https://www.youtube.com/watch?v=Ws63I3F7Moc)
* [https://www.khanacademy.org/computing/computer-science/informationtheory/moderninfotheory/v/a-mathematical-theory-of-communication?utm\_source=YT\&utm\_medium=Desc\&utm\_campaign=computerscience](https://www.khanacademy.org/computing/computer-science/informationtheory/moderninfotheory/v/a-mathematical-theory-of-communication?utm_source=YT\&utm_medium=Desc\&utm_campaign=computerscience)
* [https://www.khanacademy.org/math/statistics-probability](https://www.khanacademy.org/math/statistics-probability)
* [https://www.khanacademy.org/math/statistics-probability/random-variables-stats-library/discrete-and-continuous-random-variables/v/discrete-probability-distribution](https://www.khanacademy.org/math/statistics-probability/random-variables-stats-library/discrete-and-continuous-random-variables/v/discrete-probability-distribution)
* [https://www.youtube.com/watch?v=j\_\_Kredt7vY](https://www.youtube.com/watch?v=j__Kredt7vY)
* [https://en.wikipedia.org/wiki/Expected\_value](https://en.wikipedia.org/wiki/Expected_value)
* [https://en.wikipedia.org/wiki/Probability\_distribution](https://en.wikipedia.org/wiki/Probability_distribution)
* [https://en.wikipedia.org/wiki/Probability\_mass\_function](https://en.wikipedia.org/wiki/Probability_mass_function)
* [https://en.wikipedia.org/wiki/Probability\_density\_function](https://en.wikipedia.org/wiki/Probability_density_function)
* [https://www.youtube.com/watch?v=UrOXRvG9oYE](https://www.youtube.com/watch?v=UrOXRvG9oYE)
* [https://en.wikipedia.org/wiki/Likelihood\_function](https://en.wikipedia.org/wiki/Likelihood_function)
* [https://www.youtube.com/watch?v=DNcdvJFLgSM](https://www.youtube.com/watch?v=DNcdvJFLgSM)
