Hi all,

I want to use the loo package to obtain LOO for model comparison.

I am running a survival model written in Stan as follows. I got the looic value=233359 and the PSIS diagnostic plot is attached (iter=10000, warmup=5000, thin=10, N=34744, n_grid=1001, num=12 ,province=31).

But for the other competing model, the value of the LOO was 25105 and its KHAT values were also bigger, and I really confused.

My question is whether I calculated the loo values correctly or not? Can anyone help me with this problem?

Thanks.

```
data {
int <lower=0> province;
int <lower=0> n_grid;
int <lower=0> N;
int <lower=0> num;
int <lower=0> number;
int <lower =0 , upper = province> county[N];
vector <lower=0> [province] p;
row_vector[n_grid] kernel[province];
matrix [N,number] respon;
}
parameters{
vector [num] beta;
vector <lower=0> [province] sigma1;
real <lower=0> sigma;
vector [n_grid] x;
vector <lower=0> [province] r_county;
}
transformed parameters{
vector [num] time_ratio;
vector [N] lambdaa;
real <lower=0> alpha = 1 / sigma;
vector [n_grid] exp_x;
vector[province] a; // `a` saved to output because it's a toplevel transformed parameter
time_ratio = exp(beta);
exp_x = exp(x);
lambdaa = exp (((-1 * respon[,7:18] * beta) / sigma)+log(r_county [county]));
// }
{ // `z` not part of output
vector[province] landa;
for (k in 1 : province) {
landa[k] = kernel[k] * exp_x * p[k];
}
a = landa / sum(landa); // assign `a`
}
}
model{
vector [N] s_1;
vector [N] s_2;
vector [N] s_new1;
vector [N] s_new2;
target += normal_lpdf(x|0,5);
target += normal_lpdf(beta | 0, 1000);
target += gamma_lpdf(alpha | 0.001, 0.001);
target += normal_lpdf(r_county| 0, sigma1);
target += student_t_lpdf(sigma1| 3,0,1);
for (i in 1:N) {
s_1[i]= 1- ((lambdaa [i]*(respon[i,2]+0.01)^alpha)/ (1+(lambdaa [i]*(respon[i,2]+0.01)^alpha)));
s_2[i]= 1- ((lambdaa [i]*(respon[i,3]+0.01)^alpha)/ (1+(lambdaa [i]*(respon[i,3]+0.01)^alpha)));
s_new1[i] = a[county[i]] * s_1[i];
s_new2[i] = a[county[i]] * s_2[i];
target += log(s_1[i] - s_2[i]) + log(a[county[i]]);
}
}
generated quantities{
vector [N] log_lik;
vector [N] s_1;
vector [N] s_2;
vector [N] s_new1;
vector [N] s_new2;
for (i in 1:N){
s_1[i]= 1- ((lambdaa [i]*(respon[i,2]+0.01)^alpha)/ (1+(lambdaa [i]*(respon[i,2]+0.01)^alpha)));
s_2[i]= 1- ((lambdaa [i]*(respon[i,3]+0.01)^alpha)/ (1+(lambdaa [i]*(respon[i,3]+0.01)^alpha)));
s_new1[i] = a[county[i]] * s_1[i];
s_new2[i] = a[county[i]] * s_2[i];
log_lik [i]= log(s_1[i] - s_2[i]) + log(a[county[i]]);
}
}
.```
```