# Discrete survivor function

**URL:** <https://discourse.pymc.io/t/discrete-survivor-function/8253>\
**Category:** Questions\
**Created:** [November 1, 2021, 4:15pm UTC](https://discourse.pymc.io/t/discrete-survivor-function/8253 "2021-11-01T16:15:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbuddy\_13](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/jbuddy_13/32/5900_2.png) [@jbuddy\_13](https://discourse.pymc.io/u/jbuddy_13)\
**Post date:** [November 1, 2021, 4:15pm UTC](https://discourse.pymc.io/t/discrete-survivor-function/8253/1 "2021-11-01T16:15:12Z")

</div>

I’m following along a [tutorial](http://www.brucehardie.com/talks/intro_tut_art_16_HO.pdf) written by Marketer, Bruce Hardie. He doesn’t use Bayesian methods, so I’m trying to convert his MLE estimates into PyMC3 code.

P(churn) = Bernoulli(\theta)  
P(T=t) = Geometric(\theta) = \theta(1-\theta)^{t-1}  
P(T\>t) = S(t) = (1-\theta)^{t-1}

I’m not sure how best to implement this survivor function (as the likelihood) in PyMC3. The two most obvious choices are:

1. S(t) = (1-\theta)^{t-1} which in PyMC3 might just be  
`lik = pm.Bernoulli(1-theta)**(t-1) `

2. S(t) = \frac{Geometric(\theta)}{Bernoulli(\theta)} , which in PyMC3 might be  
`lik = pm.Geometric(theta)/Bernoulli(theta)`

My two concerns are: (A) I’ve never combined likelihoods in PyMC3 before, so I’m not sure if option 2 would even work. However, (B) I’ve never multiplied or raised a likelihood to a power before and so I’m not sure if this would work either.

Thoughts?

Edit:  
I’ve taken inspiration from this [post](https://discourse.pymc.io/t/recovering-parameters-of-long-tailed-beta-geometric-data/601) and have used the below model:

```python
with pm.Model() as model:    
    beta_alpha = pm.Uniform('beta_alpha', 0.0001, 5)
    beta_beta = pm.Uniform('beta_beta', 0.0001, 5)
    
    churn = pm.Beta('churn',
                   alpha=beta_alpha,
                   beta=beta_beta)
    renewal = pm.Deterministic('renewal', 1-churn)
    renewals = pm.Geometric('renewals',p=churn, observed=geo)/churn
    
    trace = pm.sample(chains=4)

```

Whether or not I divide by churn, the posterior estimates are the same. Philosophically, I’m curious as to why this is? And second, is PyMC3 perhaps ignoring this division as it’s not part of what PyMC3 perceives as the likelihood?

And when I try to write a custom likelihood function using `pm.potential` the sampler goes haywire…

```python
with pm.Model() as model:    
    beta_alpha = pm.Uniform('beta_alpha', 0.0001, 5)
    beta_beta = pm.Uniform('beta_beta', 0.0001, 5)
    
    churn = pm.Beta('churn',
                   alpha=beta_alpha,
                   beta=beta_beta)
    renewal = pm.Deterministic('renewal', 1-churn)

    def likelihood(theta, t):
      return theta**(t-1)
    
    lik = pm.Potential('like', likelihood(theta=renewal, t=geo))
    trace = pm.sample(chains=4)

```
