Data 605 HW5: Probability Distribution
Please refer to the Assignment 5 Document.
1 Problem Set 1
Choose independently two numbers B and C at random from the interval [0,1] with uniform density. Prove that B and C are proper probability distributions. Note that the point (B,C) is then chosen at random in the unit square.
Find the probability that,
(a.) \(B+C < \frac{1}{2}\)
(b.) \(BC < \frac{1}{2}\)
(c.) \(\left | B-C \right | < \frac{1}{2}\)
(d.) \(max \left \{ B,C \right \} < \frac{1}{2}\)
(e.) \(min \left \{ B,C \right \} < \frac{1}{2}\)
1.1 General Ideas
Def2.1 Density Functions of Continuous Random Variables from our Introduction to Probability textbook
1.2 Proof
By the Def2.1, let \(X\) be a continuous real-valued random variable. The density function for \(X\) is a real-valued function \(f\) which satifies \[P(a\leq X\leq b) = \int_{a}^{b}f(x)dx \; \; \; \; \; \; \;\forall a,b\in \mathbb{R}\]
The general formula for the probability density function of the uniform distribution is known as \[f(x)=\frac{1}{b-a} \;\;\; for \;a\leq x\leq b\]
By substituting \(a=0\) and \(b=1\) into the above formula, we get
\[P(0\leq X\leq 1) = \int_{0}^{1}f(x)dx = \int_{0}^{1}\frac{1}{1-0}dx = \int_{0}^{1}1\; dx = 1-0=1\] Therefore, the total probability of this density function equals to 1 and it satifies the definition of probability.
The cumulative distribution function of \(X\) by definition is \(F_{X}(x)=P(X \leq x)\). Based on the above distribution formula, we have \[F_{X}(x) = P(X \leq x) = \int_{-\infty }^{x}f(x)dx = \int_{-\infty }^{x}1 \; dx = \left\{\begin{matrix}0, \;\;\;\;\;\;\;\;\; if\;\;\;x \leq 0\\ x, \;\;\; if\;\;0 \leq x \leq 1\\ 1, \;\;\;\;\;\;\;\;\; if \;\;\; x \leq 1\end{matrix}\right.\]
Since \(B\) and \(C\) are independently and randomly chosen from the interval \([0,1]\), we have \[F_{X}(B) = P(X \leq B) =B\] \[F_{X}(C) = P(X \leq C) =C\]
As all definitions and properties were able to apply to \(B\) and \(C\) and they are the cumulative distribution function of their own, I conclude that \(B\) and \(C\) are proper probability distributions.
1.3 Solve (a)
\(P(B+C < \frac{1}{2})\)
Graph 1a
Given that the point (B,C) is chosen at random in the unit square, let \(x\) be \(B\) and \(y\) be \(C\), we have
\[P(x+y<\frac{1}{2})\] \[= P(y < \frac{1}{2}-x)\] \[=\int_{0}^{1/2} \int_{0}^{1/2-x} f(x,y) \;dy\,dx\] \[=\int_{0}^{1/2} \int_{0}^{1/2-x} 1 \; dy\,dx\] \[=\int_{0}^{1/2} \frac{1}{2}-x\;dx\] \[=\left [ \frac{x}{2} - \frac{x^{2}}{2} \right ]^{\frac{1}{2}}_{0}\] \[=\frac{1}{4}-\frac{1}{4}\cdot\frac{1}{2}\] \[=\frac{1}{8}\]
We can also easily solve the question by looking at the graph, the probability = shaded area in green \[= \frac{(0.5)^{2}}{2}\] \[=\frac{1}{8}\]
Verifying the result using the codes below:
# setting up the inner function as 0*x+1 because integrate must take in a function with a variable
# `integrate` expects a vectorized function.
# the InnerFunc must accept a vector of inputs and produce a vector of function evaluations at those
# points, and the `Vectorize` function can be used to convert the InnerFunc to this form.
InnerFunc <- function(x) {0*x+1}
InnerIntegral <- Vectorize(function(y){integrate(InnerFunc,0,0.5-y)$value})
integrate(InnerIntegral, 0, 0.5)## 0.125 with absolute error < 1.4e-15
1.4 Solve (b)
\(P(BC < \frac{1}{2})\)
Graph 1b
Given that the point (B,C) is chosen at random in the unit square, let \(x\) be \(B\) and \(y\) be \(C\), we have
\[P(y < \frac{1}{2x})\]
\[= 1 - P(y > \frac{1}{2x})\]
\[= 1 - \int_{1/2}^{1} \int_{1/(2x)}^{1} 1 \;dy\,dx \]
\[=1 - \int_{1/2}^{1} 1-\frac{1}{2x} \;dx \]
\[=1 - (1-\frac{1}{2}) + \frac{1}{2}\cdot \left [ ln(x) \right ]^{1}_{1/2} \] \[=\frac{1}{2} + \frac{1}{2} \cdot (ln(1)-ln(\frac{1}{2})) \] \[=\frac{1}{2} + \frac{1}{2} \cdot (ln(1)-ln(1)+ln(2)) \] \[=\frac{1}{2} + \frac{ln(2)}{2}\] \[\approx 0.84657359\]
Verifying the result using the codes below:
# find the integral that is being deducted and minus it by 1
InnerFunc <- function(x) {0*x+1}
InnerIntegral <- Vectorize(function(y){integrate(InnerFunc,0.5/y,1)$value})
1-integrate(InnerIntegral, 0.5, 1)$value## [1] 0.8465736
1.5 Solve (c)
\(\left | B-C \right | < \frac{1}{2}\)
Graph 1c
Given that the point (B,C) is chosen at random in the unit square, let \(x\) be \(B\) and \(y\) be \(C\), we have
\[P(-\frac{1}{2} \leq x-y \leq \frac{1}{2})\]
\[= P(\,y<x+\frac{1}{2} \;\;\; \cap \;\;\; y>x-\frac{1}{2}) \;\;, for \;\;x,y\in \mathbb{[0,1]}\] \[=\int_{0}^{1/2} \int_{0}^{x+1/2} 1 \;dy\,dx + \int_{1/2}^{1} \int_{x-1/2}^{1} 1 \;dy\,dx\] \[= \int_{0}^{1/2} x+\frac{1}{2} \;dx + \int_{1/2}^{1} 1-x+\frac{1}{2} \;dx\] \[= \left [ \frac{x^{2}}{2}+\frac{x}{2} \right ]^{1/2}_{0} + \left [ \frac{3x}{2} - \frac{x^{2}}{2} \right ]^{1}_{1/2}\] \[= \frac{1}{8}+\frac{1}{4}+\frac{3}{2}-\frac{1}{2}-\frac{3}{4}+\frac{1}{8}\] \[= \frac{3}{4}\]
We can also easily solve the question by looking at the graph, the probability = shaded area in green \[=1 \cdot 1 - \frac{(\frac{1}{2})^{2}}{2} \cdot 2\] \[= 1 - \frac{1}{4}\] \[= \frac{3}{4}\]
Verifying the result using the codes below:
# there are two integrals
# first integral
InnerFunc1 <- function(x) {0*x+1}
InnerIntegral1 <- Vectorize(function(y){integrate(InnerFunc1,0,y+0.5)$value})
#integrate(InnerIntegral1, 0, 0.5)
# second integral
InnerFunc2 <- function(x) {0*x+1}
InnerIntegral2 <- Vectorize(function(y){integrate(InnerFunc2,y-0.5,1)$value})
#integrate(InnerIntegral2, 0.5, 1)
# solution
integrate(InnerIntegral1, 0, 0.5)$value + integrate(InnerIntegral2, 0.5, 1)$value## [1] 0.75
1.6 Solve (d)
\[max \left \{ B,C \right \} < \frac{1}{2}\]
Graph 1d
Given that the point (B,C) is chosen at random in the unit square, let \(x\) be \(B\) and \(y\) be \(C\), we have
\[P(x<\frac{1}{2} \;\; \cap \;\; y<\frac{1}{2})\] \[\int_{0}^{1/2}\int_{0}^{1/2} 1 \;dy\,dx\]
\[=(\frac{1}{2})^{2}\] \[=\frac{1}{4}\]
Verifying the result using the codes below:
InnerFunc <- function(x) {0*x+1}
InnerIntegral <- Vectorize(function(y){integrate(InnerFunc,0,0.5)$value})
integrate(InnerIntegral, 0, 0.5)## 0.25 with absolute error < 2.8e-15
1.7 Solve (e)
\[min \left \{ B,C \right \} < \frac{1}{2}\]
Graph 1e
Given that the point (B,C) is chosen at random in the unit square, let \(x\) be \(B\) and \(y\) be \(C\), we have
\[P(x<\frac{1}{2} \;\; \cup \;\; y<\frac{1}{2})\] \[\int_{0}^{1/2}\int_{0}^{1} 1 \;dy\,dx + \int_{1/2}^{1}\int_{0}^{1/2} 1 \;dy\,dx\]
\[=\frac{1}{2} + \frac{1}{2}\cdot(1-\frac{1}{2})\] \[=\frac{1}{4}\]
We can also easily solve the question by looking at the graph, the probability = shaded area in green \[= (\frac{1}{2})^{2} \cdot 3\] \[= \frac{3}{4}\]
Verifying the result using the codes below:
# there are two integrals
# first integral
InnerFunc1 <- function(x) {0*x+1}
InnerIntegral1 <- Vectorize(function(y){integrate(InnerFunc1,0,1)$value})
#integrate(InnerIntegral1, 0, 0.5)
# second integral
InnerFunc2 <- function(x) {0*x+1}
InnerIntegral2 <- Vectorize(function(y){integrate(InnerFunc2,0,0.5)$value})
#integrate(InnerIntegral2, 0.5, 1)
# solution
integrate(InnerIntegral1, 0, 0.5)$value + integrate(InnerIntegral2, 0.5, 1)$value## [1] 0.75