Gumbel distribution

Author
Affiliation

Beniamino Sartini

University of Bologna

Published

May 1, 2024

Modified

June 19, 2024

Setup
library(dplyr)
# required for figures  
library(ggplot2)
library(gridExtra)
# required for render latex 
library(backports)
library(latex2exp)
# Random seed 
set.seed(1)

1 Distribution function

Defining \(z = \frac{x - \mu}{\sigma}\), the distribution function is given by: \[ F(x; \mu, \sigma) = \exp(-\exp(-z)) \tag{1}\]

In R code:

\[ \begin{aligned} \text{pgumbel}({} & x, \; \text{mean} = 1, \; \text{scale} = 1, \\ & \text{log.p} = {\color{red}{\text{FALSE}}}, \\ & \text{lower.tail} = {\color{green}{\text{TRUE}}}, \\ & \text{invert} = {\color{red}{\text{FALSE}}}) \end{aligned} \]

Distribution
grid <- seq(-2, 4, 0.01)
par <- list(a = c(0, 0.9), b = c(0, 2.3), c = c(0, 3.1), d = c(0, 4.4), 
            e = c(0, 5.3), f = c(0, 6.3), g = c(0, 7.2), h = c(0, 8.4))
df_plot <- list()
for(i in 1:length(par)){
  df_plot[[i]] <- tibble(label = format(par[[i]][2], scientific=FALSE, digits = 3), 
                         mean = par[[i]][1], scale = par[[i]][2], 
                         x = grid, p = pgumbel(x, mean, scale))
}
bind_rows(df_plot) %>%
  ggplot()+
  geom_line(aes(x, p, color = label))+
  theme_bw()+
  labs(x = TeX("$x$"), y = TeX("$F(x;\\mu,\\sigma^2)$"), color = TeX("$\\sigma$: "))+
  theme(legend.position = "right")
Figure 1: Gumbel distribution function for different scale parameters.
pgumbel <- function(x, mean = 0, scale = 1, log.p = FALSE, lower.tail = TRUE, invert = 1){
  # Standardized value 
  z <- (x - mean)*scale
  # Gumbel
  p <- exp(-exp(-invert*z))
  if (!lower.tail) {
    p <- 1 - p
  }
  # Log-probability
  if (log.p) {
    p <- base::log(p)
  }
  return(p)
}
import numpy as np
def pgumbel(p, mean=0, scale=1, log_p=False, lower_tail=True, invert=1):
    # Standardized value 
    z = (x - mean)*scale
    # Gumbel
    p = np.exp(-np.exp(-invert*z))
    if not lower_tail:
      p = 1 - p
    # Log-probability
    if log_p:
      p = np.log(p)
    return p

2 Density function

Defining \(z = \frac{x - \mu}{\sigma}\), the distribution function is given by: \[ f(x; \mu, \sigma) = \frac{1}{\sigma} e^{z + e^{-z}} \tag{2}\]

In R code:

\[ \begin{aligned} \text{dgumbel}({} & x, \; \text{mean} = 1, \; \text{scale} = 1, \\ & \text{log.p} = {\color{red}{\text{FALSE}}}) \end{aligned} \]

Density
grid <- seq(-10, 10, 0.01)
par <- list(a = c(0, 0.9), b = c(0, 2.3), c = c(0, 3.1), d = c(0, 4.4), 
            e = c(0, 5.3), f = c(0, 6.3), g = c(0, 7.2), h = c(0, 8.4))
df_plot <- list()
for(i in 1:length(par)){
  df_plot[[i]] <- tibble(label = format(par[[i]][2], scientific=FALSE, digits = 3), 
                         mean = par[[i]][1], scale = par[[i]][2], 
                         x = grid, p = dgumbel(x, mean, scale))
}
bind_rows(df_plot) %>%
  ggplot()+
  geom_line(aes(x, p, color = label))+
  theme_bw()+
  labs(x = TeX("$x$"), y = TeX("$f(x;\\mu,\\sigma^2)$"), color = TeX("$\\sigma$: "))+
  theme(legend.position = "right")
Figure 2: Gumbel density function for different scale parameters.
dgumbel <- function(x, mean = 0, scale = 1, log.p = FALSE, invert = 1){
  # Standardized value 
  z <- (x-mean)/scale
  # Gumbel
  p <- (1/scale)*exp(invert*(z + exp(-z)))
  # Log-probability
  if (log.p){
    return(base::log(p))
  }
  return(p)
}
import numpy as np
def pgumbel(p, mean=0, scale=1, log_p=False, invert=1):
    # Standardized value 
    z = (x - mean)*scale
    # Gumbel
    p <- (1/scale)*np.exp(invert*(z + np.exp(-z)))
    # Log-probability
    if log_p:
        p = np.log(p)
    return p

3 Quantile function

\[ F^{-1}(p; \mu, \sigma) = \mu - \sigma \log(-\log(p)) \tag{3}\]

In R code:

\[ \begin{aligned} \text{qgumbel}({} & p, \; \text{mean} = 1, \; \text{scale} = 1, \\ & \text{log.p} = {\color{red}{\text{FALSE}}}, \\ & \text{lower.tail} = {\color{green}{\text{TRUE}}}, \\ & \text{invert} = {\color{red}{\text{FALSE}}}) \end{aligned} \]

qgumbel <- function(p, mean = 0, scale = 1, log.p = FALSE, lower.tail = TRUE, invert = 1) {
  # Log-probability
  if (log.p) {
    p <- exp(p)
  }
  if (!lower.tail) {
    p <- 1 - p
  }
  # Quantile 
  x <- mean - invert*scale*log(-log(p))
  return(x)
}
import numpy as np
def qgumbel(p, mean=0, scale=1, log_p=False, lower_tail=False, invert=1):
    # Log-probability
    if log_p: 
       p = np.exp(p)
    if not lower_tail: 
       p = 1 - p
    # Quantile 
    x = mean - invert*scale*np.log(-np.log(p))
    return x

4 Random generator

In general, given a random variable \(X \sim F_{X}\) following a certain distribution \(F_{X}\) and the correspondent quantile function \(F_{X}^{-1}\) (i.e. \(F_{X}^{-1}(F(X)) = X\)) it is possible to generate a random sample by simulating the grades. In steps:

  • Step 1.: simulate the grades \(u \sim \text{Unif}[0,1]\).

  • Step 2.: apply the quantile function of the desired distribution on the grades to obtain a simulations.

In R code:

\[ \begin{aligned} \text{rgumbel}({} & n, \; \text{mean} = 1, \; \text{scale} = 1, \\ & \text{invert} = {\color{red}{\text{FALSE}}}) \end{aligned} \]

rgumbel <- function(n, mean = 0, scale = 1, invert = 1){
  u <- runif(n, min = 0, max = 1)
  qgumbel(u, mean = mean, scale = scale, 
          log.p = FALSE, lower.tail = TRUE, invert = invert)
}
import numpy as np
def rgumbel(n, mean=0, scale=1, invert=1): 
    u = np.random.uniform(0, 1, n)
    x = qgumbel(u, mean = mean, scale=scale, 
                log_p=False, lower_tail=True, invert=invert)
    return x
Back to top

Citation

BibTeX citation:
@online{sartini2024,
  author = {Sartini, Beniamino},
  title = {Gumbel Distribution},
  date = {2024-05-01},
  url = {https://greenfin.it/statistics/distributions/gumbel.html},
  langid = {en}
}
For attribution, please cite this work as:
Sartini, Beniamino. 2024. “Gumbel Distribution.” May 1, 2024. https://greenfin.it/statistics/distributions/gumbel.html.