Hierarchical GP

models that might help me work through adapting the code above?

There are a lot of different ways you could go with this. All depends on what you’re trying to do. Questions like vector[??] sigma_group; can only be answered by the application, really :D.

The most basic hierarchical GP looks something like what you have:

//... data and such... Maybe build some covariance matrices

parameters {
  vector[N] offset[G];
  vector[N] mu;
}

model {
  mu ~ multi_normal(rep_vector(0, N), Sigma);
  offset ~ multi_normal(rep_vector(0, N), Sigma);

  for(g in 1:G) {
    y[g] ~ normal(mu + offset[g], sigma);
  }
}

So the mu is the shared GP, and then the data for each group (whatever that is) is another GP offset from that.

From there probably the most common sorts of things you’d want to do are (in no particular order):

  1. Give every group it’s own covariance matrix
  2. Sample hyperparameters of the covariance matrices
  3. Work with non-centered parameterization

But it’s all a function of your problem. All the usual advice applies. Start simple and add on little pieces as you need them. Especially with GPs it makes sense to generate data to make sure you’ve got a handle on what you’re trying to fit.

1 Like