Hello,
I was wondering if there was anyway to access the probability parameter for the binomial distribution in the sample_ppc call. My model is constructed so that alpha and beta are deterministic values derived from certain distributions.
I am most interested in the p parameter of the binomial distribution, but setting the model up as a beta distribution that feeds into the binomial distribution results in much, much slower sampling.
So, to that end, if I could get help either getting the p parameter from the BetaBinomial distribution during sample_ppc or fixing the sampling issues with the theoretically same model, it would be very much appreciated.
Here is the model for reference:
with pm.Model() as model:
intercept = pm.Normal('intercept', mu=0.0, sd=5, shape=1)
link_argument = intercept
for covariate in covariates:
if covariates[covariate]['type'] == 'categorical':
shape = covariates[covariate]['encoder'].classes_.size
elif covariates[covariate]['type'] in ['metric', 'binary']:
shape = 1
sigma = pm.HalfCauchy(f'{covariate}_coeff_sigma', beta=5)
offset = pm.Normal(f'{covariate}_coeff_offset', mu=0, sd=1, shape=shape)
coeff = pm.Deterministic(f'{covariate}_coeff', 0.0 + offset * sigma)
if shape > 1:
link_argument += coeff[model_variables[covariate]]
else:
link_argument += coeff * model_variables[covariate]
omega = pm.Deterministic('omega', pm.invlogit(link_argument))
kappa = pm.Exponential('kappa', lam=1e-4)
alpha = pm.Deterministic('alpha', omega * kappa + 1)
beta = pm.Deterministic('beta', (1 - omega) * kappa + 1)
p = pm.Beta('p', alpha=alpha, beta=beta, shape=p_shape)
likelihood = pm.Binomial(
'likelihood', p=p, n=model_variables['n'], observed=model_variables['y_obs']
)
# The likelihood parameterization below results in much faster sampling, but does not let me draw p parameter from posterior distribution
# likelihood = pm.BetaBinomial('likelihood', alpha=alpha, beta=beta, n=model_variables['n'], observed=model_variables['y_obs'])
Thanks!