Sure! In this tutorial there are two model variables, I think refered as prey and predators associates with to sets of data. If we integrate the model with the mcmc chains, we obtain two sets of fits, one for prey and one for predators. I would like to obtain the likelihood for each of those fits for both prey and predators.

I’m still not quite clear what you mean. In the example, the data consists of two time series, one measuring prey abundance, and one measuring predator abundance. The parameters of the system which you are fitting are alpha (population growth rate of prey), beta (per-predator predation rate), gamma (population growth of predator per prey eaten) and delta (death rate of predators). In the first example the model (fitlv) is fitted using both the predator and prey time series, and in the second example (fitlv2) the prey time series is omitted, but you’re still inferring the values of those same four parameters in each case.

When you say “likelihood,” do you mean in the statistical sense (i.e., P(data | parameters))? Or are you asking about the posterior probabilities for the parameters, or the predator/prey population densities?

Sorry for the confusion, maybe I am confused on how Turing is computing the likelihood. My understanding is that in the fitlv function from the tutorial the likelihood P(data|parameters) is computed here:

data[:, i] ~ MvNormal(predicted[i], σ^2 * I)

But what I want is to compare different models and then compare the likelihood of each model using the posteriors probabilities for the parameters. So my idea is to integrate the model after the mcmc using the posteriors probabilities for the model parameters and then compute the likelihood to calculate indicators like AIC. I am not sure how to compute the likelihood at this stage. Is that clearer?

Ah, yes, much clearer! The chain contains a field :log_density, which records the log-posterior value for each sample. If you want the log-likelihood instead, you can calculate it after the fact using the loglikelihood function from Turing:

using Turing, DataFrames
@model function demo(x)
m ~ Normal()
s ~ Exponential()
x .~ Normal(m, s)
end
mod = demo(randn(100))
chain = sample(mod, NUTS(), 1000)
loglikelihood(mod, (m=1.0, s=1.0)) # for a single set of parameters
ll = [loglikelihood(mod, row) for row in eachrow(DataFrame(chain))] # for each sample in chain
all(ll .> chain[:log_density]) # true

Note loglikelihood expects the second argument to have named fields for each of the parameter