# How to model/deal with weighted binary outcomes

**URL:** <https://discourse.pymc.io/t/how-to-model-deal-with-weighted-binary-outcomes/1274>\
**Category:** Questions\
**Created:** [May 24, 2018, 3:51pm UTC](https://discourse.pymc.io/t/how-to-model-deal-with-weighted-binary-outcomes/1274 "2018-05-24T15:51:53Z")\
**Posts on this page:** 1\
**Showing post:** 10

<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 30, 2018, 7:40pm UTC](https://discourse.pymc.io/t/how-to-model-deal-with-weighted-binary-outcomes/1274/10 "2018-08-30T19:40:23Z")

</div>

Updated solution after this topic [How to perform weighted inference](https://discourse.pymc.io/t/how-to-perform-weighted-inference/1825/5?u=gokl)

```
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
```

---

_[View the full topic](https://discourse.pymc.io/t/how-to-model-deal-with-weighted-binary-outcomes/1274)._
