Hi,
The data structure which I work is the following. There are J subjects each with n observations, where J=67 and n=5. I have fitted two models to the data and would like to compare the models for predictive accuracy and model selection, using the loo() and waic() functions in R’s loo package. The models have the following specifications:

Model 1: 5 of the estimated parameters are common to all subjects and 1 parameter estimated specific to each individual

Model 2: Assume there are two groups and each group has its own 5 estimated parameters. 1 parameter estimated specific to each subject in the data.
Currently, the computed log_like matrix is an SbynbyJ array. However, the loo() and waic() functions require an S by n log_likelihood matrix, where S is the number of MCMC samples and n is number of data, I was wondering what would be the best approach to structure the log_like matrix from Stan to pass into these function. Would it be better to compute an SbyJ matrix or an SbynJ matrix as below?
generated quantities {
real log_lik1[n_obs, J];
vector[n_obs*J]log_lik;
for (j in 1:J){
for (n in 1:n_obs){
log_lik1[n,j] = lognormal_lpdf(y_hat[n,j]log(y_new[n,j]),std);
}
}
log_lik = to_vector(log_lik1)
}
Or
generated quantities {
real log_lik1[n_obs, J];
vector[J]log_lik;
for (j in 1:J){
for (n in 1:n_obs){
log_lik1[n,j] = lognormal_lpdf(y_hat[n,j]log(y_new[n,j]),std);
}
log_like[j] = sum(log_lik1[,j]);
}
}
Thanks very much for the help