Bayesian newbie here. I have a 4x4 data matrix consisting of proportions of success (probability of observed successes) and would like to obtain parameters alpha (4-vector for rows), beta (4-vector for columns) and c using MCMC such that the posterior distribution in data[i,j] is given by 1/(1 + exp(alpha[i] + beta[j] + c)) (sigmoid). So for (4 x 4) data I have 9 parameters. (I also have raw data for numbers of successes & failures for each cell, but I’m using data = successes/(successes+failures).)
It seems to converge okay, but the problem is when I try to use ppc the posterior gives probabilities close to 0, contrast to actual data and I’m not sure why…
data = np.array([[0.2, 0.3, 0.5, 0.6],
[0.6, 0.2, 0.6, 0.5],
[0.5, 0.6, 0.2, 0.3],
[0.3, 0.5, 0.6, 0.2]])
basic_model = pm.Model()
with basic_model:
# Priors for unknown model parameters (9 parameters in total)
a = pm.Normal('a', mu=0, sd=10, shape=(4, 1))
b = pm.Normal('b', mu=0, sd=10, shape=(1, 4))
offset = pm.Normal('offset', mu=0, sd=10)
# Expected values of outcome (4 x 4)
p = pm.Deterministic('p', sigmoid(a + b + offset))
# Likelihood (sampling distribution) of observations (4 x 4)
obs = pm.Bernoulli('obs', p=p, observed=data)
with basic_model:
# Draw posterior samples
trace = pm.sample(1000)
ppc = pm.sample_ppc(trace, samples=1000, model=basic_model)
posterior_samples = np.mean(ppc['obs'], axis=0).round(3)
print(posterior_samples)
def sigmoid(x):
z = np.exp(x)
return z / (1 + z)
posterior_samples mean gives:
[[ 0.01 0.01 0.012 0.011]
[ 0.003 0.006 0.007 0.008]
[ 0.013 0.011 0.013 0.01 ]
[ 0.007 0.007 0.008 0.015]]
which is nothing like the observed data.