Hey just sanity check here.
model = bmb.Model(“y ~ x + (1|subject) + (x|ROI)”, data=df)
This Bambi model results in correlated random intercepts and slopes correct in a non-centered form correct? In addition i have tried to hand code the model in PyMC directly.
with pm.Model() as model:
# Intercept (alpha) and beta (fixed) distribution
alpha = pm.Normal("alpha", mu=0.17, sigma=4.66)
beta = pm.Normal("beta", mu=0, sigma=0.27)
sigma = pm.HalfStudentT("sigma",nu=4, sigma=2.3)
# Subjct random intercept.
tau_u = pm.HalfNormal("tau_u", sigma=4.66)
z_u = pm.Normal('z_u', mu=0, sigma=1, shape=N_subj)
u = pm.Deterministic("u", z_u * tau_u)
# Randomintecept and slope correlated.
z_u2 = pm.Normal('z_u2', 0., 1., shape=(J, N_ROI))
sd_dist = pm.HalfNormal.dist(sigma=[4.66,0.27], shape=J)
L_u, rho, tau_u2 = pm.LKJCholeskyCov('L_u',
eta=1, n=J,
sd_dist=sd_dist)
u2 = pm.Deterministic("u2", pt.dot(L_u, z_u2).T)
# Likelihood
mu = alpha + beta * Xc + u[subj] + u2[ROI, 0] + X * u2[ROI, 1]
y = pm.Normal('y', mu = mu, sigma = sigma, observed=y)
However, my implementation is slower so just curious on any advice on my implementation.
Both Bambi and my implementation tested on nutpie sampler. and i have attmepted to take the priors from bambi to my implementation