Hierarchical or multilevel modeling is a generalization of regression modeling. Multilevel models are regression models in which the constituent model parameters are given probability models. This implies that model parameters are allowed to vary by group. Observational units are often naturally clustered. Clustering induces dependence between observations, despite random sampling of clusters and random sampling within clusters.
A hierarchical model is a particular multilevel model where parameters are nested within one another.Some multilevel structures are not hierarchical. e.g. "country" and "year" are not nested, but may represent separate, but overlapping, clusters of parameters. We will motivate this topic using an environmental epidemiology example.
- from pymc import Normal, Model, Uniform
- with Model() as partial_pooling:
-
- # Priors
- mu_a = Normal('mu_a', mu=0., tau=0.0001)
- sigma_a = Uniform('sigma_a', lower=0, upper=100)
- tau_a = sigma_a**-2
-
- # Random intercepts
- a = Normal('a', mu=mu_a, tau=tau_a, shape=len(set(county)))
-
- # Model error
- sigma_y = Uniform('sigma_y', lower=0, upper=100)
- tau_y = sigma_y**-2
-
- # Expected value
- y_hat = a[county]
-
- # Data likelihood
- y_like = Normal('y_like', mu=y_hat, tau=tau_y, observed=log_radon)
本帖隐藏的内容