# LDA Tutorial likelihood calculation

**URL:** <https://discourse.mc-stan.org/t/lda-tutorial-likelihood-calculation/21064>\
**Category:** Modeling\
**Tags:** pystan, math\
**Created:** [March 2, 2021, 8:04pm UTC](https://discourse.mc-stan.org/t/lda-tutorial-likelihood-calculation/21064 "2021-03-02T20:04:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gizem\_Caylak](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/gizem_caylak/32/10839_2.png) [@Gizem\_Caylak](https://discourse.mc-stan.org/u/Gizem_Caylak)\
**Post date:** [March 2, 2021, 8:04pm UTC](https://discourse.mc-stan.org/t/lda-tutorial-likelihood-calculation/21064/1 "2021-03-02T20:04:09Z")

</div>

Hi everyone,  
I am trying to run the LDA model from the Stan user guide which can be found here:

> **[Stan User’s Guide](https://mc-stan.org/docs/2_23/stan-users-guide/latent-dirichlet-allocation.html)**
>
> Stan user’s guide with examples and programming techniques.

However, I think the likelihood calculation in the code is not right:

```stan
for (n in 1:N) {
    real gamma[K];
    for (k in 1:K)
      gamma[k] = log(theta[doc[n], k]) + log(phi[k, w[n]]);
    target += log_sum_exp(gamma); // likelihood;
  }

```

In the formula, it also includes the prior probabilities (for \theta and \phi); however, in the code while calculating the target , likelihood, they are not included. I would appreciate your help on that whether there is a reason they are not included.

---

<div class="post-metadata">

**Author:** ![cgoold](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/cgoold/32/1387_2.png) [@cgoold](https://discourse.mc-stan.org/u/cgoold)\
**Post date:** [March 2, 2021, 9:55pm UTC](https://discourse.mc-stan.org/t/lda-tutorial-likelihood-calculation/21064/2 "2021-03-02T21:55:38Z")

</div>

From a brief look, the priors are already added to target in the prior definitions above the likelihood loop.
