How to calculate log-likelihood for multivariate model with known covariance matrix for each id

Hello All,

I am wondering how to calculate log-likelihood value for loo comparison.

Here are some details about my model.

I have K IDs and each id has ni observations and I have predictors which vary by ID.

Marginal model is yi~N(Xibeta, ZiShi*Zi’+Si), Si is known covariance matrix.

I can think of two likelihoods, 1. Point wise log-likelihood (sum(ni) likelihood values) and 2. log-likelihood for each ID (K -likelihood values).

I appreciate if someone tell me which one makes sense and provide sample code if you have any?

Marimuthu

You want to break the log likelihoods down into the granularity at which you would do cross-validation. So in this case, it’s almost certainly going to be one log likelihood per ID. The fact that there’s a known covariance structure or other details of the model shouldn’t matter as long as you define the right log likelihood for the examples.

You can find examples in the loo documentation. The general structure will look like this:

generated quantities {
  vector[N] log_lik;
  for (id in 1:N_id) {
    log_lik[id] = ... however you calculate log likelihood per id ...
  }
}

Thank you, Bob.

Marimuthu