# How to perform weighted inference

**URL:** <https://discourse.pymc.io/t/how-to-perform-weighted-inference/1825>\
**Category:** Questions\
**Created:** [August 28, 2018, 3:24pm UTC](https://discourse.pymc.io/t/how-to-perform-weighted-inference/1825 "2018-08-28T15:24:32Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![gokl](https://avatars.discourse-cdn.com/v4/letter/g/3da27b/32.png) [@gokl](https://discourse.pymc.io/u/gokl)\
**Post date:** [August 28, 2018, 6:34pm UTC](https://discourse.pymc.io/t/how-to-perform-weighted-inference/1825/5 "2018-08-28T18:34:22Z")

</div>

Hi,

> [@mgregori](#):
>
> There’s a similar question [here](https://discourse.pymc.io/t/how-to-model-deal-with-weighted-binary-outcomes/1274) but the implementation the guy came up with it’s wrong in my opinion (instead of multiplying weights with likelihoods he is summing them).

I think you are right. I added the normal Bernoulli likelihood with pm.Bernoulli and also added the weighted likelihood parts via pm.Potential. I should have used only the Potential likelihood. Thank you for pointing this out.

This would be the corrected example.

```
import numpy as np
import pymc3 as pm
import theano.tensor as T

N = 1000
P = 0.2

data = np.zeros(N)
data[:int(N * P)] = 1.0
weights = np.ones(N)
weights[:int(N * P)] = 4.0

with pm.Model() as model:
    
    p_ = pm.Normal('p_',
                  mu=0.0,
                  sd=1000.0)
    p = pm.Deterministic('p', pm.math.invlogit(p_))
        
    pm.Potential('weights', 
             weights * pm.Bernoulli.dist(p=p).logp(data))

    trace = pm.sample(10000, cores=1, random_seed=1)
    
trace['p'].mean() # 0.50019413

```

What do you think?

---

_[View the full topic](https://discourse.pymc.io/t/how-to-perform-weighted-inference/1825)._
