STAN code behind Brms cor_lagsar model

Hi

I look into the original STAN code of “cor_lagsar” in BRMS and have a question about formulating lpdf.

real normal_lagsar_lpdf(vector y, vector mu, real sigma,
                          real rho, data matrix W, data vector eigenW) {
    int N = rows(y);
    real inv_sigma2 = inv_square(sigma);
    matrix[N, N] W_tilde = add_diag(-rho * W, 1);
    vector[N] half_pred;
    real log_det;
    half_pred = W_tilde * y - mu;
    log_det = sum(log1m(rho * eigenW));
    return  0.5 * N * log(inv_sigma2) + log_det -
      0.5 * dot_self(half_pred) * inv_sigma2;
  }

All are clear, except for computing log density by " log_det = sum(log1m(rho * eigenW))“.
Why use “eigenW”, rather than the original W matrix, here?
I notice that the bounded spatial lag coefficient is defined in the data transformation part.

@paul.buerkner

Thanks in advance.
Charles L

I haven’t taken the time to read through and understand, but it appears the answer will likely be contained in this discussion:

Thank you very much! Problem solved

1 Like