From dc9e9e1e4ad97f9fc5219b8290dc3c4fe81e650b Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 8 Oct 2026 07:11:27 +0000 Subject: [PATCH 1/4] Add the Laplace distribution to the distributions page Defines the Laplace density, proves its mean and variance, and compares its tails with the normal using a figure and computed numbers. This is the prior that makes the lasso a MAP estimate. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01TCQ3dTUAunddrUWa3yTgyJ --- _subfiles/_def-laplace.qmd | 19 +++++++++++ _subfiles/_exm-laplace-vs-normal.qmd | 50 ++++++++++++++++++++++++++++ _subfiles/_sec-distributions.qmd | 14 ++++++++ _subfiles/_thm-laplace-moments.qmd | 38 +++++++++++++++++++++ inst/WORDLIST | 1 + 5 files changed, 122 insertions(+) create mode 100644 _subfiles/_def-laplace.qmd create mode 100644 _subfiles/_exm-laplace-vs-normal.qmd create mode 100644 _subfiles/_thm-laplace-moments.qmd diff --git a/_subfiles/_def-laplace.qmd b/_subfiles/_def-laplace.qmd new file mode 100644 index 00000000..18be31a1 --- /dev/null +++ b/_subfiles/_def-laplace.qmd @@ -0,0 +1,19 @@ +:::{#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 +(see @fig-laplace-vs-normal). +::: diff --git a/_subfiles/_exm-laplace-vs-normal.qmd b/_subfiles/_exm-laplace-vs-normal.qmd new file mode 100644 index 00000000..a7f0f008 --- /dev/null +++ b/_subfiles/_exm-laplace-vs-normal.qmd @@ -0,0 +1,50 @@ +:::{#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..beee10cc 100644 --- a/_subfiles/_sec-distributions.qmd +++ b/_subfiles/_sec-distributions.qmd @@ -806,6 +806,20 @@ 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/_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 From a5d8692c55cc4b01cb52622ce0e7081896a766e9 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 8 Oct 2026 07:14:46 +0000 Subject: [PATCH 2/4] Shorten the Laplace figure caption to satisfy the line-length lint Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01TCQ3dTUAunddrUWa3yTgyJ --- _subfiles/_exm-laplace-vs-normal.qmd | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/_subfiles/_exm-laplace-vs-normal.qmd b/_subfiles/_exm-laplace-vs-normal.qmd index a7f0f008..9a71828b 100644 --- a/_subfiles/_exm-laplace-vs-normal.qmd +++ b/_subfiles/_exm-laplace-vs-normal.qmd @@ -10,7 +10,9 @@ 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-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 From aa53b23a29be8db20f744d206960c896bfa593e5 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 8 Oct 2026 08:32:08 +0000 Subject: [PATCH 3/4] Add a Laplace density example directly after the definition Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01TCQ3dTUAunddrUWa3yTgyJ --- _subfiles/_exm-laplace-density.qmd | 22 ++++++++++++++++++++++ _subfiles/_sec-distributions.qmd | 4 ++++ 2 files changed, 26 insertions(+) create mode 100644 _subfiles/_exm-laplace-density.qmd 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/_sec-distributions.qmd b/_subfiles/_sec-distributions.qmd index beee10cc..cc53fb0c 100644 --- a/_subfiles/_sec-distributions.qmd +++ b/_subfiles/_sec-distributions.qmd @@ -812,6 +812,10 @@ three times the variance of a $\Pois(4)$ count with the same mean. {{< slidebreak >}} +{{< include pds/_subfiles/_exm-laplace-density.qmd >}} + +{{< slidebreak >}} + {{< include pds/_subfiles/_thm-laplace-moments.qmd >}} {{< slidebreak >}} From 96a54c1060db5230b7d07a503e16873058c6a7c8 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 8 Oct 2026 09:02:24 +0000 Subject: [PATCH 4/4] Remove the forward reference to the Laplace figure from the definition remark Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01TCQ3dTUAunddrUWa3yTgyJ --- _subfiles/_def-laplace.qmd | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/_subfiles/_def-laplace.qmd b/_subfiles/_def-laplace.qmd index 18be31a1..1a13ce54 100644 --- a/_subfiles/_def-laplace.qmd +++ b/_subfiles/_def-laplace.qmd @@ -14,6 +14,5 @@ $$\p(Y=y) \eqdef \frac{1}{2b} \ef{-\frac{\abs{y - \mu}}{b}}, \quad y \in \mathbb 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 -(see @fig-laplace-vs-normal). +but the Laplace density has a sharp peak at $\mu$ and decays more slowly in the tails. :::