# Loo\_compare issue

**URL:** <https://discourse.mc-stan.org/t/loo-compare-issue/17747>\
**Category:** Modeling\
**Created:** [August 30, 2020, 4:11pm UTC](https://discourse.mc-stan.org/t/loo-compare-issue/17747 "2020-08-30T16:11:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dkaplan](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/dkaplan/32/13835_2.png) [@dkaplan](https://discourse.mc-stan.org/u/dkaplan)\
**Post date:** [August 30, 2020, 4:11pm UTC](https://discourse.mc-stan.org/t/loo-compare-issue/17747/1 "2020-08-30T16:11:07Z")

</div>

Greetings,

I’m running a simple loo\_compare and although I can extract the likelihoods for both models, when I run the compare program, I receive an error message

Error: Not all models have the same number of data points.

log\_lik\_1 \<- extract\_log\_lik(myfit, merge\_chains = FALSE) // These two lines are fine  
log\_lik\_2 \<- extract\_log\_lik(myfit2, merge\_chains = FALSE)

```

loo1 <- loo(log_lik_1) // These four lines give me the output
loo2 <- loo(log_lik_2)
print(loo1)
print(loo2)

comp <- loo_compare(loo1, loo2) // This line gives me the error message
print(comp,simplify=FALSE,digits=3)

Thank you,

David
```

---

<div class="post-metadata">

**Author:** ![JimBob](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jimbob/32/19329_2.png) [@JimBob](https://discourse.mc-stan.org/u/JimBob)\
**Post date:** [August 30, 2020, 7:37pm UTC](https://discourse.mc-stan.org/t/loo-compare-issue/17747/2 "2020-08-30T19:37:07Z")

</div>

Is the error message correct in noting that the models do not have the same number of data points? If your loo values are based on models with different data, then it is quite possible the comparison will not work, because loo is about the predictive power of the models and I presume should be applied to the same data.

---

<div class="post-metadata">

**Author:** ![dkaplan](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/dkaplan/32/13835_2.png) [@dkaplan](https://discourse.mc-stan.org/u/dkaplan)\
**Post date:** [August 31, 2020, 1:32am UTC](https://discourse.mc-stan.org/t/loo-compare-issue/17747/3 "2020-08-31T01:32:13Z")

</div>

Hi JimBob,

Thanks for our reply. The data sources are the same and when I ask for the number of rows of log\_lik\_1 and log\_lik\_2 (each models extraced log likelhood) they are the same.

David

---

<div class="post-metadata">

**Author:** ![jonah](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jonah/32/200_2.png) [@jonah](https://discourse.mc-stan.org/u/jonah)\
**Post date:** [August 31, 2020, 5:56pm UTC](https://discourse.mc-stan.org/t/loo-compare-issue/17747/4 "2020-08-31T17:56:45Z")

</div>

> [@dkaplan](#):
>
> I ask for the number of rows of log\_lik\_1 and log\_lik\_2 (each models extraced log likelhood) they are the same.

Hi David, the number of rows should be the number of posterior draws not the number of data points. What do you get if you check all the dimensions with `dim(log_lik_1)` and `dim(log_lik_2)`?

---

<div class="post-metadata">

**Author:** ![dkaplan](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/dkaplan/32/13835_2.png) [@dkaplan](https://discourse.mc-stan.org/u/dkaplan)\
**Post date:** [August 31, 2020, 6:46pm UTC](https://discourse.mc-stan.org/t/loo-compare-issue/17747/5 "2020-08-31T18:46:54Z")

</div>

That was it. Thanks! The two models with different variables also had different amounts of missing data, and the way I handled the missing data gave rise to two different sample sizes.

Best,

David

---

<div class="post-metadata">

**Author:** ![jonah](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jonah/32/200_2.png) [@jonah](https://discourse.mc-stan.org/u/jonah)\
**Post date:** [August 31, 2020, 6:47pm UTC](https://discourse.mc-stan.org/t/loo-compare-issue/17747/6 "2020-08-31T18:47:42Z")

</div>

Ok great, glad you figured it out!
