Section 5.3 Probability Functions
In the formulas below, we will presume that we have a random variable 5.2.1 X which maps the sample space S onto some range of real numbers R. From this set, we then can define a probability function f(x) which acts on the numerical values in R and returns another real number. We attempt to do so to obtain (for discrete values) P(sample space value s)=f(X(s)). That is, the probability of a given outcome s is equal to the composition which takes s to a numerical value x which is then plugged into f to get the same final values. For example, consider a random variable which assigns a 1 when you roll a 1 on a six-sided die and 0 otherwise. Presuming each side is equally likely, f(1)=16 and f(0)=56.Definition 5.3.1. Probability "Mass" Function.
Given a discrete random variable 5.2.1 X on a space R, a probability mass function on X is given by a function f:R→R such that:
For x∉R, you can use the convention f(x)=0.
Definition 5.3.2. Probability "Density" Function.
Given a continuous random variable X on a space R, a probability density function on X is given by a function f:R→R such that:
For x∉R, you can use the convention f(x)=0.
Example 5.3.3. Discrete Probability Function.
Consider f(x)=x/10 over R = {1,2,3,4}. Then, f(x) is obviously positive for each of the values in R and certainly
Therefore, f(x) is a probability mass function over the space R.
xxxxxxxxxx
# Combining all of the above into one interactive cell
def _(D = input_box([1,2,3,5,6,8,9,11,12,14],
label="[Domain] :",width=60),
Probs = input_box([1/20,1/20,1/20,3/20,1/20,4/20,4/20,1/20,1/20,3/20],
label=" $$[f(x)] :$$",width=60),
n_samples=slider(100,10000,100,100,label="$$ \\text{# of samples:}$$")):
n = len(D)
R = range(n)
one_huh = sum(Probs)
​
if one_huh!=1:
print("f(x) values do not sum to 1")
else:
G = Graphics()
if len(D)==len(Probs):
f = zip(D,Probs)
meanf = 0
variancef = 0
for k in R:
meanf += D[k]*Probs[k]
variancef += D[k]^2*Probs[k]
G += line([(D[k],0),(D[k],Probs[k])],color='green')
variancef = variancef - meanf^2
sd = sqrt(variancef)
G += points(f,color='blue',size=50)
G += point((meanf,0),color='yellow',size=60,zorder=3)
G += line([(meanf-sd,0),(meanf+sd,0)],color='red',thickness=5)
g = DiscreteProbabilitySpace(D,Probs)
pretty_print(" mean = %s"%str(meanf))
pretty_print(" variance = %s"%str(variancef))
# perhaps to add mean and variance for pmf here
else:
print("Domain and Probabilities Probs must be lists of the same size")
# sample from the distribution and see how a random sampling matches up
​
counts = [0] * len(Probs)
X = GeneralDiscreteDistribution(Probs)
sample = []
​
for _ in range(n_samples):
elem = X.get_random_element()
sample.append(D[elem])
counts[elem] += 1
Empirical = [1.0*x/n_samples for x in counts] # random
samplemean = mean(sample)
samplevariance = variance(sample)
sampdev = sqrt(samplevariance)
E = points(zip(D,Empirical),color='orange',size=40)
E += point((samplemean,0.005),color='brown',size=60,zorder=3)
E += line([(samplemean-sampdev,0.005),(samplemean+sampdev,0.005)],
color='orange',thickness=5)
(G+E).show(ymin=0,figsize=(5,4))
Example 5.3.4. Continuous Probability Function.
Consider f(x)=x2/c for some positive real number c and presume R = [-1,2]. Then f(x) is nonnegative (and only equals zero at one point). To make f(x) a probability density function 5.3.2, we must have
In this instance you get
Therefore, f(x) is a probability density function over R provided c=3.
Definition 5.3.5. Distribution Function.
Given a random variable X on a space R, a probability distribution function on X is given by a function
Example 5.3.6. Discrete Distribution Function.
Using f(x)=x/10 over R = {1,2,3,4} again, note that F(x) will only change at these four domain values. We get
X | F(x) |
x<1 | 0 |
1≤x<2 | 1/10 |
2≤x<3 | 3/10 |
3≤x<4 | 6/10 |
4≤x | 1 |
Example 5.3.8. Continuous Distribution Function.
Consider f(x)=x2/3 over R = [-1,2]. Then, for −1≤x≤2,
Notice, F(−1)=0 since nothing has yet been accumulated over values smaller than -1 and F(2)=1 since by that time everything has been accumulated. In summary:
X | F(x) |
x<−1 | 0 |
−1≤x<2 | x3/9+1/9 |
2≤x | 1 |
Theorem 5.3.10.
F(x)=0,∀x<inf(R) where inf is the infimum...the "minimum" but in a limit sense.
Proof.
Let a = inf(\(R\)). Then, for \(x \lt a,\)
since none of the x-values in this range are in \(R\text{.}\)
Theorem 5.3.11.
F(x)=1,∀x≥sup(R) where sup is the supremum...the "maximum" but in a limit sense.
Proof.
Let b = sup(\(R\)). Then, for \(x \ge b,\)
since all of the x-values in this range are in R and therefore will either sum over or integrate over all of \(R\text{.}\)
Theorem 5.3.12.
F is non-decreasing
Proof.
Case 1: \(R\) discrete
Case 2: \(R\) continuous
Theorem 5.3.13. Using Discrete Distribution Function to compute probabilities.
For x∈R,f(x)=F(x)−F(x−1)
Proof.
Assume \(x \in R\) for some discrete \(R\text{.}\) Then,
Theorem 5.3.14. Using Continuous Distribution function to compute probabilities.
For a<b,(a,b)∈R,P(a<X≤b)=F(b)−F(a)
Proof.
For a and b as noted, consider
Corollary 5.3.15.
For continuous distributions, P(X=a)=0.
Proof.
We will assume that \(F(x)\) is a continuous function. With that assumption, note
Take the limit as \(\epsilon \rightarrow 0^+\) to get the result noting that
Theorem 5.3.16. F(x) vs f(x), for continuous distributions.
If X is a continuous random variable, f the corresponding probability function, and F the associated distribution function, then
Proof.
Assume \(X\) is continuous and \(f\) and \(F\) as above. Notice, by the definition of \(f\text{,}\) \(\lim_{x \rightarrow \pm \infty} f(x) = 0\) since otherwise the integral over the entire space could not be finite.
Now, let \(A(x)\) be any antiderivative of \(f(x)\text{.}\) Then, by the Fundamental Theorem of Calculus,
Hence, \(F'(x) = A'(x) - \lim_{u \rightarrow -\infty} A'(u) = f(x)\) as desired.
Definition 5.3.17. Percentiles for Random Variables.
For 0<p<1, the 100pth percentile is the largest random variable value c that satisfies
For continuous random variables over an interval R=[a,b], you will solve for c in the equation
For discrete random variables, it is unlikely that a particular percentile will land exactly on one of the elements of R but you will want to take the smallest value in R so that F(c)≥p.
The 50th percentile (as before) is also known as the median.
Example 5.3.18. Continuous Percentile.
For our earlier example with f(x)=x2/3 on R = [-1,2], the 50th percentile (i.e. the median) is found by starting with p = 0.5 and then solving
or
or
After solving for c, you find
Example 5.3.19. Discrete Percentile.
TBA, using one of the table examples from above.