1. Concepts & Definitions
1.1. Example of random variables
1.2. Probability of events to random variables
1.4. Discrete uniform distribution of probability
1.5. Bernoulli distribution of probability
1.6. Binomial distribution of probability
1.7. Hypergeometrical distribution of probability
2. Problem & Solution
In statistics literature, the probability distribution function related to a random variable is often called the probability mass function (PMF), and there is a corresponding cumulative which is called the cumulative distribution function (CDF).
The probability density/mass function for discrete and continuous variables x could be mathematically defined by
where P(X = x) means the probability of discrete variable X assuming a specific value x, and fX (x) is the same for a continuous variable.
The cumulative distribution function for a discrete or continuous variable is mathematically defined by Eq.
where: FX (x) is the symbol for the cumulative probability function, P(.) is the probability mass function for a discrete variable, f (x) is the probability mass function for a continuous variable, and P(X = x) means the probability of variable X assume a specific value x.
Remember the results of the previous section's numerical example.
From the numerical example presented in the previous section, the following probabilities could be computed:
P( 1 <= X <= 2) = P(X = 1) + P(X = 2) = 0.375 + 0.375 = 0.75
P(X <= 2) = P(X = 0) + P(1 <= X <= 2) = 0.125 + 0.75 = 0.875
The next computational code shows employs the numerical example to illustrate the computation of the previous probabilities using Python syntax.
import pandas as pd
ph = 0.5
pt = 1-ph
p3 = ph*ph*ph
p2 = 3*ph*ph*pt
p1 = 3*ph*pt*pt
p0 = pt*pt*pt
data = [p0, p1, p2, p3]
rows = ['p']
cols = [0, 1, 2, 3]
df = pd.DataFrame(data=[data], index=rows, columns=cols)
df
p12 = df.loc['p',1]+df.loc['p',2]
p012 = df.loc['p',0]+p12
print('P(1 <= X <= 2)',p12)
print('P(X <= 2)',p012)
P(1 <= X <= 2) = 0.75
P(X <= 2) = 0.875
The previous complete code is available in the following link:
https://colab.research.google.com/drive/1Ff287m5sDgyBNJwPpOe86SqAdEkCgdVR?usp=sharing