I have the following bayesian hierarchical model, where y is of dimension (1313x1), X (1313, 2) and Z (1313x2).
y = data["Score"]
y = y.values.reshape(-1, 1)
X = data[["Var1", "Var2"]].values
Z = data[["Control1", "Control2"]].values
with pm.Model() as model:
gamma = pm.Normal("gamma", mu=0, sigma=1, shape=(2, 2))
u = pm.Normal("u", mu=0, sigma=1, shape=2)
beta = pm.math.dot(Z, gamma) + u
# Model error
r = pm.Gamma("r", alpha=9, beta=4, shape=())
y_hat = pm.math.dot(X, beta)
# Likelihood
y_like = pm.Normal("y_like", mu=y_hat, sigma=r, observed=y)
with model:
trace = pm.sample(draws=500, chains=2, tune=2000, discard_tuned_samples=True, random_seed=SEED, progressbar=True,
cores=1, init="adapt_diag", return_inferencedata=True)
If I run the model, the following error message comes up:
ValueError: shapes (1313,2) and (1313,2) not aligned: 2 (dim 1) != 1313 (dim 0)
I considered transposing beta from (1313x2) to (2, 1313) but I am not sure whether its shape is correct at all.
However this gave me the following error
ValueError: Mass matrix contains zeros on the diagonal.
The derivative of RV u
.ravel()[1] is zero.
The derivative of RV gamma
.ravel()[2] is zero.
The derivative of RV gamma
.ravel()[3] is zero.
I use pymc3 3.11.2