diff --git a/_subfiles/_def-laplace.qmd b/_subfiles/_def-laplace.qmd new file mode 100644 index 00000000..1a13ce54 --- /dev/null +++ b/_subfiles/_def-laplace.qmd @@ -0,0 +1,18 @@ +:::{#def-laplace} +#### Laplace distribution + +A random variable $Y$ has the **Laplace distribution** +with location parameter $\mu \in \mathbb{R}$ and scale parameter $b > 0$, +written $Y \sim \dLaplacef{\mu, b}$, +if $Y$ is continuous with [density](random-variables.qmd#def-pdf): + +$$\p(Y=y) \eqdef \frac{1}{2b} \ef{-\frac{\abs{y - \mu}}{b}}, \quad y \in \mathbb{R}$$ {#eq-laplace-pdf} + +::: + +::: {.remark .notes} +The [normal density](random-variables.qmd#def-normal) has the squared distance $(y - \mu)^2$ in its exponent. +The Laplace density has the absolute distance $\abs{y - \mu}$ instead. +Both densities are symmetric about $\mu$, +but the Laplace density has a sharp peak at $\mu$ and decays more slowly in the tails. +::: diff --git a/_subfiles/_exm-laplace-density.qmd b/_subfiles/_exm-laplace-density.qmd new file mode 100644 index 00000000..73c554e0 --- /dev/null +++ b/_subfiles/_exm-laplace-density.qmd @@ -0,0 +1,22 @@ +:::{#exm-laplace-density} +#### Laplace density values + +Let $Y \sim \dLaplacef{3, 2}$, so $\mu = 3$ and $b = 2$ (@def-laplace). +At the location, $\abs{y - \mu} = 0$, so the density is $\frac{1}{2b}$. +At a point $y = 5$, the distance is $\abs{5 - 3} = 2 = b$, so the density is $\frac{1}{2b}\ef{-1}$. +Here are both values: + +```{r} +#| label: laplace-density-values +#| code-fold: false +b <- 2 +c( + at_mu = 1 / (2 * b), + at_mu_plus_2 = exp(-1) / (2 * b) +) |> + round(3) +``` + +The density at $\mu + b$ is the density at $\mu$ times $\ef{-1}$, +and the same holds at $\mu - b$, because the density depends only on the distance from $\mu$. +::: diff --git a/_subfiles/_exm-laplace-vs-normal.qmd b/_subfiles/_exm-laplace-vs-normal.qmd new file mode 100644 index 00000000..9a71828b --- /dev/null +++ b/_subfiles/_exm-laplace-vs-normal.qmd @@ -0,0 +1,52 @@ +:::{#exm-laplace-vs-normal} +#### Laplace and normal tails with the same mean and variance + +A Laplace variable $Y \sim \dLaplacef{0, b}$ has variance $2b^2$ (@thm-laplace-moments). +Choosing $b = 1/\sqrt{2}$ gives variance $1$, +the same mean and variance as a standard normal. +@fig-laplace-vs-normal compares the two densities. +The Laplace density is higher at the center and in the far tails, +and lower in between. + +```{r} +#| label: fig-laplace-vs-normal +#| fig-cap: >- +#| Laplace and standard normal densities with the same mean (0) +#| and variance (1) +#| fig-alt: >- +#| Two symmetric curves over y from minus 4 to 4. The standard normal is a +#| smooth bell. The Laplace curve with the same variance peaks higher at 0 +#| with a sharp point, falls below the normal curve at moderate distances, +#| and stays above it in the far tails. +#| code-fold: true +b <- 1 / sqrt(2) +grid <- seq(-4, 4, length.out = 801) +dlaplace <- function(y, mu = 0, b = 1) exp(-abs(y - mu) / b) / (2 * b) +densities <- tibble::tibble( + y = rep(grid, times = 2), + distribution = rep(c("Laplace", "Normal"), each = length(grid)), + density = c(dlaplace(grid, b = b), dnorm(grid)) +) +ggplot2::ggplot(densities) + + ggplot2::aes(x = y, y = density, colour = distribution) + + ggplot2::geom_line() + + ggplot2::labs(colour = NULL) +``` + +The probability of landing more than $3$ standard deviations from the mean shows the difference in the tails. +For the Laplace distribution, +$\P(\abs{Y} > t) = \ef{-t/b}$, +because each tail has probability $\frac{1}{2}\ef{-t/b}$ by integrating @eq-laplace-pdf. + +```{r} +#| label: laplace-vs-normal-tails +#| code-fold: false +t <- 3 +c( + Laplace = exp(-t / b), + Normal = 2 * pnorm(-t) +) +``` + +The Laplace distribution puts about `r round(exp(-3 / b) / (2 * pnorm(-3)), 1)` times as much probability beyond $3$ standard deviations as the normal distribution does. +::: diff --git a/_subfiles/_sec-distributions.qmd b/_subfiles/_sec-distributions.qmd index f28bee9e..cc53fb0c 100644 --- a/_subfiles/_sec-distributions.qmd +++ b/_subfiles/_sec-distributions.qmd @@ -806,6 +806,24 @@ three times the variance of a $\Pois(4)$ count with the same mean. {{< slidebreak >}} +## The Laplace distribution {#sec-laplace} + +{{< include pds/_subfiles/_def-laplace.qmd >}} + +{{< slidebreak >}} + +{{< include pds/_subfiles/_exm-laplace-density.qmd >}} + +{{< slidebreak >}} + +{{< include pds/_subfiles/_thm-laplace-moments.qmd >}} + +{{< slidebreak >}} + +{{< include pds/_subfiles/_exm-laplace-vs-normal.qmd >}} + +{{< slidebreak >}} + ## Weibull distribution {#sec-weibull} :::{#def-weibull} diff --git a/_subfiles/_thm-laplace-moments.qmd b/_subfiles/_thm-laplace-moments.qmd new file mode 100644 index 00000000..e0b4875b --- /dev/null +++ b/_subfiles/_thm-laplace-moments.qmd @@ -0,0 +1,38 @@ +:::{#thm-laplace-moments} +#### Mean and variance of the Laplace distribution + +If $Y \sim \dLaplacef{\mu, b}$ (@def-laplace), then + +$$\E{Y} = \mu \quad \text{and} \quad \Var{Y} = 2b^2.$$ {#eq-laplace-moments} + +::: + +::: proof +Write $U = Y - \mu$. +By @eq-laplace-pdf, $U$ has density $\frac{1}{2b}\ef{-\abs{u}/b}$, +which is symmetric about $0$. + +For the mean, the integrand $u \cdot \frac{1}{2b}\ef{-\abs{u}/b}$ is an odd function, +so its integral over $\mathbb{R}$ is $0$. +Therefore $\E{U} = 0$, and $\E{Y} = \mu + \E{U} = \mu$. + +For the variance, $\Var{Y} = \Var{U} = \E{U^2}$ because $\E{U} = 0$. +The integrand $u^2 \cdot \frac{1}{2b}\ef{-\abs{u}/b}$ is even, +so + +$$ +\ba +\E{U^2} +&= 2 \int_0^\infty u^2 \frac{1}{2b} \ef{-u/b} \, du +&& \text{(even integrand)} \\ +&= \frac{1}{b} \int_0^\infty u^2 \ef{-u/b} \, du +&& \text{(multiplying the constants)} \\ +&= \frac{1}{b} \paren{2b \int_0^\infty u \ef{-u/b} \, du} +&& \text{(integration by parts; the boundary terms are $0$)} \\ +&= \frac{1}{b} \paren{2b \cdot b^2} +&& \text{(integration by parts again; the boundary terms are $0$)} \\ +&= 2b^2. +&& \text{(multiplying the constants)} +\ea +$$ +::: diff --git a/inst/WORDLIST b/inst/WORDLIST index bff6ee2b..548e761c 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -48,3 +48,4 @@ submodule subtype symlink uarto +dLaplacef