# You could use a function like this to calculate the log-likelihood
# for an observation over the posterior distribution to then use as
# an ingredient to the calculation of the WAIC
mc <-
'
functions {
vector logLik(int y, real x, vector beta) {
vector[rows(beta)] logLik;
for (i in 1:rows(beta)) {
logLik[i] <- poisson_log_log(y, x * beta[i]);
}
return logLik;
}
}
model {}
'
cppcode <- stanc(model_code = mc, model_name = "Demonstration")
expose_stan_functions(cppcode)
Run the code above in your browser using DataLab