---
title: "C21-22 Continuous Random Variables"
author: "David Housman"
format: docx
editor: visual
fig-width: 6
fig-height: 4
---

```{r}
#| message: false
#| warning: false
#| echo: false
library(tidyverse)
library(latex2exp)
```

## Concepts

$$\begin{array}{lll} \text{Type} & \text{Discrete} & \text{Continuous} \\  & & \\ \text{Example values} & 0, 1, 2, \ldots & (-\infty, \infty) \\  & & \\ \text{pdf}  & \text{probability distribution function} & \text{probability density function} \\  & f(x) \geq 0, \displaystyle\sum_{x=0}^{\infty} f(x) = 1 & f(x) \geq 0, \displaystyle\int_{-\infty}^{\infty} f(x) \, dx = 1 \\  & & \\ \text{cdf}  & F(x) = P(X \leq x) = \displaystyle\sum_{u=0}^{x} f(u) & F(x) = P(X \leq x) = \displaystyle\int_{-\infty}^{x} f(u) \, du \\  & f(x) = F(x) - F(x-1) & f(x) = F'(x) \\  & & \\ \text{Expectation} & E[X] = \displaystyle\sum_{x=0}^{\infty} x f(x) & E[X] = \displaystyle\int_{-\infty}^{\infty} x f(x) \, dx \end{array}$$

## Examples

1.  Spin a spinner. Let $X$ be the counter-clockwise angle from a specified line to the resting place of the arrow.

    a.  Find the probability density function and graph it.

    b.  Find the cumulative distribution function and graph it.

    c.  Find $P(X > 4\pi/3)$ and $P(X > 4\pi/3 \; | \; X > \pi/2)$.

    d.  Find the mean ($\mu$), variance ($\sigma^2$), and standard deviation ($\sigma$).

    e.  Mark the pdf graph with $\mu$, $\mu \pm \sigma$, $\mu \pm 2\sigma$, and $\mu \pm 3\sigma$.

    f.  Find $P(\mu-\sigma < X < \mu+\sigma)$, $P(\mu-2\sigma < X < \mu+2\sigma)$, and $P(\mu-3\sigma < X < \mu+3\sigma)$.

    g.  From the cdf graph and equation, find the quartiles.

2.  Throw a dart at a circular board of radius one foot, and assume that it lands at a random point distributed uniformly across the board. Let $R$ be the distance in feet from the center that the dart lands.

    a.  Find the cdf (it is easier to find this first) and pdf. Graph the two functions.

    b.  Find the mean and standard deviation.

    c.  From the pdf graph, estimate the probabilities of being within one, two, and three standard deviations from the mean, and then find these probabilities and compare with the empirical rule.

3.  Let $T$ be the lifetime of a certain type of light bulb assumed to have a unimodal, skewed right distribution with a mean of 1000 hours.

    a.  Find a reasonable pdf and cdf.

    b.  Find $P(T > 1000)$ and $P(T > 1000 \; | \; T > 900)$.

    c.  Interpret the previous two probabilities in words.

    d.  Calculate the standard deviation using R.

    e.  Compare this distribution with the empirical rule.

```{r}
f = function(x) {0.000004*x*exp(-0.002*x)}
plot(f, 0, 2000)
g = function(x) (x - 1000)^2 * f(x)
sigma2 = integrate(g, 0, Inf)$value
sigma = sqrt(sigma2)
sigma
```

```         
f.  ow long will at least 90% of the light bulbs last?
```

1.  On average, what would be the largest of four spins of the above described spinner? Write down a guess first.
