Non-centered parameterization with group-specific random effects?

Good evening,

This post considers the same program as found in my previous post, but looks to build on the vectorized code and non-centered parameterizations.

In that code, the model is specified such that the variance across elements within each group (here, items within family) is the same across all groups:

parameters {
...
  real<lower=0> sigma_item;
  vector[K] betai_offset;
...
transformed parameters{
...
  vector[K] betai;
  betai = family_mu[parent] + betai_offset*sigma_item; 
...
model { 
  betai_offset ~ normal(0,1);
...

I would like to specify the model so that variances are group-specific, e.g., vector [P] sigma_item . I have not seen in any of the posts here how to specify NCP when the variances are group-specific, and I am wondering how to do this.

Would an appropriate approach look something like this, where matrix[K,P] betai_offset is a diagonal matrix? …

parameters {
...
  vector [P]<lower=0> sigma_item;
  matrix[K,P] betai_offset;
...
transformed parameters{
...
  vector[K] betai;
  betai = family_mu[parent] + sigma_item*betai_offset; 
...
model { 
  betai_offset ~ normal(0,1);
...

if betai_offset needs to be a diagonal matrix, is there a clean way to specify this in the code?

Thank you for any suggestions.

I don’t really understand your model, but it seems that you just need to multiply each betaai_offset with the correct element of sigma_item, so you might need something like:

parameters {
...
  vector [P]<lower=0> sigma_item;
  vector[K] betai_offset;
...
transformed parameters{
...
  vector[K] betai;
  betai = family_mu[parent] + betai_offset .* sigma_item[parent]; 
...
model { 
  betai_offset ~ normal(0,1);
...

Note the .* operator which indicates element-wise multiplication (i-th element of result is simply the i-th element of betai_offset multipled by i-th element of sigma_item[parent]).
That is in contrast to * which defaults to matrix multiplication (or dot product for vectors). This might be confusing, becaus it is the exact opposite of R, where * defaults to element-wise multiplication and a special operator %*% is reserved for matrix multiplication.

2 Likes

Hello @martinmodrak,

I appreciate your comment - I think I was definitely overthinking and overcomplicating the proposed model. I will work through your suggestion with some simulated data, and once it is debugged post the code in full here. Perhaps it will provide more context, and also it may be helpful to folks in the future as well - in case anyone has a similar specification.

Thank you!
S