Error extracting log likelihood from rank ordered logit model

Hi, I try to follow Savage’s @James_Savage rank ordered logit approach to extract log-likelihood to calculate AIC or WAIC. The links to his approach is “https://khakieconomics.github.io/2018/12/27/Ranked-random-coefficients-logit.html”. However, I get the error when I write my code below saying rows of left-hand side does not match the row of the right-hand side at line(5). If I delete generated quantities, it runs correctly. Anybody can give me any suggestions?

generated quantities {
  vector[N] log_lik;
  for (n in 1:N) log_lik[n] = rank_logit_lpmf(rank_order[]| beta_individual[task_individual[n]]');
}

Hi @HCOKSTATE, one thing I notice is that your loop has for (n in 1:N) but on the right side there’s no n. I haven’t had a chance to go through all the code at the link, but my guess is that you need to index something on the right side with n also.

Hi thanks for response. That should be rank_logit_lpmf(rank_order| beta_individual[task_individual[n]]’. My typing mistake.

Do you also need rank_order[n]?

rank_order is a int in the code. So if I did that, stan would report error like No matches for:

rank_logit_lpmf(int, vector).

Can you post the full Stan program you are using here?

Ok from seeing this section in the model block

my first guess for generated quantities would be this:

generated quantities {
  vector[T] log_lik;
  for (t in 1:T) {
    vector[K] utilities; 
    utilities = X[start[t]:end[t]]*beta_individual[task_individual[t]]';
    log_lik[t] = rank_logit_lpmf(rank_order[start[t]:end[t]] | utilities);
  }
}
1 Like

That works! Thanks for you help!

1 Like