# Samples from Conditional Posterior Distribution

**URL:** <https://discourse.pymc.io/t/samples-from-conditional-posterior-distribution/9138>\
**Category:** v3\
**Tags:** modeling\
**Created:** [April 3, 2022, 10:12pm UTC](https://discourse.pymc.io/t/samples-from-conditional-posterior-distribution/9138 "2022-04-03T22:12:59Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![Giorgos\_Nikola](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/giorgos_nikola/32/4924_2.png) [@Giorgos\_Nikola](https://discourse.pymc.io/u/Giorgos_Nikola)\
**Post date:** [April 3, 2022, 10:13pm UTC](https://discourse.pymc.io/t/samples-from-conditional-posterior-distribution/9138/1 "2022-04-03T22:13:00Z")

</div>

Let us consider the following Hierarchical Bayesian model:

- w \sim\ Beta(20, 20)
- K = 6
- a = w \* (K - 2) + 1
- b = (1 - w) \* (K - 2) + 1
- theta \sim\ Beta(a, b)
- y \sim\ Bern(theta)

The above is the example of figure 9.3 in the book Doing Bayesian Data Analysis by John Kruschke.

I use the pymc3 to construct the model as follows:

```
import numpy as np
import pymc3 as pm
import arviz as az

K = 6
D = np.array([1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0])

with pm.Model() as mdl:
    
    w = pm.Beta('w', alpha=20., beta =20.)
    a = w * (K - 2) + 1
    b = (1 - w) * (K - 2) + 1
    theta = pm.Beta('theta', alpha=a, beta=b)
    y = pm.Bernoulli('y', p=theta, observed=D)
    trace = pm.sample(10000, tune=3000)

```

My question is the following:

- How can I compute the conditional posterior probability p(theta|w=0.25,D)? In other words how can I obtain samples from the conditional posterior distribution of theta|w=0.25, D?

---

_[View the full topic](https://discourse.pymc.io/t/samples-from-conditional-posterior-distribution/9138)._
