I fit this very simple model in pyStan.
import pystan
import numpy as np
import matplotlib.pyplot as plt
election_code = """
data {
int<lower=0> n; // number of people
int<lower=0> y; // number of people preferring candidate A
}
parameters {
real<lower=0, upper=1> p;
}
model {
p ~ beta(1, 1); // equivalent to the Uniform distribution
y ~ binomial(n, p);
}
"""
election_data = {
'n': 100,
'y': 58
}
fit = pystan.stan(model_code=election_code, data=election_data,
iter=1000, chains=4)
print(fit)
fit.plot()
plt.show()
Is there a way to return the HDI in pyStan? I haven't found anything about it in the official documentation. I'm aware that for unimodal and symmetric distributions, HDI and quantile-based credible intervals won't be too different. I'm just wondering how I could return it in case I need it when working with more complex posteriors.
I'm not sure if this is the right channel to reach out for this sort of questions. Apologies if this was not the right community.