Is the log-likelihood computed in the stan model? If so, then the corresponding parameter name should be passed to extract_log_lik (a name such as A is not particularly informative). If not, you need to compute it in the generated quantities block, with something like this if it’s a linear regression model (adapt it for different models and for variable names you use):
generated quantities {
vector[N] log_lik;
for (n in 1:N) {
log_lik[n] = normal_lpdf(yt[n] | X[n] * beta, sigma);
}
}
Thank you for letting me know my misunderstand. I was wrong. I understand that I should substitute log-likelihood to the variable parameter_name in the function loo::extract_log_lik(), namely, I should substitute \{\log (f(y|\theta_i)\pi(\theta_i)) + \text{const};i=1,2,...,n\} where \{\theta_1,\theta_2,....\theta_n\} is a collection of posterior MCMC samples and f is a likelihood and \pi is a prior and y is a data-set.
In my model, dataset is a collection of non-negative integers y=\{(H_c,F_c) \in \mathbb{N} \times \mathbb{N};c=1,2,...,5\}, which is distributed by
lp__ is the log-posterior density up to a constant, and by extracting it you get one value per MCMC sample. But what you want is the log-likelihood of each observation at each MCMC sample, that’s why you need to compute it by hand.
I think your log-likelihood formulation is correct, now you need to express the maths in the stan model (all constants will be computed correctly when using the nomal_lpdf function and friends).
I understand that lp__ retains log likelihood values \{\sum_i L(y_i|\theta_k)\}_{ k=1,2,...}, but, the code of generated block should be write to provide \{ L(y_i|\theta_j)\}_{i, j=1,2,...} for each data y_i and MCMC samples \theta_j.
And “computed correctly” means the target+= as follows: