Level-k thinking and cognitive hierarchy — bounded rationality in strategic games

behavioral-gt
level-k
cognitive-hierarchy
bounded-rationality
Implement the level-k model and Camerer-Ho-Chong cognitive hierarchy for the p-beauty contest, simulate heterogeneous populations, and visualize convergence to Nash equilibrium as strategic sophistication increases.
Author

Raban Heller

Published

May 8, 2026

Modified

May 8, 2026

Keywords

level-k model, cognitive hierarchy, p-beauty contest, bounded rationality, Camerer, iterated reasoning

Introduction & motivation

Nash equilibrium assumes that all players are perfectly rational, that they correctly anticipate other players’ strategies, and that these beliefs are mutually consistent. In practice, people engage in limited depths of strategic reasoning. In laboratory experiments, subjects rarely iterate beyond a few levels of reasoning, even in games where the Nash equilibrium requires infinite iterative elimination of dominated strategies. The p-beauty contest (or “guess 2/3 of the average” game) starkly illustrates this: Nash equilibrium predicts that everyone guesses 0, but experimental data consistently shows a wide distribution of guesses centred around 20–35, suggesting that most players perform only 1–3 steps of strategic reasoning.

The level-k model, formalised by Nagel (1995) and developed further by Stahl and Wilson (1994) and Costa-Gomes and Crawford (2006), provides a structured framework for bounded rationality. It posits a hierarchy of player types: Level-0 (L0) players are non-strategic, typically modelled as randomising uniformly over available actions; Level-1 (L1) players best-respond to L0; Level-2 (L2) players best-respond to L1; and so on. Each level \(k\) player assumes everyone else is exactly one level below them — a strong but tractable assumption. In the beauty contest with \(p = 2/3\), L0 guesses 50 (the midpoint), L1 guesses \(50 \times 2/3 \approx 33.3\), L2 guesses \(33.3 \times 2/3 \approx 22.2\), and the sequence converges geometrically to the Nash equilibrium of 0.

Camerer et al. (2004) extended this with the cognitive hierarchy (CH) model, which relaxes the level-k assumption that each player believes everyone else is exactly one level below. Instead, a level-\(k\) player in the CH model correctly anticipates the distribution of players at levels \(0, 1, \ldots, k-1\) and best-responds to this mixture. The distribution of levels follows a Poisson distribution with parameter \(\tau\), which captures the average depth of reasoning in the population. When \(\tau\) is small, most players are L0 or L1; as \(\tau \to \infty\), the distribution shifts toward higher levels and the aggregate prediction converges to Nash equilibrium. Empirically, \(\tau \approx 1.5\) fits a wide range of experimental data across different games.

This tutorial implements both models for the p-beauty contest, simulates populations with heterogeneous reasoning depths, demonstrates how the aggregate guess distribution depends on \(\tau\), and shows the convergence to Nash equilibrium. The analysis highlights a deep insight: the gap between Nash predictions and observed behaviour is not random noise but reflects the structured distribution of strategic sophistication in the population.

Mathematical formulation

Beauty contest. \(n\) players simultaneously choose a number \(g_i \in [0, 100]\). The winner is the player whose guess is closest to \(p \cdot \bar{g}\), where \(\bar{g} = \frac{1}{n}\sum_i g_i\) and \(p \in (0, 1)\). The unique Nash equilibrium is \(g_i = 0\) for all \(i\).

Level-k model. Define the hierarchy of best responses:

\[ g_0 = 50, \quad g_k = p \cdot g_{k-1} = 50 \cdot p^k \quad \text{for } k \geq 1 \]

In general, \(g_k = 50 \cdot p^k \xrightarrow{k \to \infty} 0\), converging to the Nash equilibrium.

Cognitive hierarchy model. The fraction of players at level \(k\) follows a Poisson distribution:

\[ f(k \mid \tau) = \frac{e^{-\tau} \tau^k}{k!} \]

A level-\(k\) player believes the population consists only of levels \(0, 1, \ldots, k-1\), with normalised probabilities:

\[ g_k^{CH} = p \cdot \frac{\sum_{j=0}^{k-1} f(j \mid \tau) \cdot g_j^{CH}}{\sum_{j=0}^{k-1} f(j \mid \tau)} \]

The aggregate predicted guess is:

\[ \bar{g}^{CH}(\tau) = \sum_{k=0}^{\infty} f(k \mid \tau) \cdot g_k^{CH} \]

R implementation

# --- Parameters ---
p <- 2/3         # beauty contest multiplier
g0 <- 50         # L0 guess (midpoint)
K_max <- 15      # maximum level to compute

# --- Level-k model ---
level_k_guesses <- function(p, g0, K) {
  guesses <- numeric(K + 1)
  guesses[1] <- g0  # L0

  for (k in 2:(K + 1)) {
    guesses[k] <- p * guesses[k - 1]
  }
  names(guesses) <- paste0("L", 0:K)
  guesses
}

lk_guesses <- level_k_guesses(p, g0, K_max)
cat("=== Level-k Guesses (p = 2/3) ===\n")
=== Level-k Guesses (p = 2/3) ===
for (k in 0:8) {
  cat(sprintf("  L%d: %.4f\n", k, lk_guesses[k + 1]))
}
  L0: 50.0000
  L1: 33.3333
  L2: 22.2222
  L3: 14.8148
  L4: 9.8765
  L5: 6.5844
  L6: 4.3896
  L7: 2.9264
  L8: 1.9509
# --- Cognitive hierarchy model ---
ch_guesses <- function(p, g0, tau, K_max = 20) {
  # Poisson probabilities
  probs <- dpois(0:K_max, lambda = tau)

  # CH guesses: L0 is g0, Lk best-responds to the perceived mixture of 0..k-1
  g_ch <- numeric(K_max + 1)
  g_ch[1] <- g0

  for (k in 1:K_max) {
    # Weights for levels 0 to k-1 (normalised)
    w <- probs[1:k]
    w <- w / sum(w)
    # Expected average guess perceived by level k
    perceived_avg <- sum(w * g_ch[1:k])
    g_ch[k + 1] <- p * perceived_avg
  }

  names(g_ch) <- paste0("L", 0:K_max)
  list(guesses = g_ch, probs = probs)
}

cat("\n=== Cognitive Hierarchy Guesses (tau = 1.5) ===\n")

=== Cognitive Hierarchy Guesses (tau = 1.5) ===
ch_15 <- ch_guesses(p, g0, tau = 1.5, K_max = K_max)
for (k in 0:8) {
  cat(sprintf("  L%d: guess=%.4f, prob=%.4f\n", k, ch_15$guesses[k + 1],
              ch_15$probs[k + 1]))
}
  L0: guess=50.0000, prob=0.2231
  L1: guess=33.3333, prob=0.3347
  L2: guess=26.6667, prob=0.2510
  L3: guess=23.9080, prob=0.1255
  L4: guess=22.8375, prob=0.0471
  L5: guess=22.4725, prob=0.0141
  L6: guess=22.3662, prob=0.0035
  L7: guess=22.3399, prob=0.0008
  L8: guess=22.3342, prob=0.0001
# Aggregate prediction
aggregate_guess <- function(tau, p = 2/3, g0 = 50, K_max = 20) {
  ch <- ch_guesses(p, g0, tau, K_max)
  sum(ch$probs * ch$guesses)
}

cat("\n=== Aggregate CH Prediction vs tau ===\n")

=== Aggregate CH Prediction vs tau ===
for (tau in c(0.5, 1.0, 1.5, 2.0, 3.0, 5.0, 10.0, 50.0)) {
  agg <- aggregate_guess(tau)
  cat(sprintf("  tau=%5.1f: aggregate guess = %.4f\n", tau, agg))
}
  tau=  0.5: aggregate guess = 43.0969
  tau=  1.0: aggregate guess = 37.8372
  tau=  1.5: aggregate guess = 33.4995
  tau=  2.0: aggregate guess = 29.8066
  tau=  3.0: aggregate guess = 23.8121
  tau=  5.0: aggregate guess = 15.5011
  tau= 10.0: aggregate guess = 5.5558
  tau= 50.0: aggregate guess = 0.0000
# --- Population simulation ---
set.seed(42)
simulate_ch_population <- function(n_players, tau, p = 2/3, g0 = 50, K_max = 20) {
  ch <- ch_guesses(p, g0, tau, K_max)
  # Assign levels to players
  levels <- rpois(n_players, lambda = tau)
  levels <- pmin(levels, K_max)
  # Get each player's guess
  guesses <- ch$guesses[levels + 1]
  # Add small noise for realism
  guesses <- pmax(0, pmin(100, guesses + rnorm(n_players, 0, 2)))
  data.frame(player = 1:n_players, level = levels, guess = guesses)
}

cat("\n=== Simulated Population (n=1000, tau=1.5) ===\n")

=== Simulated Population (n=1000, tau=1.5) ===
sim_data <- simulate_ch_population(1000, tau = 1.5)
cat(sprintf("  Mean guess: %.2f\n", mean(sim_data$guess)))
  Mean guess: 33.98
cat(sprintf("  Median guess: %.2f\n", median(sim_data$guess)))
  Median guess: 32.13
cat(sprintf("  Target (2/3 * mean): %.2f\n", p * mean(sim_data$guess)))
  Target (2/3 * mean): 22.65
cat("  Level distribution:\n")
  Level distribution:
level_tab <- table(sim_data$level)
for (lev in names(level_tab)) {
  cat(sprintf("    L%s: %d players (%.1f%%)\n", lev, level_tab[lev],
              100 * level_tab[lev] / 1000))
}
    L0: 244 players (24.4%)
    L1: 341 players (34.1%)
    L2: 227 players (22.7%)
    L3: 125 players (12.5%)
    L4: 50 players (5.0%)
    L5: 10 players (1.0%)
    L6: 3 players (0.3%)

Static publication-ready figure

set.seed(123)
tau_values <- c(0.5, 1.5, 5.0)
sim_all <- lapply(tau_values, function(tau) {
  sim <- simulate_ch_population(2000, tau)
  sim$tau_label <- paste0("tau = ", tau)
  sim
}) |> bind_rows() |>
  mutate(tau_label = factor(tau_label, levels = paste0("tau = ", tau_values)))

p_static <- ggplot(sim_all, aes(x = guess, fill = tau_label)) +
  geom_histogram(binwidth = 3, alpha = 0.85, color = "white", linewidth = 0.2) +
  geom_vline(xintercept = 0, linetype = "dashed", color = "#D55E00", linewidth = 0.6) +
  annotate("text", x = 3, y = Inf, label = "NE = 0", vjust = 2,
           color = "#D55E00", size = 3) +
  facet_wrap(~tau_label, ncol = 3) +
  scale_fill_manual(values = okabe_ito[c(1, 3, 5)], guide = "none") +
  labs(title = "Guess distributions in the p-beauty contest (p = 2/3)",
       subtitle = "Cognitive hierarchy model: higher tau shifts guesses toward Nash equilibrium",
       x = "Guess", y = "Count") +
  theme_publication() +
  theme(strip.text = element_text(face = "bold"))

p_static
Figure 1: Figure 1. Distribution of guesses in the p-beauty contest (p=2/3) under the cognitive hierarchy model for three values of tau. With low tau (0.5), most players are L0 or L1 and guesses cluster around 33-50. With empirically calibrated tau (1.5), guesses spread across 15-50 with a peak near 25-35. With high tau (5.0), the distribution shifts toward lower guesses, approaching Nash equilibrium. Each histogram is based on 2000 simulated players. The red dashed line marks the Nash equilibrium at 0. Okabe-Ito palette.

Interactive figure

# Aggregate guess as function of tau
tau_seq <- seq(0.1, 15, by = 0.1)
convergence_data <- tibble(
  tau = tau_seq,
  aggregate_guess = sapply(tau_seq, aggregate_guess)
) |>
  mutate(text = paste0("tau = ", round(tau, 1),
                       "\nAggregate guess = ", round(aggregate_guess, 2)))

# Also show level-k sequence
lk_data <- tibble(
  level = 0:10,
  guess = lk_guesses[1:11]
) |>
  mutate(text = paste0("Level ", level, "\nGuess = ", round(guess, 2)))

# Combine into a two-panel interactive plot
p_conv <- ggplot(convergence_data, aes(x = tau, y = aggregate_guess, text = text)) +
  geom_line(linewidth = 1, color = okabe_ito[5]) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "grey50") +
  geom_point(data = tibble(tau = 1.5, aggregate_guess = aggregate_guess(1.5),
                            text = paste0("Empirical tau = 1.5\nGuess = ",
                                          round(aggregate_guess(1.5), 2))),
             color = okabe_ito[6], size = 3) +
  labs(title = "CH aggregate prediction converges to NE as tau increases",
       subtitle = "Orange dot = empirically estimated tau (1.5)",
       x = expression("Mean thinking depth " * tau),
       y = "Aggregate predicted guess") +
  theme_publication()

ggplotly(p_conv, tooltip = "text") |>
  config(displaylogo = FALSE, modeBarButtonsToRemove = c("select2d", "lasso2d"))
Figure 2

Interpretation

The level-k and cognitive hierarchy models provide a structured explanation for the persistent gap between Nash equilibrium predictions and observed behaviour in experiments. In the p-beauty contest with \(p = 2/3\), Nash equilibrium predicts everyone guesses 0, but the cognitive hierarchy model with the empirically calibrated \(\tau = 1.5\) predicts an aggregate guess around 27 — remarkably close to the 20–35 range typically observed in experiments with first-time players. The Poisson distribution at \(\tau = 1.5\) implies that about 22% of players are L0, 34% are L1, 25% are L2, and the remaining 19% are at higher levels. This matches the common experimental finding that the modal type is L1, with substantial fractions at L0 and L2, and few players reasoning beyond L3.

The convergence to Nash equilibrium as \(\tau \to \infty\) is theoretically reassuring: Nash equilibrium is the limiting case of the cognitive hierarchy when all players are infinitely sophisticated. But for realistic finite \(\tau\), the model makes sharply different predictions. A key insight from Camerer et al. (2004) is that the CH model, calibrated on one game, can predict behaviour across very different games using the same \(\tau\) — suggesting that strategic sophistication is partially a stable individual trait rather than being entirely game-specific.

The practical implications are significant for mechanism design and market design: if you assume Nash equilibrium behaviour when designing an institution, you may get systematically different outcomes because real agents reason at finite depth. Auction designers, platform architects, and policy-makers should consider how their mechanisms perform not just at Nash equilibrium but across the distribution of reasoning depths they expect in their population.

References

Camerer, Colin F., Teck-Hua Ho, and Juin-Kuan Chong. 2004. “A Cognitive Hierarchy Model of Games.” The Quarterly Journal of Economics 119 (3): 861–98. https://doi.org/10.1162/0033553041502225.
Costa-Gomes, Miguel A., and Vincent P. Crawford. 2006. “Cognition and Behavior in Two-Person Guessing Games: An Experimental Study.” American Economic Review 96 (5): 1737–68. https://doi.org/10.1257/aer.96.5.1737.
Nagel, Rosemarie. 1995. “Unraveling in Guessing Games: An Experimental Study.” American Economic Review 85 (5): 1313–26.
Stahl, Dale O., and Paul W. Wilson. 1994. “Experimental Evidence on Players’ Models of Other Players.” Journal of Economic Behavior & Organization 25 (3): 309–27. https://doi.org/10.1016/0167-2681(94)90103-1.
Back to top

Reuse

Citation

BibTeX citation:
@online{heller2026,
  author = {Heller, Raban},
  title = {Level-k Thinking and Cognitive Hierarchy — Bounded
    Rationality in Strategic Games},
  date = {2026-05-08},
  url = {https://r-heller.github.io/equilibria/tutorials/behavioral-gt/level-k-cognitive-hierarchy/},
  langid = {en}
}
For attribution, please cite this work as:
Heller, Raban. 2026. “Level-k Thinking and Cognitive Hierarchy — Bounded Rationality in Strategic Games.” May 8. https://r-heller.github.io/equilibria/tutorials/behavioral-gt/level-k-cognitive-hierarchy/.