4.2 A language for describing models
A clear model notation separates the likelihood from the linear model. Writing the model as a list of distributional assumptions and deterministic equations makes it easier to communicate, critique, and extend.
4.2.1 Model notation
The standard notation for a Bayesian model has two parts:
- Probability statements: Describe how the data are distributed and the priors on parameters.
- Deterministic statements: Describe how the parameters of the likelihood depend on predictors.
For a simple linear regression:
The first line is the likelihood: each observation is normally distributed around with standard deviation . The second line is the linear model: the expected value is a linear function of the predictor . The remaining lines are the priors.
4.2.2 Why this notation matters
This notation is powerful because:
- Transparency: Every assumption is explicit. You can see the likelihood, the linear model, and the priors at a glance.
- Modifiability: You can change any component independently. Swap the likelihood, add a predictor, change a prior.
- Generality: The same notation works for linear models, generalized linear models, multilevel models, and more.
- Communication: The notation is compact and unambiguous, making it easy to share models with others.
# Model notation in R: the rethinking package uses alist
# A simple linear regression model:
# y_i ~ Normal(mu_i, sigma)
# mu_i = alpha + beta * x_i
# alpha ~ Normal(0, 10)
# beta ~ Normal(0, 10)
# sigma ~ Uniform(0, 50)
# In rethinking notation:
# model <- alist(
# y ~ dnorm(mu, sigma),
# mu <- a + b * x,
# a ~ dnorm(0, 10),
# b ~ dnorm(0, 10),
# sigma ~ dunif(0, 50)
# )
# Demonstrate with simulated data
set.seed(42)
n <- 100
x <- runif(n, 0, 10)
y <- 2 + 1.5 * x + rnorm(n, sd = 2)
# Fit with lm (frequentist equivalent)
fit <- lm(y ~ x)
cat("Intercept (alpha):", round(coef(fit)[1], 3), "\n")
cat("Slope (beta):", round(coef(fit)[2], 3), "\n")
cat("Residual SD (sigma):", round(summary(fit)$sigma, 3), "\n")
# Plot
plot(x, y, pch = 16, col = "steelblue",
main = "Linear regression: y = alpha + beta * x",
xlab = "x", ylab = "y")
abline(fit, lwd = 2, col = "firebrick")4.2.3 Link functions
For generalized linear models (Chapter 9), we add a link function that maps the linear model to the parameter of the likelihood:
For example, for a binomial model with a logit link:
The link function ensures that the parameter stays in the valid range (e.g., for the binomial). We will study link functions in detail in Chapter 9.
# Demonstrate a link function: logit
# logit(p) = log(p / (1 - p))
# inverse logit: p = 1 / (1 + exp(-x))
x <- seq(-5, 5, length.out = 100)
logit_vals <- x
prob_vals <- 1 / (1 + exp(-x))
par(mfrow = c(1, 2))
plot(x, logit_vals, type = "l", lwd = 2, col = "steelblue",
main = "Logit link: logit(p) = alpha + beta * x",
xlab = "Linear predictor", ylab = "logit(p)")
abline(h = 0, lty = 2, col = "gray50")
plot(x, prob_vals, type = "l", lwd = 2, col = "firebrick",
main = "Inverse logit: p = 1/(1+exp(-x))",
xlab = "Linear predictor", ylab = "p")
abline(h = 0.5, lty = 2, col = "gray50")
abline(v = 0, lty = 2, col = "gray50")
par(mfrow = c(1, 1))The model is the map. The model notation is not just a way to write code. It is a map of your assumptions. Every line encodes a choice: the likelihood, the linear model, the priors. When you share this map with others, they can see exactly what you assumed and can critique or extend it. This is the opposite of black-box procedures that hide assumptions behind a function call. The model notation makes statistics a transparent, collaborative engineering practice.
Summary of Section 4.2
- Model notation separates likelihood, linear model, and priors into explicit statements.
- The notation is transparent, modifiable, general, and communicable.
- Link functions map the linear model to the likelihood parameter for generalized linear models.
- The model notation makes every assumption visible and critiquable.