Seeds: Random effect logistic regression

Tried this as well

import matplotlib.pyplot as plt



with m:
    # update values of predictors:
    pm.set_data({"data": n.astype('int64')})
    # use the updated values and predict outcomes and probabilities:
    posterior_predictive = pm.sample_posterior_predictive(
        ptrace1, var_names=["p"], random_seed=15
    )
    model_preds = posterior_predictive["p"]
p_values = np.zeros(shape=21)

for l in range (0,21):
 p_values[l]=(ptrace1["p"][1][l].mean())

_, ax = plt.subplots(figsize=(12, 6))

# uncertainty about the estimates:
ax.plot(
    [n, n],
    az.hdi(model_preds).T,
    lw=6,
    color="#00204C",
    alpha=0.8,
)
# expected probability of success:
ax.plot(
    n,
    model_preds.mean(0),
    "o",
    ms=5,
    color="#FFE945",
    alpha=0.8,
    label="Expected prob.",
)

# actual outcomes:
ax.scatter(
    x=n,
    y=r/n,
    marker="x",
    color="#A69C75",
    alpha=0.8,
    label="Observed outcomes",
)

# # true probabilities:
# x = np.linspace(n.min() - 0.1, n.max() + 0.1,num=21)
ax.plot(
    n,
    p_values,
    lw=2,
    ls="--",
    color="#565C6C",
    alpha=0.8,
    label="True prob.",
)

ax.set_xlabel("Predictor")
ax.set_ylabel("Prob. of succes")
ax.set_title("Out-of-sample Predictions")
ax.legend(fontsize=10, frameon=True, framealpha=0.5);