文档中有some examples个用于简单线性模型的公式:
with Model() as model:
GLM.from_formula('y ~ x', data)
trace = sample(2000, cores=2)
文档还具有examples的分层GLM模型:
with pm.Model() as model:
# Uninformative prior for alpha and beta
ab = pm.HalfFlat('ab',
shape=2,
testval=np.asarray([1., 1.]))
pm.Potential('p(a, b)', logp_ab(ab))
X = pm.Deterministic('X',tt.log(ab[0]/ab[1]))
Z = pm.Deterministic('Z',tt.log(tt.sum(ab)))
theta = pm.Beta('theta', alpha=ab[0], beta=ab[1], shape=N)
p = pm.Binomial('y', p=theta, observed=y, n=n)
trace = pm.sample(1000, tune=2000, nuts_kwargs={'target_accept': .95})
我是PyMC的新手,我试图了解如何构建层次模型。
patsy
中更简洁的GLM公式来获得相同的层次模型?