> ## Documentation Index
> Fetch the complete documentation index at: https://offthepace.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# bayesian_shrinkage

> Computes Bayesian shrinkage estimate from observed data and prior.

Computes Bayesian shrinkage estimate from observed data and prior. Normal-normal conjugate model: posterior\_mean = (n × observed + prior\_weight × prior\_mean) / (n + prior\_weight)

## Signature

```sql theme={null}
{{ bayesian_shrinkage(n_col, observed_col, prior_mean_expr, prior_weight) }}
```

## Arguments

| Argument          | Description                                                                       |
| ----------------- | --------------------------------------------------------------------------------- |
| `n_col`           | column name or expression for sample size (e.g., 'panel\_observations\_n')        |
| `observed_col`    | column name or expression for observed mean (e.g., 'observed\_coefficient')       |
| `prior_mean_expr` | expression for prior mean (e.g., '0' for a zero-centered prior, or a column ref)  |
| `prior_weight`    | numeric or expression for prior strength (e.g., '10' means 10 equivalent samples) |

## Returns

scalar expression composable in SELECT lists. Tolerates n=0 by returning NULL (via NULLIF), which is the correct behaviour for unobserved cells.

## Usage

```sql theme={null}
SELECT
      driver_id,
      {{ bayesian_shrinkage('sample_count', 'observed_skill', '0', '5') }} as shrunken_skill
    FROM panel_data
```
