Hi all,

How calculate the deviance information criterion (DIC) with stan?

As far as I know it’s not implemented. On the other hand there has been interesting work which did the calculation using posterior draws produced by Stan: https://arxiv.org/abs/1806.09996

It is not implemented because it is not nearly as good as estimator as that which is produced by `loo()`

.

Thank you so much for your help. Did you have the R program to compute DIC from Stan?

Thank you so much fro your help and information. Yes, I used LOO for GEV model but it is difficult for a very big data.

My interest in DIC is limited to the results of that paper. Does the author of the paper have the ability to share their code?

Also the work was based on features of WinBUGS so there may be code examples in the R interface for that, or in other R packages.

Thank you so much for your explanation and help.

Can you tell more about your model and data, and how long it is taking if you use loo package? There are ways to make loo faster and I’m interested in case examples.

Thank you so much Prof Aki Vehtari

the length of y is 47662.

model:

functions{

real gev_lpdf (real y, real loc, real scale, real shape){

real z;

real inv_shape;

inv_shape = 1.0/shape;

z = 1 + (y - loc) * shape / scale;

return -log(scale) - (1 + inv_shape)*log(z) - pow(z,-inv_shape);

}

}

data {

int<lower=0> n;

int<lower=0> ns;

int<lower=0> nt;

vector [n] y; //data

vector [nt] x; //covariates

int site[n];

int year[n];

}

parameters {

vector<lower=0, upper=85>[ns] alpha_mu;

vector [ns] beta_mu;

vector<lower=0, upper=50>[ns] alpha_sigma;

vector [ns] beta_sigma;

vector<lower=-0.2, upper=0.2> [ns] xi;

}

transformed parameters {

matrix[nt,ns] mu;

matrix[nt,ns] sigma;

for (i in 1:ns){

for(t in 1:nt){

mu[t,i] = alpha_mu[i] + beta_mu[i] * x[t];

sigma[t,i] = alpha_sigma[i] + beta_sigma[i] * x[t];

}

}

}

model {

target += normal_lpdf(alpha_mu | 0, pow(10,2));

target += normal_lpdf(beta_mu | 0, 10);

target += normal_lpdf(alpha_sigma | 0, 10);

target += normal_lpdf(beta_sigma | 0, 10);

target += normal_lpdf(xi | 0, 0.3);

for (i in 1:n){

target += gev_lpdf(y[i] | mu[year[i], site[i]],sigma[year[i], site[i]],xi[site[i]]);

}

}

generated quantities{

vector[n] log_lik;

for (i in 1:n){

log_lik[i] = gev_lpdf(y[i] | mu[year[i], site[i]],sigma[year[i], site[i]],xi[site[i]]);

}

}

Can you tell also ns and nt? That would help to figure out whether you need loo at all.

We’ll have soon have a loo version which would be fast for n=47622, too. Not also that Windows has a problem making loo slow with multiple cores. While waiting for faster loo(), you may also try waic(), which is better than dic, but not better than loo.

It would be better not to use use upper limit unless there is a real physical restriction at that value. You have priors for these, so you would get also better sampling behavior if you remove the upper limits.

The same thing for this. Is there a real physical restriction at -0.2 and 0.2? If not, it’s better to let the continuous prior to handle the prior information.

Thank you so much.

What about the generated quantities and log_lik, is it correct?

ns: number of sites

nt: number of times

Looks correct.

I meant what are the values of these? Helps to figure out the total number of parameters

Aki

Thank you so much Profesor