Hierarchical Gaussian Filter (HGF) using brms

I would like to know if it’s possible to run hierarchical Gaussian filter models (1,2) with brms.

The model is nicely described here in Julia, and I am having trouble translating it to R.

I managed to translate the data simulation part (#it’s something):

library(tidyverse)

simulate_data <- function(n=100, k, w, z_var=1, y_var=1) {
  z_prev <- 0
  x_prev <- 0

  z <- rep(NA, n)
  v <- rep(NA, n)
  x <- rep(NA, n)
  y <- rep(NA, n)

  for(i in 1:n) {
    z[i] <- rnorm(1, z_prev, sqrt(z_var))
    v[i] <- exp(k * z[i] + w)
    x[i] <- rnorm(1, x_prev, sqrt(v[i]))
    y[i] <- rnorm(1, x[i], sqrt(y_var))

    z_prev <- z[i]
    x_prev <- x[i]
  }
  data.frame(index = 1:n, z=z, x=x, y=y)
}


simulate_data(100, k=1, w=0, z_var=1, y_var=1) |>
  pivot_longer(2:4) |>
  ggplot(aes(x = index, y = value, color = name)) +
    geom_line()

Created on 2022-10-05 by the reprex package (v2.0.1)

Any pointer or advice is welcome!

brms can fit regression-type models but not these types of Markovian learning models. I am not aware of existing HGF models in Stan, but for similar models check out the hBayesdm package.

1 Like