I have a simple inference example for multiple coinflips for multiple agents. For reproducibility I’m using p=11% for the probability of heads for all agents:
import pymc as pm
import arviz as az
import numpy as np
num_trials = 500
num_agents = 60
true_p_heads = np.array([0.11]*num_agents)
observed_heads = np.random.binomial(n=num_trials, p=true_p_heads) # Simulated observed heads
with pm.Model() as hierarchical_model:
# Hyperpriors for the group parameters
alpha = pm.Gamma('alpha', alpha=1, beta=1)
beta = pm.Gamma('beta', alpha=1, beta=1)
# Individual participant probabilities of heads
p_heads = pm.Beta('p_heads', alpha=alpha, beta=beta, shape=num_agents)
# Likelihood of observed data
observations = pm.Binomial('observations', n=num_trials, p=p_heads, observed=observed_heads, shape=num_agents)
# Posterior sampling
trace = pm.sample(chains = 4, draws = 2_000, tune = 5_00)
pm.compute_log_likelihood(trace)
az.summary(trace)
az.waic(trace)
No matter how often I repeat the inference, for num_trials=50, p_waic is around 20, for num_trials=500, it is around 27, and for num_trials=5000, it’s around 30. This is weird, since according to the book Bayesian Data Analysis by Gelman, et al., pwaic is the result of a sum over all trials (see attached equation), and should therefore be (more or less) proportional to the number of trials, if I understand correctly. I do get the warning “There has been a warning during the calculation. Please check the results.”, but since it’s not very specific I have no idea what it’s trying to tell me, or if that’s, in fact, the reason for the discrepancy.
Am I missing something?
I’m using
pymc 5.10.0
arviz 0.16.1
Thank you.