Hierarchical linear regression
In the previous chapter, we learned the rudiments of hierarchical models. We can apply these concepts to linear regression and model several groups at the same time including estimations at the group level and estimations above the group level. As we saw, this is done by including hyperpriors.
We are going to create eight related data groups, including one with just one data point:
N = 20 M = 8 idx = np.repeat(range(M-1), N) idx = np.append(idx, 7) alpha_real = np.random.normal(2.5, 0.5, size=M) beta_real = np.random.beta(60, 10, size=M) eps_real = np.random.normal(0, 0.5, size=len(idx)) y_m = np.zeros(len(idx)) x_m = np.random.normal(10, 1, len(idx)) y_m = alpha_real[idx] + beta_real[idx] * x_m + eps_real
Our data ...
Get Bayesian Analysis with Python now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.