I'm following these slides. I have some lamps, which I expect to die at a time $t$ where $p(t) = \lambda e ^{-\lambda t}$ for some $\lambda$. My prior for $\lambda$ is given by $p(\lambda) = \Gamma(\lambda, 2, 2)$. I observe one lamp die at time 10. According to those slides, my posterior is $$k' = 2 + 1 = 3$$ $$ \theta' = 2 / (1 + 2 * 10) = 0.095$$ so

$$p(\lambda) =\Gamma(\lambda, 3, 0.095)$$ When I plot this though, it doesn't look right:

enter image description here

My posterior has shifted far to the left, even though my observation was to the right of the expectation of my prior. What's going on?


import matplotlib.pyplot as plt
import numpy as np
from scipy.special import gamma as gamma_function

def gamma(x, k, theta):
    return np.power(x, k-1) * np.exp(-x/theta) / (gamma_function(k) * np.power(theta, k))

k = 2
theta = 2

data = [10]
new_k = k + len(data)
new_theta = theta / (1 + theta * sum(data))

x = np.linspace(0, 10, 100)
plt.plot(x, gamma(x, 2, 2), label = 'prior')
plt.plot(x, gamma(x, new_k, new_theta), 'r', label = 'posterior')

1 Answer 1


The mean of an exponential RV is $1/\lambda$, so an increasing lifetime in data decreases your posterior $\lambda$, e.g. mean life=10 means $\lambda=0.1$. So, it's normal that your posterior belief goes towards left side of the plot.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.