---
title: "Math 151 - Probability Theory - Homework 5"
author: "your name here"
date: "Due: Friday, September 25, 2020, midnight PDT"
output: pdf_document
---
## Important Note:
You should work to turn in assignments that are clear, communicative, and concise. Part of what you need to do is not print pages and pages of output. Additionally, you should remove these exact sentences and the information about HW scoring below.
Click on the *Knit to PDF* icon at the top of R Studio to run the R code and create a PDF document simultaneously. [PDF will only work if either (1) you are using R on the network, or (2) you have LaTeX installed on your computer. Lightweight LaTeX installation here: https://yihui.name/tinytex/]
> Either use the college's RStudio server (https://rstudio.pomona.edu/)
or install R and R Studio on to your personal computer.
See: https://research.pomona.edu/johardin/math151f20/ for resources.
```{r warning=FALSE, comment=FALSE, message=FALSE, echo = FALSE}
knitr::opts_chunk$set(message=FALSE, warning=FALSE, fig.height=3, fig.width=5,
fig.align = "center")
```
### Assignment
#### 1: PodQ
Describe one thing you learned from someone in your pod this week (it could be: content, logistical help, background material, R information, etc.) 1-3 sentences.
#### 2: 3.2.4
Suppose that the pdf of a random variable $X$ is as follows:
$$ \begin{cases} f(x) = cx^2 & 1 \leq x \leq 2 \\ 0 & \hbox{ else } \end{cases}$$
a. Find the value of the constant $c$ and sketch the pdf.
b. Find the value of $P(X > 3/2)$.
#### 3: 3.2.11
Show that there does not exist any number $c$ such that the following function $f(x)$ would be a pdf: $$ \begin{cases} f(x) = \frac{c}{x} & 0 < x < 1 \\ 0 & \hbox{ else } \end{cases}$$
#### 4: 3.3.4
Suppose that the c.d.f. $F$ of a random variable $X$ is as given below (and in Figure 3.9 in DeGroot). Find each of the following probabilities:
```{r message=FALSE, warning=FALSE, echo=FALSE}
exes <- seq(-2,6, by=.001)
plot(exes, ifelse(exes<=-1, 0,
ifelse(exes<=0, 0.1,
ifelse(exes <=1, exes*.1 + .2,
ifelse(exes <=2, 0.3,
ifelse(exes <=3, 0.16*exes^2 - .5*exes + .66,
ifelse(exes <=4, .8,
ifelse(exes <=5, .0125*exes^3 - .0625*exes^2 + 1, 1))))))),
xlab="x", ylab="F(x)", type="l")
points(c(-1,0,3), c(0.1, 0.2, 0.8),pch=18)
abline(v=0)
abline(h=.4, lty=2)
abline(h=.6, lty=2)
abline(h=.8, lty=2)
abline(h=1, lty=2)
```
a. $P(X = -1)$.
b. $P(X < 0)$.
c. $P(X \le 0)$.
d. $P(X = 1)$.
e. $P(0 < X \le 3)$.
f. $P(0 < X < 3)$.
g. $P(0 \le X \le 3)$.
h. $P(1 < X \le 2)$.
i. $P(1 \le X \le 2)$.
j. $P(X > 5)$.
k. $P(X \ge 5)$.
l. $P(3 \le X \le 4)$.
#### 5: 3.3.6
Suppose that the c.d.f. of a random variable $X$ is as follows:
$$F(x) = \begin{cases} e^{x - 3} & x \le 3 \\ 1 & x > 3 \end{cases}$$
Find and sketch the pdf of $X$.
#### 6: 3.3.8
Suppose that a point in the $xy$-plane is chosen at random from the interior of a circle for which the equation is $x^2 + y^2 = 1$; and suppose that the probability that the point will belong to each region inside the circle is proportional to the area of that region. Let $Z$ denote a random variable representing the distance from the center of the circle to the point. Find and sketch the c.d.f. of $Z$. [Hint: the solution to this problem requires you to think about circles, it does not require any sophisticated integrals or other mathematical tricks.]
#### 7: R - Estimate $\pi$.
The goal of this problem is to use a uniform distribution and related probabilities to estimate the value of $\pi$. We are going to use two different random variables which we'll learn in more detail when we get to section 3.4 in DeGroot. You should be able to approach the problem visually / intuitively / computationally. We will solve it analytically (i.e., using integrals) after we have covered the material in chapter 3.4.
a. If $X$ and $Y$ both have uniform distributions on the interval [0,1] (i.e., on the unit square), what is the probability that one random $(X,Y)$ coordinate will fall in the circle centered at (1/2, 1/2)?
b. Use R to estimate the area of the circle of radius 1/2 with center at (1/2, 1/2) inside the unit square by choosing 1000 points at random. Compare your results with the true value of the area of the circle, and use your results to estimate the value of $\pi$. How accurate is your estimate? [Use a lot of points!]
**Sample R example**
Let's say that I want to estimate the area under $y=\frac{1}{x+1}$ in the unit square. I simulate random point, test whether it is under (i.e., inside) the curve, and keep the points that are within the area constraints.
The function `runif()` is short for `r`andom `unif`orm. It kind of looks like a logical questions as in: should you `run` the value `if()` something happens? But `runif()` is a function to generate **random uniform** values, it is *not* an if statement.
```{r}
set.seed(47) # what does set.seed mean? try: ?set.seed
nreps = 20
xval = runif(nreps,0,1)
yval = runif(nreps,0,1)
xval # remove when you understand runif, also try: ?runif
yval # remove when you understand runif, also try: ?runif
yval < 1/(xval+1) # remove after you understand this line
sum(yval < 1/(xval+1))
sum(yval < 1/(xval+1))/nreps
# by doing the integration, I see that my answer should be close to ln(2)
# up the reps (and remove the uneeded lines above!) to see if my method is close
log(2)
```