I’m trying to create a model for truncated lognormal observations, but unsure of how to approach this with PyMC3
with pm.Model() as trunc_model:
theta = pm.Normal('theta', 6.8, 0.3)
sigma = pm.Exponential('sigma', 1.25)
logp = pm.Lognormal.dist(theta, sigma).logp(y_post_pred)
y = pm.Potential('y', logp - pm.Lognormal.dist(theta, sigma).logcdf(2000))
trace = pm.sample(tune=4000, return_inferencedata=True)
prior_p = pm.sample_prior_predictive()
pp = pm.sample_posterior_predictive(trace)
The model fits the parameters, but the posterior predictive samples are empty and the prior predictive samples are just the log likelihoods.
Here’s the data gen process:
lognorm_data = np.random.lognormal(6.6, 0.82, 10000)
y_post_pred= lognorm_data[lognorm_data <= 2000][:100]
Three questions:
- Any idea on how to improve this?
- Any ideas on how to get this model setup to the point that it can also generate samples?
- How would I implement a lower truncation as well?