I made progress with the code, now I suppose that users send me multiple measurement then I compute the latent mean and the standard deviation for each user:
# True parameter values
true_mu = 38.095
true_sigma = 0.005
# Size of dataset
size = 10
# Simulate some data, each user makes 10 measures
y1 = true_mu + np.random.randn(size)* true_sigma
y2 = true_mu + np.random.randn(size)*(true_sigma-0.001)
y3 = true_mu + np.random.randn(size)*(true_sigma-0.002) # Best values
y4 = true_mu + np.random.randn(size)*(true_sigma+0.005) # Worst values
x = np.array([y1, y2, y3, y4])
with pm.Model() as hierachical_model:
# Latent mean and sigma, I want to estimate these parameters
mu = pm.Normal('mu', 0., 10.)
rho = pm.HalfNormal('rho', .1)
sigma = pm.HalfNormal('sigma', rho, shape=(4, 1))
like = pm.Normal('like', mu, sigma, observed=x)
trace = pm.sample(500)
print('mu: ',trace['mu'].mean(axis=0), 'rho: ', trace['rho'].mean(axis=0))
print(trace['sigma'].mean(axis=0))
pm.traceplot(trace)
plt.show()
Lastly, I would like to give more weight to users who send me similar measures. There is a simple way to say this?