Assignment_5

Tom Detzel

3/4/2018


Q. 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.

A. We will conduct an experimental proof following Grimstead in Example 2.7 on pp. 55-56.

Below, we create two random uniform distributions using runif() in R, then plot the results and overlay the density in a lineplot. The area under each bar is the probability (relative frequency) of B or C falling in each interval [a,b] in [0,1]. The probabilities are uniform such that

\(f(x)\quad =\quad \begin{cases} 1,\ if\ 0\le x\le 1 \\ 0,\ otherwise \end{cases}\)

\(P(E)\ =\ \int _{ a }^{ b }{ 1dx\ =\ { x }_{ 0 }^{ 1 } } \ =\ 1-0\ =\ 1\\\)

\(P(E)\ =\int _{ 0 }^{ 1 }{ 1dx = b-a }\)

Recall that for \(f(x)\) to be a true probability distribution function, it must meet the conditions that:

\(1.\ f(x)\ ≥\ 0\ for\ all\ x\)

and

\(2. \int _{ a }^{ b }{ f(x)\ dx\ =\ 1 }\)

that is, the sum of all probabilities (area under the \(f(x)\)) must total to 1. Now examine our distributions.

# first, create two sets of random numbers in [0,1]
set.seed(1234)
B <- runif(10000, min=0, max=1)
C <- runif(10000, min=0, max=1)
# plot the frequency distributions
# overlay a line for the density function

plot.new()
par(mfrow=c(1,2))

histB <- hist(B, freq=F, col='lightblue', breaks=10, main="Density of Random Uniform Variable B")
         lines(density(B), col='red', lwd=3)
         
histC <- hist(C, freq=F, col='lightblue', breaks=10, main="Density of Random Uniform Variable C")
         lines(density(C), col='red', lwd=3)

We can use the dunif() function to check whether \(P(B) = 1\) and the punif() function to make sure probabilities are all greather than zero.

any(dunif(B)!=1)
## [1] FALSE
any(punif(B)<0)
## [1] FALSE


(a) Find the probability that B+C < 1/2.

A. Following Example 2.14 in Grimstead, we have the distribution function:

\({ F }_{ Z }(z)\ =\ P(Z≤z)\ =\ Area\ of\ { E }_{ Z }\)

\({ F }_{ Z }(z)=\begin{cases} 0,\quad if\quad z<0 \\ (1/2){ z }^{ 2 },\quad if\quad 0\le z\le 1 \\ 1-(1/2){ (2-z) }^{ 2 },\quad if\quad 1\le z\le 2\quad \quad \\ 0,\quad if\quad z>2 \end{cases}\)

And the density function is derived by differentiating:

\({ f }_{ Z }(z) =\begin{cases} 0,\quad if\quad z<0 \\ z,\quad if\quad 0\le z\le 1 \\ 2-z,\quad if\quad 1\le z\le 2\quad \quad \\ 0,\quad if\quad z>2 \end{cases}\)

Following our general formula, we use R to integrate \(f(z)\) for the interval [0,0.5]. In this case \(f(z) = 1/(1-0) = 1\).

# following the example in R help for integrate()
f <- function(x){x}
prob <- integrate(f, lower=0, upper=0.5)

A. The probability that B+C < 1/2 = 0.125.

We can check this mathematically dervied probability against frequencies in B+C. The probability is approximately as predicted.

length(which(B+C<0.5))*.0001
## [1] 0.1185
plot.new()
par(mfrow=c(1,2))
X <- B+C
hist(X, freq=FALSE, breaks=30, main='Probability Density, B+C', col='lightblue')
lines(density(X), col='red', lwd=3)

plot(ecdf(X), col='red', lwd=3, main="Cumulative Probability, B+C")



(b) Find the probability that BC < 1/2.

Following Grimstead Example 2.17 using the exponential density distribution:

\(f(x)\quad =\quad \begin{cases} { λe }^{ −λx },\quad if\quad x\ge 0 \\ 0,\quad if\quad otherwise \end{cases}\)

So our probability density function is \(-\frac { 1 }{ \lambda } log(x)\). We integrate in R:

f <- function(x) {-log(x)}
prob <-integrate(f, lower = 0, upper = 1/2)

A. The probability that BC < 1/2 = 0.8465736.

Because we have 10,000 values in X, we can easily check the proportion of values less than 0.5. This confirms our result.

length(which(B*C<0.5))*.0001
## [1] 0.8421
plot.new()
par(mfrow=c(1,2))
X <- B*C
hist(X, freq=FALSE, breaks=30, main='Probability Density, BC', col='lightblue')
lines(density(X), col='red', lwd=3)

plot(ecdf(X), col='red', lwd=3, main="Cumulative Probability, BC")

(c) Find the probability that |B-C| < 1/2.

Following the example of Grimstead 2.16, we have:

\({ F }_{ Z }(z)\ =\ P(Z≤z)\ =\ P(|B-C|≤z)\ =\ Area\ of\ { E }\)

\({ F }_{ Z }(z)\quad =\quad \begin{cases} 0,\quad if\quad z<0 \\ (1-(1-z)^{ 2 },\quad if\quad 0\le z\le 1 \\ 1,\quad if\quad z>1\quad \quad \end{cases}\)

\({ f }_{ Z }(z)\quad =\quad \begin{cases} 0,\quad if\quad z\le 0 \\ 2(1-z),\quad if\quad 0\le z\le 1 \\ 0\quad if\quad z>1\quad \quad \end{cases}\)

Again, we integrate over our probability density function, \(2 (1-x)\).

f <- function(x) {2*(1-x)}
prob <-integrate(f, lower = 0, upper = 1/2)

A. The probability that |B-C| < 1/2 = 0.75.

Again, we can check for consistency with our actual values.

length(which(abs(B-C)<0.5))*.0001
## [1] 0.7565
plot.new()
par(mfrow=c(1,2))
X <- abs(B-C)
hist(X, freq=FALSE, breaks=30, main='Probability Density, |B-C|', col='lightblue')
lines(density(X), col='red', lwd=3)

plot(ecdf(abs(B-C)), col='red', lwd=3, main="Cumulative Probability, |B-C|")


(d) Compute the probability that max{B,C} < 1/2.

A.I could not figure out how to derive the probability density function for the pairwise functions max{B,C} or min{B,C}. The math is beyond my abilities. However, plotting the distributions is revealing.

The plots (see below) show that min{B,C} is identical to |B-C| and that max{B,C} is the inverse, as expected. By deduction, probabilities can be derived from our earlier computations. But we can also check against our observed values. The probabilities are essentially the same. Computations use the same code we emplyed earlier to count values < 0.5)

\(P(min{B,C} < 0.5) =\) 0.7466

\(P(max{B,C} < 0.5) =\) 0.2486

plot.new()
par(mfrow=c(1,2))
X <- pmax(B,C)
hist(X, freq=FALSE, breaks=30, main='Probability Density, max{B,C}', col='lightblue')
lines(density(X), col='red', lwd=3)

plot(ecdf(X), col='red', lwd=3, main="Cumulative Probability, max{B,C}")

plot.new()
par(mfrow=c(1,2))
X <- pmin(B,C)
hist(X, freq=FALSE, breaks=30, main='Probability Density, min{B,C}', col='lightblue')
lines(density(X), col='red', lwd=3)

plot(ecdf(X), col='red', lwd=3, main="Cumulative Probability, min{B,C}")