Gamma

Resources

  • https://discourse.mc-stan.org/t/output-for-family-in-brms/9379
  • https://discourse.mc-stan.org/t/decoding-smooth-fits-in-brms/34473
  • https://stats.stackexchange.com/questions/96972/how-to-interpret-parameters-in-glm-with-family-gamma
library(tidyverse)
library(brms)
library(posterior)
library(bayesplot)
library(ggdist)
library(patchwork)

color_scheme_set(scheme = "red")
theme_set(theme_ggdist())

prior_pred_lines <- function(post) {
  map(.x = seq_len(nrow(post)),
    .f = function(ii, post){
      p_Intercept <- post$b_Intercept[ii]
      p_shape <- post$shape[ii]
      tibble(ii = ii,
             x = seq(0, 30, length.out = 100),
             y = dgamma(x, shape = exp(p_Intercept), rate = 1 / p_shape))
    }, post = post) |> 
  list_rbind()
}

Gamma distribution

Shape (\(\theta\)) and Scale (\(k\))

\[PDF(x)=\frac{1}{\Gamma(k)~\theta^k} x^{k - 1}~e^{-x/\theta}\]

Shape (\(\alpha = \theta\)) and Rate (\(\beta\))

\[PDF(x) = \frac{\beta^\alpha}{\Gamma(\alpha)} x^{\alpha - 1}~e^{-\beta x}\]

Inverse scale parameter = rate

\[\beta = \frac{1}{\theta} = \frac{1}{\alpha}\]

\[\bar{x} = \mu = \frac{\alpha}{\beta}\]

Data

set.seed(3475934)

x_mean <- 4
alpha <- 12
(beta <- alpha / x_mean)
[1] 3
n <- 1e4

GD <- tibble(x = rgamma(n, shape = alpha, rate = beta))