Skip to content

geodalib / core/src / spatialEmpiricalBayes

Function: spatialEmpiricalBayes() ​

spatialEmpiricalBayes(baseValues, eventValues, neighbors): number[]

Defined in: core/src/mapping/rates.ts:240

Description ​

Compute the spatial empirical Bayes smoothed rates using a local reference rate for each observation.

For each location i, the reference mean (μi) is computed from its spatial window as:

μi=∑jwijOj∑jwijPj

The local prior variance (σi2) is estimated as:

σi2=∑jwijPj(rj−μi)2∑jwijPj−μi∑jwijPi/(ki+1)

where:

  • wij are binary spatial weights (1 for neighbors, 0 otherwise)
  • Oj are observed events in area j
  • Pj are populations at risk in area j
  • rj are crude rates in area j
  • ki is the number of neighbors of area i

Key differences from standard EB:

  1. Uses a local reference rate specific to each observation's spatial window
  2. Requires sufficient observations in the reference window for effective smoothing
  3. Block weights are useful to avoid irregularity in neighbor counts

Note: If the estimated variance is negative, it is set to zero as in standard EB.

Parameters ​

baseValues ​

number[]

The values of base variable (populations at risk, Pi).

eventValues ​

number[]

The values of event variable (observed events, Oi).

neighbors ​

number[][]

The list of neighbors for each location.

Returns ​

number[]

The spatial empirical Bayes smoothed rates.