Skip to contents

weave turns noisy, gappy spatio-temporal count data — such as malaria cases reported by health facilities — into smooth estimates of the underlying rate. It fills in missing weeks and attaches an honest prediction interval to every estimate.

How it works

weave treats the counts as arising from a smooth latent surface that varies across space and time, modelled as a separable Gaussian process — a spatial kernel combined with a temporal kernel (periodic season × long-term drift). In three steps it:

  1. builds a quick rough estimate of the smooth signal behind the counts (per-site standardised log(1 + y) — the “plug-in field”);
  2. estimates the kernel hyperparameters — how fast counts decorrelate across space, within the season, and over the long term — by maximising the Gaussian-process marginal likelihood, kept fast by the kernel’s Kronecker structure; and
  3. predicts the latent rate at every site and week, conditioning on the observed cells (so gaps are genuinely interpolated rather than guessed) and combining rate uncertainty with Negative-Binomial count noise to form a 95% prediction interval.

Installation

You can install the development version of weave from GitHub with:

# install.packages("pak")
pak::pak("mrc-ide/weave")

Getting started

weave needs two inputs: obs_data, a data frame with columns id (site), t (a numeric time index whose differences encode real elapsed time, e.g. weeks since a reference) and y_obs (the count, NA where missing); and coordinates, giving each site’s id and lon/lat. If you are starting from one raw data frame, data_process() returns obs_data, coordinates and nt in exactly this shape. The workflow is then two calls — estimate the kernels, then predict:

library(weave)

prepared <- data_process(raw_data, facility_name)   # raw -> model-ready
obs_data    <- prepared$obs_data
coordinates <- prepared$coordinates
nt          <- prepared$nt

# 1. estimate the spatial + temporal kernel length-scales
#    (with missing weeks, refine = TRUE removes the gap-induced bias)
est <- infer_kernel_params(obs_data, coordinates, nt = nt, period = 52,
                           refine = TRUE)

# 2. predict the rate, fill the gaps, and attach a 95% prediction interval
pred <- gp_predict(obs_data, coordinates, hyperparameters = est,
                   nt = nt, period = 52, n_draws = 100)

pred has one row per site-week, with the posterior rate and a lower/upper prediction interval.

Learn more