---
title: Continuous random variables
heading: Densities, lifetimes and the exponential distribution
eyebrow: A11 · Lesson 14 · Continuous random variables
xp: 40
---

::: hook
A power supply is rated for a failure rate of one in ten years. What's the chance it lasts five? The time to failure isn't a count; it can be any positive number, and the chance of failing at exactly 3.000000 years is zero. Continuous quantities like lifetimes, noise voltages and arrival times need a different description: a density, whose area over a range gives the chance of landing there. The simplest useful one, the exponential, describes the lifetime of anything that fails at random with no wear-out, and the gaps between Poisson events.
:::

::: play
- Each draw is a lifetime from a part with constant failure rate $\lambda$ per year. The histogram fills in the exponential density, $\lambda e^{-\lambda t}$.
- The readouts compare the measured fraction surviving past $t_0$ with $e^{-\lambda t_0}$.
- Set $t_0$ to $1/\lambda$, the mean lifetime. Do half the parts survive that long? Fewer?
:::
:::

```sim plot
view: random
x: t = 0..30 years
slider: lam = 0.05..1 step 0.01 = 0.1 /year
slider: t0 = 0..30 step 0.5 = 5 years
sample: -ln(1 - rand(1))/lam | mean: M
trials: 20000
bins: 60
density: lam*exp(-lam*t)
measure: step(t - t0) | name: P
marker: x = t0 | label: t0
readout: surviving past t0, measured = P | digits: 3
readout: e^(−λ t0) = exp(-lam*t0) | digits: 3
readout: mean lifetime, measured = M | digits: 3
```

::: predict
## A part fails at random with a mean lifetime of 10 years. What fraction of parts survive past 10 years?

- [ ] 50%
- [x] 37%
- [ ] 10%
- [ ] 0%: they all fail by their mean lifetime

::: reveal
37%: $e^{-1} = 0.368$. Most failures happen early, because at every moment the surviving parts fail at the same rate, and early on there are the most survivors. Half the parts are gone by $\ln 2 \times 10 = 6.9$ years, the median, well before the mean.
:::
:::

::: nameit
## Densities

A continuous random variable $X$ has a **probability density** $p(x)$: the chance of landing between $a$ and $b$ is the area

$$P(a < X < b) = \int_a^b p(x)\,dx$$

The density is never negative and has total area 1. Any single exact value has probability zero; only ranges have chance. The density itself can exceed 1, since it's chance per unit of $x$.

The **CDF** is $F(x) = P(X \le x) = \int_{-\infty}^x p(u)\,du$, rising from 0 to 1, and $p = F'$. Means and variances are integrals: $E[X] = \int x\,p(x)\,dx$ and $\text{Var}(X) = \int (x - \mu)^2p(x)\,dx$ (lesson 9).

## Uniform

Equally likely anywhere between $a$ and $b$: $p = \frac{1}{b - a}$ there. Mean $\frac{a + b}{2}$, variance $\frac{(b - a)^2}{12}$. An ADC's rounding error is uniform over one step $\Delta$, so its RMS is $\frac{\Delta}{\sqrt{12}}$.

## Exponential

With rate $\lambda$ (events or failures per unit time), for $t \ge 0$:

$$p(t) = \lambda e^{-\lambda t} \qquad F(t) = 1 - e^{-\lambda t} \qquad P(T > t) = e^{-\lambda t}$$

Mean $\frac{1}{\lambda}$, variance $\frac{1}{\lambda^2}$, median $\frac{\ln 2}{\lambda}$.

- **Reliability.** For a part with constant failure rate $\lambda$, $R(t) = e^{-\lambda t}$ is the chance of surviving to $t$, and $\frac{1}{\lambda}$ is the **mean time to failure** (MTTF). Rates are often quoted in FIT, failures per $10^9$ device-hours.
- **Gaps between Poisson events.** If events come at rate $r$, the wait to the next one is exponential with $\lambda = r$: no event in time $t$ means a Poisson count of zero, with chance $e^{-rt}$.
- **No memory.** $P(T > s + t \mid T > s) = e^{-\lambda t}$: a part that has survived so far is as good as new. That's right for random failures and wrong for parts that wear out, like electrolytic capacitors and fans.
:::

::: example
## A converter has a constant failure rate of 0.1 per year. What is the chance it survives 5 years? Its mean and median lifetimes?

::: solution
1. **Survival to 5 years.**
   $$\begin{aligned} R(5) &= e^{-0.1 \times 5} \\ &= 0.607 \end{aligned}$$
2. **Mean lifetime.**
   $$\frac{1}{0.1} = 10\ \text{years}$$
3. **Median lifetime.**
   $$\frac{\ln 2}{0.1} = 6.93\ \text{years}$$

**Answer:** it survives 5 years with chance 0.607; its mean lifetime is 10 years and its median 6.93 years.
:::
:::

::: example
## Packets arrive at random at 100 per second. What is the mean gap between them, and how often is a gap longer than 30 ms?

::: solution
1. **Mean gap.** The gap is exponential with $\lambda = 100$ s⁻¹:
   $$\begin{aligned} \text{mean} &= \frac{1}{100}\ \text{s} \\ &= 10\ \text{ms} \end{aligned}$$
2. **Gaps longer than 30 ms.**
   $$\begin{aligned} P(\text{gap} > 0.03\text{ s}) &= e^{-100 \times 0.03} \\ &= e^{-3} \\ &= 0.050 \end{aligned}$$
3. **What it means.** About one gap in twenty is three times the average or longer.

**Answer:** the mean gap is 10 ms, and 5% of gaps are longer than 30 ms.
:::
:::

::: example
## A 12-bit converter spans 0 to 4.096 V. Treating its rounding error as uniform over one step, what is its RMS value?

::: solution
1. **Step size.**
   $$\begin{aligned} \Delta &= \frac{4.096\ \text{V}}{4096} \\ &= 1\ \text{mV} \end{aligned}$$
2. **Error distribution.** The error is uniform on $\left[-\frac\Delta2, \frac\Delta2\right]$, with variance $\frac{\Delta^2}{12}$.
3. **RMS error.**
   $$\frac{\Delta}{\sqrt{12}} = 0.289\ \text{mV}$$
4. **What it means.** That's quantization noise, the floor that sets a converter's ideal SNR of about $6.02N + 1.76$ dB.

**Answer:** the RMS rounding error is 0.289 mV.
:::
:::

::: check
given: lam = 0.05 | 0.2; t = 2 | 5 | 10
answer: exp(-lam*t)
tolerance: 0.5%

## A part fails at random at a rate of {lam} per year. What is the chance it is still working after {t} years?

::: right
Right. $e^{-\lambda t}$ = {answer}.
:::

::: misses
- [1 - exp(-lam*t)] That's the chance it has failed by then.
- [1 - lam*t] That linear estimate only works when $\lambda t$ is small.
- [any] Not yet. $R(t) = e^{-\lambda t}$.
:::
:::

::: check
given: f = 100 | 500 | 2000
answer: 1e9/f
unit: h
tolerance: 0.5%

## A part has a failure rate of {f} FIT (failures per $10^9$ hours). What is its mean time to failure, in hours?

::: right
Right. $\lambda = f \times 10^{-9}$ per hour, so MTTF $= 1/\lambda$ = {answer}.
:::

::: misses
- [f*1e-9] That's the rate; the mean time is its reciprocal.
- [any] Not yet. MTTF $= 1/\lambda$.
:::
:::

::: check
given: m = 5 | 10 | 20
answer: m*ln(2)
tolerance: 0.5%

## Lifetimes are exponential with mean {m} years. By when has half the population failed?

::: right
Right. The median, $\frac{\ln 2}{\lambda} = m\ln 2$ = {answer} years.
:::

::: misses
- [m] The mean is longer than the median: the long tail pulls it up.
- [m/2] Solve $e^{-t/m} = \frac12$.
- [any] Not yet. Solve $e^{-\lambda t} = 0.5$.
:::
:::

::: check
given: lam = 0.1 | 0.2; t1 = 3 | 5; t2 = 2 | 4
answer: exp(-lam*t2)
tolerance: 0.5%

## A part with failure rate {lam} per year has already run {t1} years without failing. What is the chance it survives {t2} more?

::: right
Right. No memory: $e^{-\lambda t_2}$ = {answer}, as for a new part.
:::

::: misses
- [exp(-lam*(t1 + t2))] That's the chance a new part survives the whole time. Given it has survived {t1} years, only the next {t2} matter.
- [any] Not yet. Use the conditional probability; the exponential has no memory.
:::
:::

::: check
given: a = 1 | 2 | 4
answer: 3/a^3
tolerance: 0.5%

## A density is $p(x) = cx^2$ for $0 \le x \le \given{a}$ and zero elsewhere. What must $c$ be?

::: right
Right. The area $\frac{ca^3}{3}$ must be 1: $c = \frac{3}{a^3}$ = {answer}.
:::

::: misses
- [1/a^3] Integrate $x^2$: the area is $\frac{ca^3}{3}$.
- [any] Not yet. Set the total area to 1.
:::
:::

::: check
given: d = 1 | 2 | 4
answer: d/sqrt(12)
unit: mV
tolerance: 0.5%

## An ADC rounds to steps of {d} mV, so its error is uniform over one step. What is the RMS error?

::: right
Right. $\frac{\Delta}{\sqrt{12}}$ = {answer}.
:::

::: misses
- [d/2] That's the largest error; the RMS is smaller.
- [d^2/12] That's the variance; take its square root.
- [any] Not yet. A uniform spread of width $\Delta$ has variance $\Delta^2/12$.
:::
:::

::: check
kind: parts
given: N = 10 | 12 | 16; V = 3.3 | 5

## An $N$ = {N}-bit converter spans 0 to {V} V.

::: part
answer: V/2^N/sqrt(12)*1e6
unit: µV
tolerance: 0.5%

### What is the RMS quantization noise?

::: misses
- [V/2^N*1e6] That's one step; the uniform error's RMS is step$/\sqrt{12}$.
- [any] $\frac{\Delta}{\sqrt{12}}$.
:::
:::
:::

::: check
kind: derivation
vars: l = 0.01..2, t = 0..10

## A part has a constant failure rate $l$ per year.

::: step
answer: exp(-l*t)

### What is the chance it survives $t$ years?
:::

::: step
answer: 1/l

### What is its mean life?
:::

::: right
Right. The exponential distribution: memoryless, with mean $1/\lambda$.
:::
:::

::: explain
## Why is the probability of any single exact value zero for a continuous variable?

::: model
Probability comes from the area under the density over a range. A single point is a range of width zero, so its area is zero however tall the density is there. Only intervals have chance, and narrow ones have chance about $p(x)\,\Delta x$. That's also why the density can be bigger than 1: it's chance per unit of $x$, not a chance itself.
:::
:::

::: practice

::: check
given: lam = 2..20 int
answer: 1/lam
unit: s
tolerance: 0.5%

## Events come at random at {lam} per second. What is the mean wait between them, in seconds?

::: misses
- [lam] That's the rate.
- [any] $1/\lambda$.
:::
:::

::: check
given: lam = 0.5 | 2; t = 0.5 | 1
answer: 1 - exp(-lam*t)
tolerance: 0.5%

## A wait is exponential with rate {lam} per second. What is the chance it's shorter than {t} s?

::: misses
- [exp(-lam*t)] That's the chance it's longer.
- [any] The CDF, $1 - e^{-\lambda t}$.
:::
:::

::: check
given: a = 2 | 6; b = 10 | 12
answer: (b - a)^2/12
tolerance: 0.5%

## What is the variance of a variable uniform between {a} and {b}?

::: misses
- [(b - a)/sqrt(12)] That's the standard deviation.
- [any] $\frac{(b - a)^2}{12}$.
:::
:::
:::
