Hi
I’ve got two groups (A & B) with multiple studies (in this case two each), which I want to compare but do not want to pool the studies.
Therefore I created a hierarchical model based on the tipps from this thread (Hierarchical AB testing in PyMC3)
However I’m not sure how to draw a good conclusion, because I get multiple ‘deltaABX’ (one for each study)
How can I get an ‘overall’ (one) estimation of the delta of the rates of A and B?
Example code:
import pymc3 as pm
import theano.tensor as tt
import numpy as np
trials_A=np.array([ 96, 185])
successes_A=np.array([25, 36])
trials_B=np.array([216, 100])
successes_B=np.array([52, 19])
def logp_ab(value):
return tt.log(tt.pow(tt.sum(value), -5/2))
with pm.Model() as model2:
# Uninformative prior for alpha and beta (Group A)
ab_A = pm.HalfFlat('ab_A', shape=2, testval=np.asarray([1., 1.]))
pm.Potential('p(a, b)_A', logp_ab(ab_A))
# # Our alpha and beta. Remove this code if you don't want to track alpha
# # and beta
# alpha_A = pm.Deterministic('alpha_A', ab_A[0])
# beta_A = pm.Deterministic('beta_A', ab_A[1])
theta_A = pm.Beta('theta_A', alpha=ab_A[0], beta=ab_A[1], shape=trials_A.shape[0])
p_A = pm.Binomial('y_A', p=theta_A, observed=successes_A, n=trials_A)
# the same as above for second group (B)
ab_B = pm.HalfFlat('ab_B', shape=2, testval=np.asarray([1., 1.]))
pm.Potential('p(a, b)_B', logp_ab(ab_B))
# alpha_B = pm.Deterministic('alpha_B', ab_B[0])
# beta_B = pm.Deterministic('beta_B', ab_B[1])
theta_B = pm.Beta('theta_B', alpha=ab_B[0], beta=ab_B[1], shape=trials_B.shape[0])
p_B = pm.Binomial('y_B', p=theta_B, observed=successes_B, n=trials_B)
deltaABX = pm.Deterministic('deltaABX',theta_B - theta_A) # for each theta
trace2 = pm.sample(draws=5_000, tune=5_000)
c_interval=0.95
pm.plot_posterior(trace2,credible_interval=c_interval, point_estimate='mean', ref_val=0.0)
pm.summary(trace2,credible_interval=c_interval)