Is a Hirearchical model, using a StudentT distribution and for the formulation I followed a non-centered parameterization.
with pm.Model() as hmodel:
# Hyper priors
mu_a = pm.Normal('alpha', mu=0.0, sigma=0.5)
sigma_a = pm.Exponential('sigma_alpha', lam=1)
sigma_a2 = pm.Exponential('sigma_alpha2', lam=1)
mu_b = pm.Normal("beta", mu=0.5, sigma=0.2)
sigma_b = pm.Exponential('sigma_beta', lam=1)
mu_b2 = pm.Normal("beta2", mu=0, sigma=0.5)
sigma_b2 = pm.Exponential('sigma_beta2', lam=1)
# Varying intercepts by each water year category
za_wtr_yr = pm.Normal('za_wtr_yr', mu=0.0, sigma=1.0, shape=3)
za2_wtr_yr = pm.Normal('za2_wtr_yr', mu=0.0, sigma=1.0, shape=3)
#Varying slopes by each water year category
zb_wtr_yr = pm.Normal('zb_wtr_yr', mu=0.0, sigma=1.0, shape=3)
zb2_wtr_yr = pm.Normal('zb2_wtr_yr', mu=0.0, sigma=1.0, shape=3)
eps = pm.Exponential('eps', 1)
id_wtr_yr = pm.Data("id_wtr_yr", id_wtr_yr_)
id_wtr_yr_lag = pm.Data("id_wtr_yr_lag", id_wtr_yr_lag_)
gw_pump_semi = pm.Data("gw_pump_semi", gw_pump_semi_)
gw_pump_semi_lag = pm.Data("gw_pump_semi_lag", gw_pump_semi_lag_)
depth_est = (mu_a + za_wtr_yr[id_wtr_yr] * sigma_a) + (za2_wtr_yr[id_wtr_yr_lag] * sigma_a2) + (mu_b + zb_wtr_yr[id_wtr_yr] * sigma_b) * gw_pump_semi + (mu_b2 + zb2_wtr_yr[id_wtr_yr_lag] * sigma_b2) * gw_pump_semi_lag
nu = pm.Gamma("nu", alpha=2, beta=0.1)
depth_like = pm.StudentT('depth_like', nu=nu, mu=depth_est, igma=eps,observed=df.std_depth_semi)
Later I use this model for frecast:
with hmodel:
pm.set_data({“gw_pump_semi”: [pump],
“gw_pump_semi_lag”: [pump_lag],
“id_wtr_yr_lag”: [wtr_yr_lag],
“id_wtr_yr”: [wtr_yr]})
p_post = pm.sample_posterior_predictive(trace=gwtrace,random_seed=800,var_names=[“depth_like”])