Hello PyMC3 Community,
I’m new to the Bayesian/PyMC3 community and I’m coming to you with a question about how to make my model make more sense. In my model, I want to have an intercept term that’s informed by the county my data is in which should be informed by the state that my county is in. However, when I finish running my model I end up with lots of coefficients that don’t make sense i.e., a coefficient for a county that doesn’t belong to a given state. Which brings me to my question. Is there a way I can inform my model to not create coefficients for state and county combos that aren’t present in my data?
I’m including my code below with the model with along with a screen shot of the intercept term of my model.
with pm.Model(coords=coords) as hierarchical_model_varying_intercept_county_state:
# Hyper Priors: State
sigma_a_state = pm.HalfNormal("sigma_a_state", 3.)
mu_a_state = pm.Normal("mu_a_state",mu=9., sigma = 2.5)
# State coefficients
a_state_offset = pm.Normal("a_state_offset", mu = 0., sigma = 1., dims="state")
a_state = pm.Deterministic("a_state", mu_a_state + sigma_a_state*a_state_offset)
# Hyper Priors: County
sigma_a_county = pm.HalfNormal("sigma_a_county", 3.)
mu_a_county = pm.Normal("mu_a_county",mu = 0., sigma = 2.5)
# County coefficients
a_county_offset = pm.Normal("a_county_offset", mu = 0., sigma = 1., dims= ("county", "state"))
a_county = pm.Deterministic("a_county", mu_a_county + a_state + sigma_a_county*a_county_offset)
# Model error
epsilon = pm.HalfCauchy("eps", 5.0)
yield_estimate = (
a_county[county_idx, state_idx]
)
# Data likelihood
disease_like = pm.TruncatedNormal("disease_likelihood",
mu=yield_estimate,
sigma=epsilon,
observed = data.disease.values,
dims="obs_id", lower = 0.)