# Computing likelihood multiple datasets

**URL:** <https://discourse.pymc.io/t/computing-likelihood-multiple-datasets/17253>\
**Category:** v5\
**Tags:** modeling\
**Created:** [August 9, 2025, 12:10pm UTC](https://discourse.pymc.io/t/computing-likelihood-multiple-datasets/17253 "2025-08-09T12:10:10Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![TroubledStudent](https://avatars.discourse-cdn.com/v4/letter/t/e9a140/32.png) [@TroubledStudent](https://discourse.pymc.io/u/TroubledStudent)\
**Post date:** [August 9, 2025, 12:10pm UTC](https://discourse.pymc.io/t/computing-likelihood-multiple-datasets/17253/1 "2025-08-09T12:10:10Z")

</div>

Hello there,

Excuse me if this wasn’t posted under the right forum/tag.

I am currently using the PyMC built-in Metropolis-Hastings algorithm to estimate parameters of a given exponential model.

I would like to use the data of multiple datasets to compute the likelihood of a given parameter set. In the tutorial this is shown for a single dataset as follows:

Y\_obs = pm.Normal(“Y\_obs”, mu=mu, sigma=sigma, observed=Y)

My question now is how to combine this for multiple, independent datasets? Especially when they have different numbers of rows? Does anyone have a clue?

---

<div class="post-metadata">

**Author:** ![jessegrabowski](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/jessegrabowski/32/5010_2.png) [@jessegrabowski](https://discourse.pymc.io/u/jessegrabowski)\
**Post date:** [August 10, 2025, 4:39am UTC](https://discourse.pymc.io/t/computing-likelihood-multiple-datasets/17253/2 "2025-08-10T04:39:01Z")

</div>

You’ll need to provide some more details, your post is too vague with respect to exactly what you need. Do you want the same parameters for both datasets? Or different parameters? Do the datasets have the same features? What have you tried?

---

<div class="post-metadata">

**Author:** ![TroubledStudent](https://avatars.discourse-cdn.com/v4/letter/t/e9a140/32.png) [@TroubledStudent](https://discourse.pymc.io/u/TroubledStudent)\
**Post date:** [August 10, 2025, 5:17am UTC](https://discourse.pymc.io/t/computing-likelihood-multiple-datasets/17253/3 "2025-08-10T05:17:06Z")

</div>

Thank you for your reply! 🙂

I am indeed trying to infer the same set of parameters for all the datasets, but want to include all of their likelihoods. The datasets have the same features.

I have read elsewhere that by adding multiple likelihood function lines of code, the combined likelihood gets computed behind the scenes. So I have tried the following:

`y_like2 = pm.Normal(“y_like2”, `_`mu`_`=mu, `_`sigma`_`=sigma, `_`observed`_`=data2) `

```auto
y_like3 = pm.Normal("y_like3", mu=mu, sigma=sigma, observed=data3) 

```

However, the error that is raised after this is that the input shapes (data2 and data3) are uneven. This is true, because the observed datasets have different amounts of records.

My question now is how to make it work despite the uneven shapes. It isn’t uncommon for datasets modeling the same thing to have different amounts of records, right?

---

<div class="post-metadata">

**Author:** ![jessegrabowski](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/jessegrabowski/32/5010_2.png) [@jessegrabowski](https://discourse.pymc.io/u/jessegrabowski)\
**Post date:** [August 10, 2025, 5:37am UTC](https://discourse.pymc.io/t/computing-likelihood-multiple-datasets/17253/4 "2025-08-10T05:37:49Z")

</div>

I guess because `mu` has the same shape as the data (it comes from a regression or something?)

Is there any reason why you can’t just concatenate the datasets together? Otherwise you will need to compute a separate mu for each observed outcome distribution.

---

<div class="post-metadata">

**Author:** ![TroubledStudent](https://avatars.discourse-cdn.com/v4/letter/t/e9a140/32.png) [@TroubledStudent](https://discourse.pymc.io/u/TroubledStudent)\
**Post date:** [August 10, 2025, 6:21am UTC](https://discourse.pymc.io/t/computing-likelihood-multiple-datasets/17253/5 "2025-08-10T06:21:58Z")

</div>

The mu comes from the following:

```auto
# Priors for parameters

```

```auto
alpha = pm.HalfNormal("alpha", sigma=2) # initial capacity > 0

```

```auto
b = pm.HalfNormal("b", sigma=1) # decay rate > 0

```

```auto
sigma = pm.HalfNormal("sigma", sigma=0.1) # observation noise

```

```auto
# degradation model

```

```auto
mu = alpha * pm.math.exp(-b * t)

```

And the datasets are separate time series, which is why I wanted to include them separately… Do you think adding an extra column to uniquely identify the datasets might work if I concatenate them?

---

<div class="post-metadata">

**Author:** ![jessegrabowski](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/jessegrabowski/32/5010_2.png) [@jessegrabowski](https://discourse.pymc.io/u/jessegrabowski)\
**Post date:** [August 10, 2025, 6:25am UTC](https://discourse.pymc.io/t/computing-likelihood-multiple-datasets/17253/6 "2025-08-10T06:25:37Z")

</div>

Where does `t` come from? I assume it’s just a column of feature values that happens to represent time. In this case, you can indeed just concatenate everything, because all the rows of your data are conditionally independent once you know the value of `t` for that row. You don’t have a recursive time series function like x\_t = f(x\_{t-1}), so there’s no need to handle time in a special way.

You can shuffle the rows of a single dataset and check that you get the same answer to convince yourself this is the case.

---

<div class="post-metadata">

**Author:** ![TroubledStudent](https://avatars.discourse-cdn.com/v4/letter/t/e9a140/32.png) [@TroubledStudent](https://discourse.pymc.io/u/TroubledStudent)\
**Post date:** [August 10, 2025, 6:46am UTC](https://discourse.pymc.io/t/computing-likelihood-multiple-datasets/17253/7 "2025-08-10T06:46:09Z")

</div>

In this case, it doesn’t matter if for example the query t = 10 gives multiple records? I am worried the data will look like it is representing some form of periodicity.

---

<div class="post-metadata">

**Author:** ![jessegrabowski](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/jessegrabowski/32/5010_2.png) [@jessegrabowski](https://discourse.pymc.io/u/jessegrabowski)\
**Post date:** [August 10, 2025, 6:46am UTC](https://discourse.pymc.io/t/computing-likelihood-multiple-datasets/17253/8 "2025-08-10T06:46:55Z")

</div>

Why are you querying?

---

<div class="post-metadata">

**Author:** ![TroubledStudent](https://avatars.discourse-cdn.com/v4/letter/t/e9a140/32.png) [@TroubledStudent](https://discourse.pymc.io/u/TroubledStudent)\
**Post date:** [August 10, 2025, 6:49am UTC](https://discourse.pymc.io/t/computing-likelihood-multiple-datasets/17253/9 "2025-08-10T06:49:48Z")

</div>

Ah sorry, to clarify: I am not querying, but I meant that at a given time step you will acquire values from both datasets. And I was wondering if that was problematic.

---

<div class="post-metadata">

**Author:** ![jessegrabowski](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/jessegrabowski/32/5010_2.png) [@jessegrabowski](https://discourse.pymc.io/u/jessegrabowski)\
**Post date:** [August 10, 2025, 6:54am UTC](https://discourse.pymc.io/t/computing-likelihood-multiple-datasets/17253/10 "2025-08-10T06:54:41Z")

</div>

You can add a column to identify which dataset the row is from

---

<div class="post-metadata">

**Author:** ![TroubledStudent](https://avatars.discourse-cdn.com/v4/letter/t/e9a140/32.png) [@TroubledStudent](https://discourse.pymc.io/u/TroubledStudent)\
**Post date:** [August 16, 2025, 5:39pm UTC](https://discourse.pymc.io/t/computing-likelihood-multiple-datasets/17253/11 "2025-08-16T17:39:59Z")

</div>

Dear Jesse,

Excuse me for my late reply. There were some urgent personal matters this week that took away all my attention.

And also thank you for your swift response! This perfectly resolved my issue, and I can now continue with my thesis. 🙂

Best regards!
