Estimating prior sd for the parameter p of a beta binomial regression

I haven’t looked at the blog and don’t have your input data but making some up to show you the method

X_predictor = 1
num_trials = 8
with pm.Model() as model:
    # Priors
    intercept = pm.Normal('intercept', mu=np.log(0.1), sd=0.05)
    beta = pm.Normal('beta', mu=np.log(0.75), sd=0.05)

    # Beta parameters
    p_mu = pm.Deterministic('p_mu', pm.math.invlogit(intercept + beta * X_predictor))
    p_kappa = pm.HalfNormal('p_kappa', 10)
    p_alpha = p_mu * p_kappa
    p_beta = (1-p_mu) * p_kappa

    # Outcome definition
    p = pm.Beta('p', alpha=p_alpha, beta=p_beta)
    Y = pm.Binomial('num_successes', n=num_trials, p=p)
    
    prior = pm.sample_prior_predictive()
    
prior['p'].std() ### equals 0.1133

Is that what you want to achieve?
You can add an observed with proper predictors, then run a trace and posterior_predictive checks to get a posterior distribution for p to compare to prior.

1 Like