Richard McElreath in his book Statistical Rethinking Chapter 13 models varying intercepts where categories covary not in a discrete way but based on a continuous variable. In his example he uses euclidean distance as the metric of similarity between data generating points. He then uses this kernel to model the covaration in a MvN distribution between data generating points.
Here is the code in pymc3 for his model:
with pm.Model() as m_13_7_:
# kernel hyperparameters
etasq = pm.HalfCauchy(‘etasq’, 1)
rhosq = pm.HalfCauchy(‘rhosq’, 1)
# kernel function
Kij = etasq * (tt.exp(-rhosq * Dmatsq) + np.diag([.01] * Nsociety))
g = pm.MvNormal('g', mu=np.zeros(Nsociety), cov=Kij, shape=Nsociety) # priors on intercept / slopes a = pm.Normal('a', 0, 10) bp = pm.Normal('bp', 0, 1) # linear model lam = pm.math.exp(a + g[dk.society.values] + bp * dk.logpop) # likelihood
obs = pm.Poisson(‘total_tools’, lam, observed=dk.total_tools)
trace_13_7_ = pm.sample(1000, tune=1000)
I am using a similar style of model and am hoping for speed ups using the marginalsparse method.
How would one reparameterize this inside of the pm.gp class? Or would it be better/easier to get pymc3 to recognize a sparse covariance matrix?