# A Primer on Bayesian Methods for Multilevel Modeling¶

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.

## Example: Radon contamination (Gelman and Hill 2006)¶

Radon is a radioactive gas that enters homes through contact points with the ground. It is a carcinogen that is the primary cause of lung cancer in non-smokers. Radon levels vary greatly from household to household.

The EPA did a study of radon levels in 80,000 houses. There are two important predictors:

• measurement in basement or first floor (radon higher in basements)

• county uranium level (positive correlation with radon levels)

We will focus on modeling radon levels in Minnesota.

The hierarchy in this example is households within county.

## Data organization¶

First, we import the data from a local file, and extract Minnesota’s data.

[1]:
import arviz as az
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import pymc3 as pm
import xarray as xr
import warnings

from theano import tensor as tt

print(f"Running on PyMC3 v{pm.__version__}")
warnings.simplefilter(action="ignore", category=FutureWarning)
RANDOM_SEED = 8924
np.random.seed(286)
Running on PyMC3 v3.9.2
[2]:
az.style.use("arviz-darkgrid")
srrs2.columns = srrs2.columns.map(str.strip)
srrs_mn = srrs2[srrs2.state == "MN"].copy()

Next, obtain the county-level predictor, uranium, by combining two variables.

[3]:
srrs_mn["fips"] = srrs_mn.stfips * 1000 + srrs_mn.cntyfips
cty_mn = cty[cty.st == "MN"].copy()
cty_mn["fips"] = 1000 * cty_mn.stfips + cty_mn.ctfips

Use the merge method to combine home- and county-level information in a single DataFrame.

[4]:
srrs_mn = srrs_mn.merge(cty_mn[["fips", "Uppm"]], on="fips")
srrs_mn = srrs_mn.drop_duplicates(subset="idnum")
u = np.log(srrs_mn.Uppm).unique()

n = len(srrs_mn)
[5]:
[5]:
idnum state state2 stfips zip region typebldg floor room basement ... stopdt activity pcterr adjwt dupflag zipflag cntyfips county fips Uppm
0 5081 MN MN 27 55735 5 1 1 3 N ... 12288 2.2 9.7 1146.499190 1 0 1 AITKIN 27001 0.502054
1 5082 MN MN 27 55748 5 1 0 4 Y ... 12088 2.2 14.5 471.366223 0 0 1 AITKIN 27001 0.502054
2 5083 MN MN 27 55748 5 1 0 4 Y ... 21188 2.9 9.6 433.316718 0 0 1 AITKIN 27001 0.502054
3 5084 MN MN 27 56469 5 1 0 4 Y ... 123187 1.0 24.3 461.623670 0 0 1 AITKIN 27001 0.502054
4 5085 MN MN 27 55011 3 1 0 4 Y ... 13088 3.1 13.8 433.316718 0 0 3 ANOKA 27003 0.428565

5 rows × 27 columns

We also need a lookup table (dict) for each unique county, for indexing.

[6]:
srrs_mn.county = srrs_mn.county.map(str.strip)
mn_counties = srrs_mn.county.unique()
counties = len(mn_counties)
county_lookup = dict(zip(mn_counties, range(counties)))

Finally, create local copies of variables.

[7]:
county = srrs_mn["county_code"] = srrs_mn.county.replace(county_lookup).values
floor = srrs_mn.floor.values

Distribution of radon levels in MN (log scale):

[8]:

## Conventional approaches¶

The two conventional alternatives to modeling radon exposure represent the two extremes of the bias-variance tradeoff:

Complete pooling:

Treat all counties the same, and estimate a single radon level.

$y_i = \alpha + \beta x_i + \epsilon_i$

No pooling:

Model radon in each county independently.

$y_i = \alpha_{j[i]} + \beta x_i + \epsilon_i$

where $$j = 1,\ldots,85$$

The errors $$\epsilon_i$$ may represent measurement error, temporal within-house variation, or variation among houses.

We’ll start by estimating the slope and intercept for the complete pooling model. You’ll notice that we used an index variable instead of an indicator variable in the linear model below. There are two main reasons. One, this generalizes well to more-than-two-category cases. Two, this approach correctly considers that neither category has more prior uncertainty than the other. On the contrary, the indicator variable approach necessarily assumes that one of the categories has more uncertainty than the other: here, the cases when floor=1 would take into account 2 priors ($$\alpha + \beta$$), whereas cases when floor=0 would have only one prior ($$\alpha$$). But a priori we aren’t more unsure about floor measurements than about basement measurements, so it makes sense to give them the same prior uncertainty.

Now for the model:

[9]:
coords = {"Level": ["Basement", "Floor"], "obs_id": np.arange(floor.size)}
with pm.Model(coords=coords) as pooled_model:
floor_idx = pm.Data("floor_idx", floor, dims="obs_id")
a = pm.Normal("a", 0.0, sigma=10.0, dims="Level")

theta = a[floor_idx]
sigma = pm.Exponential("sigma", 1.0)

y = pm.Normal("y", theta, sigma=sigma, observed=log_radon, dims="obs_id")

pm.model_to_graphviz(pooled_model)
[9]:

You may be wondering why we are using the pm.Data container above even though the variable floor_idx is not an observed variable nor a parameter of the model. As you’ll see, this will make our lives much easier when we’ll plot and diagnose our model. In short, this will tell ArviZ that floor_idx is information used by the model to index variables. ArviZ will thus include floor_idx as a variable in the constant_data group of the resulting InferenceData <https://arviz-devs.github.io/arviz/notebooks/XarrayforArviZ.html>__ object. Moreover, including floor_idx in the InferenceData object makes sharing and reproducing analysis much easier, all the data needed to analyze or rerun the model is stored there.

Before running the model let’s do some prior predictive checks. Indeed, having sensible priors is not only a way to incorporate scientific knowledge into the model, it can also help and make the MCMC machinery faster – here we are dealing with a simple linear regression, so no link function comes and distorts the outcome space; but one day this will happen to you and you’ll need to think hard about your priors to help your MCMC sampler. So, better to train ourselves when it’s quite easy than having to learn when it’s very hard… There is a really neat function to do that in PyMC3:

[10]:
with pooled_model:
prior_checks = pm.sample_prior_predictive(random_seed=RANDOM_SEED)
idata_prior = az.from_pymc3(prior=prior_checks)

_, ax = plt.subplots()
idata_prior.prior.plot.scatter(x="Level", y="a", color="k", alpha=0.2, ax=ax)

ArviZ InferenceData uses xarray.Datasets under the hood, which give access to several common plotting functions with .plot. In this case, we want scatter plot of the mean log radon level (which is stored in variable a) for each of the two levels we are considering. If our desired plot is supported by xarray plotting capabilities, we can take advantage of xarray to automatically generate both plot and labels for us. Notice how everything is directly plotted and annotated, the only change we need to do is renaming the y axis label from a to Mean log radon level.

I’m no expert in radon levels, but, before seing the data, these priors seem to allow for quite a wide range of the mean log radon level. But don’t worry, we can always change these priors if sampling gives us hints that they might not be appropriate – after all, priors are assumptions, not oaths; and as most assumptions, they can be tested.

However, we can already think of an improvement. Do you see it? Remember what we said at the beginning: radon levels tend to be higher in basements, so we could incorporate this prior scientific knowledge into our model by giving $$a_{basement}$$ a higher mean than $$a_{floor}$$. Here, there are so much data that the prior should be washed out anyway, but we should keep this fact in mind – for future cases or if sampling proves more difficult than expected…

Speaking of sampling, let’s fire up the Bayesian machinery!

[11]:
with pooled_model:
pooled_trace = pm.sample(random_seed=RANDOM_SEED)
pooled_idata = az.from_pymc3(pooled_trace)
az.summary(pooled_idata, round_to=2)
Auto-assigning NUTS sampler...
Multiprocess sampling (4 chains in 4 jobs)
NUTS: [sigma, a]
100.00% [8000/8000 00:02<00:00 Sampling 4 chains, 0 divergences]
Sampling 4 chains for 1_000 tune and 1_000 draw iterations (4_000 + 4_000 draws total) took 2 seconds.
[11]:
mean sd hdi_3% hdi_97% mcse_mean mcse_sd ess_mean ess_sd ess_bulk ess_tail r_hat
a[0] 1.36 0.03 1.31 1.42 0.0 0.0 5575.60 5574.11 5537.43 3084.72 1.0
a[1] 0.78 0.06 0.66 0.90 0.0 0.0 5498.84 5488.15 5471.73 2757.02 1.0
sigma 0.79 0.02 0.76 0.83 0.0 0.0 5425.61 5418.60 5409.46 3220.75 1.0

No divergences and a sampling that only took seconds – this is the Flash of samplers! Here the chains look very good (good R hat, good effective sample size, small sd), but remember to check your chains after sampling – az.plot_trace is usually a good start.

Let’s see what it means on the outcome space: did the model pick-up the negative relationship between floor measurements and log radon levels? What’s the uncertainty around its estimates? To estimate the uncertainty around the household radon levels (not the average level, but measurements that would be likely in households), we need to sample the likelihood y from the model. In another words, we need to do posterior predictive checks:

[12]:
with pooled_model:
ppc = pm.sample_posterior_predictive(pooled_trace, random_seed=RANDOM_SEED)
pooled_idata = az.from_pymc3(pooled_trace, posterior_predictive=ppc, prior=prior_checks)
100.00% [4000/4000 00:03<00:00]

We have now converted our trace and posterior predictive samples into an arviz.InferenceData object. InferenceData is specifically designed to centralize all the relevant quantities of a Bayesian inference workflow into a single object. This will also make the rendering of plots and diagnostics faster – otherwise ArviZ will need to convert your trace to InferenceData each time you call it.

[13]:
pooled_idata
[13]:
arviz.InferenceData
• xarray.Dataset
• Level: 2
• chain: 4
• draw: 1000
• chain
(chain)
int64
0 1 2 3
array([0, 1, 2, 3])
• draw
(draw)
int64
0 1 2 3 4 5 ... 995 996 997 998 999
array([  0,   1,   2, ..., 997, 998, 999])
• Level
(Level)
<U8
'Basement' 'Floor'
array(['Basement', 'Floor'], dtype='<U8')
• a
(chain, draw, Level)
float64
1.36 0.8198 1.379 ... 1.372 0.669
array([[[1.36003081, 0.81977505],
[1.37920395, 0.66651084],
[1.38843716, 0.73977369],
...,
[1.3808629 , 0.77455787],
[1.36854138, 0.76905752],
[1.36623622, 0.80602402]],

[[1.304446  , 0.78838488],
[1.27732718, 0.78443489],
[1.28471339, 0.79588536],
...,
[1.33343979, 0.74229685],
[1.377951  , 0.78555699],
[1.40959545, 0.82210539]],

[[1.39806331, 0.7761219 ],
[1.33757218, 0.81386552],
[1.34304989, 0.82311483],
...,
[1.37208126, 0.79705118],
[1.36599617, 0.73993194],
[1.37137703, 0.83027871]],

[[1.32105078, 0.72270027],
[1.32206321, 0.73551535],
[1.39273143, 0.76878013],
...,
[1.33261996, 0.83296046],
[1.36090689, 0.73292274],
[1.37228387, 0.66896247]]])
• sigma
(chain, draw)
float64
0.8159 0.7656 ... 0.8082 0.8136
array([[0.81591061, 0.76558976, 0.78261912, ..., 0.79732297, 0.79384231,
0.8227709 ],
[0.79839321, 0.79900885, 0.78482389, ..., 0.75153775, 0.76896342,
0.79116258],
[0.78922225, 0.7721042 , 0.78189829, ..., 0.79389866, 0.78118743,
0.77926888],
[0.78728498, 0.79573539, 0.81175752, ..., 0.76108708, 0.80816283,
0.81360926]])
• created_at :
2020-06-29T15:32:28.155588
arviz_version :
0.9.0
inference_library :
pymc3
inference_library_version :
3.9.2
sampling_time :
2.229020118713379
tuning_steps :
1000

• xarray.Dataset
• chain: 4
• draw: 1000
• obs_id: 919
• chain
(chain)
int64
0 1 2 3
array([0, 1, 2, 3])
• draw
(draw)
int64
0 1 2 3 4 5 ... 995 996 997 998 999
array([  0,   1,   2, ..., 997, 998, 999])
• obs_id
(obs_id)
int64
0 1 2 3 4 5 ... 914 915 916 917 918
array([  0,   1,   2, ..., 916, 917, 918])
• y
(chain, draw, obs_id)
float64
1.725 1.314 1.424 ... 2.064 2.282
array([[[ 1.72472544,  1.31445151,  1.42365609, ...,  1.18250864,
2.75272475,  2.65149084],
[ 1.18964108,  1.50385018,  1.18541763, ...,  2.11849695,
0.38012737,  1.91266818],
[ 0.85144292,  1.33360976,  1.20450892, ...,  0.85999651,
1.15073918,  2.03686851],
...,
[ 0.67311258,  1.45060305, -0.34311737, ...,  2.61566098,
2.34505068,  1.06794886],
[ 1.50528551,  0.3288518 ,  0.65422444, ...,  0.50475773,
0.38521335,  1.81753607],
[ 2.34468257,  1.43525342,  0.82484275, ...,  1.00520813,
0.74639388,  1.66720179]],

[[ 0.37876057,  0.82322464,  1.71935313, ...,  3.27862212,
1.46451829,  1.645308  ],
[-0.09337309,  1.2972835 , -0.81646107, ...,  1.46488027,
1.42906209,  1.74001415],
[ 0.71778986, -0.6062489 ,  2.14934778, ...,  1.68912651,
0.20009612,  0.15962525],
...,
[ 1.29597786,  1.67130944,  2.07639762, ...,  2.67812302,
1.12478763,  1.44138921],
[ 2.40869621,  1.42860443,  1.18201287, ...,  2.89503179,
2.32400947,  1.94186751],
[ 1.38133179,  0.21709599,  1.69663929, ...,  1.85833737,
1.84244049,  0.2283722 ]],

[[-0.31052659,  1.50912383,  0.02236094, ...,  3.63727411,
0.97330499,  2.30221729],
[ 0.9862554 ,  2.54743129,  3.01278281, ...,  1.56867454,
1.17988129,  0.4350395 ],
[ 1.88716638,  0.87640842,  2.23021753, ...,  2.01076723,
0.6573071 ,  2.10437785],
...,
[ 1.51980878,  1.79842498,  1.46920825, ...,  2.21372649,
0.25295592,  1.68968592],
[ 0.57564921,  1.53225937,  1.49230863, ...,  1.35392686,
1.77504792,  0.2909977 ],
[ 1.73176918,  0.49713767,  2.64885015, ...,  1.27559601,
0.08050368,  1.49078798]],

[[ 0.25829276,  1.76490637,  1.10697522, ...,  0.94841791,
1.76130593,  1.49555782],
[ 0.53564721,  1.05569348,  0.6641274 , ...,  1.72062385,
1.95174347,  1.79212754],
[ 1.35863274,  1.05822114,  2.23314952, ...,  1.35760996,
1.17390869,  2.12992547],
...,
[ 1.1797652 ,  1.85766736,  2.60367467, ...,  1.64131037,
1.82346733,  1.14784485],
[-0.702155  ,  1.05113162,  1.40164217, ...,  0.14609939,
1.84966703,  1.04425182],
[ 1.14366067,  0.63654963,  1.91589791, ...,  0.597106  ,
2.06407734,  2.28241194]]])
• created_at :
2020-06-29T15:32:28.416163
arviz_version :
0.9.0
inference_library :
pymc3
inference_library_version :
3.9.2

• xarray.Dataset
• chain: 4
• draw: 1000
• obs_id: 919
• chain
(chain)
int64
0 1 2 3
array([0, 1, 2, 3])
• draw
(draw)
int64
0 1 2 3 4 5 ... 995 996 997 998 999
array([  0,   1,   2, ..., 997, 998, 999])
• obs_id
(obs_id)
int64
0 1 2 3 4 5 ... 914 915 916 917 918
array([  0,   1,   2, ..., 916, 917, 918])
• y
(chain, draw, obs_id)
float64
-0.7156 -0.9242 ... -0.7137 -0.7692
array([[[-0.71561762, -0.92418045, -0.76681643, ..., -0.76992156,
-0.7159586 , -0.76681643],
[-0.67544947, -0.90641421, -0.71899228, ..., -0.70516135,
-0.6534965 , -0.71899228],
[-0.68091047, -0.92576008, -0.74240039, ..., -0.72116569,
-0.67616038, -0.74240039],
...,
[-0.69512103, -0.92859382, -0.75510032, ..., -0.74096372,
-0.69409735, -0.75510032],
[-0.69130288, -0.91570096, -0.74587782, ..., -0.74199193,
-0.68896065, -0.74587782],
[-0.72439491, -0.93394818, -0.77676182, ..., -0.77495128,
-0.72458165, -0.77676182]],

[[-0.69533947, -0.86819299, -0.72701746, ..., -0.77653176,
-0.6945168 , -0.72701746],
[-0.69639558, -0.84924099, -0.71956958, ..., -0.79154782,
-0.69716038, -0.71956958],
[-0.67775533, -0.84234402, -0.70475666, ..., -0.77299721,
-0.67869541, -0.70475666],
...,
[-0.64057316, -0.85508847, -0.68212116, ..., -0.71076281,
-0.63330685, -0.68212116],
[-0.65812266, -0.90742594, -0.72220796, ..., -0.7096225 ,
-0.65778651, -0.72220796],
[-0.68477997, -0.95034164, -0.76193919, ..., -0.72322406,
-0.68913152, -0.76193919]],

[[-0.68481987, -0.93862369, -0.75421307, ..., -0.72513164,
-0.68542357, -0.75421307],
[-0.66060694, -0.87391259, -0.70819535, ..., -0.73165323,
-0.66030831, -0.70819535],
[-0.67298638, -0.88574611, -0.72177378, ..., -0.73989336,
-0.67296091, -0.72177378],
...,
[-0.68915909, -0.91875789, -0.74746656, ..., -0.740601  ,
-0.68922982, -0.74746656],
[-0.67908129, -0.90483739, -0.73057575, ..., -0.72877605,
-0.67278549, -0.73057575],
[-0.6695451 , -0.90827379, -0.73079867, ..., -0.72428827,
-0.67062889, -0.73079867]],

[[-0.68957158, -0.87199321, -0.71968761, ..., -0.75639361,
-0.67993054, -0.71968761],
[-0.69794019, -0.87939001, -0.72987725, ..., -0.76495935,
-0.69058214, -0.72987725],
[-0.71350544, -0.94818817, -0.77602423, ..., -0.75282861,
-0.71291379, -0.77602423],
...,
[-0.64593104, -0.86147648, -0.69319841, ..., -0.72187686,
-0.64593593, -0.69319841],
[-0.71360021, -0.91936746, -0.75861532, ..., -0.76106851,
-0.70646059, -0.75861532],
[-0.73296569, -0.93240871, -0.76923497, ..., -0.76253562,
-0.7137134 , -0.76923497]]])
• created_at :
2020-06-29T15:32:28.414738
arviz_version :
0.9.0
inference_library :
pymc3
inference_library_version :
3.9.2

• xarray.Dataset
• chain: 4
• draw: 1000
• chain
(chain)
int64
0 1 2 3
array([0, 1, 2, 3])
• draw
(draw)
int64
0 1 2 3 4 5 ... 995 996 997 998 999
array([  0,   1,   2, ..., 997, 998, 999])
• step_size
(chain, draw)
float64
1.092 1.092 1.092 ... 1.369 1.369
array([[1.09190406, 1.09190406, 1.09190406, ..., 1.09190406, 1.09190406,
1.09190406],
[1.20961785, 1.20961785, 1.20961785, ..., 1.20961785, 1.20961785,
1.20961785],
[1.06967901, 1.06967901, 1.06967901, ..., 1.06967901, 1.06967901,
1.06967901],
[1.36922931, 1.36922931, 1.36922931, ..., 1.36922931, 1.36922931,
1.36922931]])
• energy
(chain, draw)
float64
1.097e+03 1.097e+03 ... 1.096e+03
array([[1096.66734722, 1097.43137346, 1096.03199987, ..., 1095.62971323,
1094.18541554, 1096.13821516],
[1097.12802458, 1098.84256782, 1099.53751898, ..., 1099.32093067,
1096.59624855, 1096.14886898],
[1095.85042184, 1097.44945597, 1095.02233924, ..., 1094.58624706,
1095.29270767, 1096.35249165],
[1097.04498154, 1095.73920371, 1097.48208061, ..., 1097.09203406,
1097.93015051, 1096.31975324]])
• max_energy_error
(chain, draw)
float64
0.4696 0.5671 ... 0.8329 0.5076
array([[ 0.46955093,  0.56712523, -0.78655606, ...,  0.33638964,
-0.11098879,  0.94936003],
[-0.12710124,  0.74607733, -0.12455709, ...,  0.97460651,
-0.77557688,  0.27401945],
[ 0.22714146,  0.85246213, -0.30971579, ...,  0.164446  ,
0.33800096,  1.12707475],
[-0.78466638, -0.43826189,  0.91415026, ...,  0.80680591,
0.83286512,  0.50763949]])
• mean_tree_accept
(chain, draw)
float64
0.6627 0.8024 1.0 ... 0.8911 0.8738
array([[0.66265343, 0.80241632, 1.        , ..., 0.9306354 , 1.        ,
0.69078831],
[1.        , 0.47422313, 1.        , ..., 0.60874491, 1.        ,
0.82318492],
[0.91855343, 0.64133549, 1.        , ..., 0.90773314, 0.81942209,
0.70071852],
[1.        , 1.        , 0.7371465 , ..., 0.7321354 , 0.89114853,
0.87376245]])
• tree_size
(chain, draw)
float64
3.0 3.0 1.0 3.0 ... 3.0 3.0 3.0 3.0
array([[3., 3., 1., ..., 3., 3., 3.],
[1., 1., 1., ..., 3., 3., 3.],
[3., 3., 3., ..., 3., 3., 3.],
[1., 3., 3., ..., 3., 3., 3.]])
• step_size_bar
(chain, draw)
float64
1.119 1.119 1.119 ... 1.149 1.149
array([[1.1194909 , 1.1194909 , 1.1194909 , ..., 1.1194909 , 1.1194909 ,
1.1194909 ],
[1.11545333, 1.11545333, 1.11545333, ..., 1.11545333, 1.11545333,
1.11545333],
[1.13841975, 1.13841975, 1.13841975, ..., 1.13841975, 1.13841975,
1.13841975],
[1.14910816, 1.14910816, 1.14910816, ..., 1.14910816, 1.14910816,
1.14910816]])
• depth
(chain, draw)
int64
2 2 1 2 2 2 2 2 ... 2 2 2 2 2 2 2 2
array([[2, 2, 1, ..., 2, 2, 2],
[1, 1, 1, ..., 2, 2, 2],
[2, 2, 2, ..., 2, 2, 2],
[1, 2, 2, ..., 2, 2, 2]])
• energy_error
(chain, draw)
float64
0.0 0.4863 ... -0.3683 0.5076
array([[ 0.        ,  0.48627072, -0.78655606, ..., -0.1918688 ,
-0.09102834,  0.63727907],
[-0.12710124,  0.74607733, -0.12455709, ...,  0.25001608,
-0.77557688,  0.27401945],
[-0.02755983,  0.17120786, -0.16377546, ..., -0.05422448,
0.04345316,  0.06434738],
[-0.78466638, -0.08243175,  0.00595899, ...,  0.52918868,
-0.3683263 ,  0.50763949]])
• lp
(chain, draw)
float64
-1.095e+03 ... -1.096e+03
array([[-1095.17668016, -1096.58855593, -1094.62076592, ...,
-1094.26442405, -1094.02451712, -1095.61667491],
[-1096.12152448, -1098.45193046, -1097.79813716, ...,
-1096.9743661 , -1094.77346076, -1095.5942442 ],
[-1094.74813049, -1095.00030373, -1094.56147563, ...,
-1094.10753825, -1094.23620135, -1094.54098501],
[-1095.37867276, -1095.20749226, -1095.21532245, ...,
-1096.23154933, -1094.68757211, -1096.17273164]])
• diverging
(chain, draw)
bool
False False False ... False False
array([[False, False, False, ..., False, False, False],
[False, False, False, ..., False, False, False],
[False, False, False, ..., False, False, False],
[False, False, False, ..., False, False, False]])
• created_at :
2020-06-29T15:32:28.161093
arviz_version :
0.9.0
inference_library :
pymc3
inference_library_version :
3.9.2
sampling_time :
2.229020118713379
tuning_steps :
1000

• xarray.Dataset
• Level: 2
• chain: 1
• draw: 500
• chain
(chain)
int64
0
array([0])
• draw
(draw)
int64
0 1 2 3 4 5 ... 495 496 497 498 499
array([  0,   1,   2, ..., 497, 498, 499])
• Level
(Level)
<U8
'Basement' 'Floor'
array(['Basement', 'Floor'], dtype='<U8')
• sigma
(chain, draw)
float64
0.606 0.9084 ... 0.3994 0.2126
array([[6.05955282e-01, 9.08446169e-01, 7.17482115e-01, 1.33522137e+00,
1.96531239e-01, 6.42556442e-03, 8.32377910e-01, 4.31819937e+00,
9.24898193e-01, 2.11971737e+00, 2.60050891e+00, 3.49022583e-01,
6.32872621e-01, 2.66909520e-01, 1.97761998e-01, 6.98332002e-01,
3.52226850e-01, 1.03552667e+00, 3.43718836e-01, 2.05740498e-01,
1.75522739e+00, 1.08076293e+00, 2.21714774e-01, 6.19876497e-01,
2.12352800e+00, 9.92174903e-01, 4.94515621e+00, 5.82470140e-01,
1.21951729e+00, 1.51516342e-01, 6.97969321e-02, 1.10419699e+00,
4.85447548e-01, 8.48273985e-01, 1.61637757e+00, 1.65730671e+00,
1.27606323e+00, 5.29669741e-01, 4.61018646e-01, 8.88318064e-01,
9.68271046e-01, 1.72699775e-01, 6.28400469e-01, 3.49134396e-02,
4.27383303e-01, 3.85895578e-01, 2.22147865e+00, 7.68438071e-01,
8.90273145e-02, 1.11110950e+00, 5.71461155e-01, 8.63167951e-01,
4.93875489e-01, 2.95943114e-01, 4.78118705e-01, 2.07269323e+00,
3.39269064e+00, 4.10185996e-01, 7.03602592e-01, 2.90868663e-01,
6.03879724e-01, 1.52643321e+00, 6.07334495e-02, 3.74655281e-01,
2.12385555e-01, 9.43435448e-01, 1.96836029e+00, 2.93462127e-01,
1.47655417e-01, 1.03253542e-01, 3.65081695e-01, 3.33889324e-01,
3.34978399e+00, 9.12910726e-02, 2.59246638e-01, 3.08096015e+00,
2.98668863e-01, 7.74595404e-01, 2.79777183e-01, 1.34695653e+00,
1.53470192e-01, 1.53578941e+00, 1.65847694e+00, 1.07991461e+00,
4.73699516e-01, 1.99942125e+00, 9.22574476e-02, 7.52880832e-01,
1.50014819e+00, 6.19228337e-01, 6.46919737e-01, 1.59516507e+00,
2.69980578e-01, 2.51134177e-01, 4.57285376e-02, 1.43827294e+00,
8.50644053e-01, 1.32584159e+00, 2.02044421e+00, 1.40533754e+00,
3.88158018e-02, 2.90438454e+00, 1.38941097e-01, 4.25694602e-01,
4.88254687e-01, 3.28776677e+00, 3.77139758e+00, 4.30638453e-01,
5.26755826e-01, 2.47162491e-01, 1.32109777e+00, 1.18958586e-01,
1.15237722e+00, 1.42275591e+00, 3.67306941e+00, 3.49509903e-01,
9.08359303e-01, 4.47743377e-01, 6.42220572e-01, 1.05027370e-01,
8.74764252e-01, 4.56021860e-01, 1.36363738e+00, 8.10707041e-01,
2.85208575e+00, 1.84856410e-01, 1.67645350e-01, 2.35372241e-01,
5.02114858e-01, 1.35063954e+00, 6.09983915e-01, 7.71305672e-01,
1.96949825e-01, 3.10527739e-01, 7.24934777e-01, 3.31173428e-01,
3.18496346e-01, 1.91675413e+00, 6.16083593e-01, 4.43659310e-01,
1.37344686e+00, 1.83662034e-01, 4.52667200e-02, 9.28189159e-01,
1.44302931e-01, 1.30550502e+00, 3.96145316e-02, 8.02031497e-01,
8.52773619e-01, 7.96923080e-01, 2.20373972e-01, 2.48552565e+00,
1.19684966e+00, 4.44905045e-01, 1.10926136e+00, 1.79027706e-01,
6.17574403e-01, 1.52736292e+00, 1.01867603e+00, 2.18265128e-01,
1.45915317e+00, 3.72998030e+00, 1.76764164e-01, 1.36087286e+00,
2.55640886e+00, 1.09229075e+00, 4.16293609e+00, 1.01124903e+00,
2.66082562e-01, 1.33567595e+00, 6.26843299e-02, 5.23335872e-01,
1.02725640e+00, 7.34877112e-01, 2.47070175e-01, 1.97016642e+00,
2.05784269e-01, 8.39458205e-01, 2.83382912e-01, 9.57728640e-01,
3.59317467e-01, 4.05671990e-02, 4.51464985e-03, 1.46136554e+00,
1.48203062e-01, 1.71364041e+00, 1.42748744e+00, 3.01185103e-02,
1.10430859e+00, 8.73360538e-01, 1.79988191e+00, 4.57134454e-01,
9.95913174e-01, 3.36694292e+00, 9.82315321e-01, 2.78095232e-01,
6.51559540e-01, 1.67700989e+00, 1.10173490e+00, 3.37369569e-01,
4.82509213e-02, 2.33188914e-02, 2.58258496e+00, 2.07756648e+00,
7.64353811e-02, 2.63731510e+00, 2.02583694e-01, 1.98571493e+00,
7.31721278e-01, 3.05318900e-01, 5.24565379e-01, 1.21649270e+00,
1.33069091e-01, 1.03716477e+00, 2.96650002e+00, 6.62168243e-01,
2.02190644e+00, 3.04687422e-01, 3.03007878e+00, 1.84279255e-01,
1.02064967e+00, 3.87441404e+00, 1.07989085e+00, 1.76274712e-01,
3.46213425e-01, 4.29487038e-01, 2.57600724e+00, 3.37379766e-01,
8.49091391e-01, 4.38300133e-01, 4.10582964e-03, 5.30928029e-01,
4.20197293e-01, 2.09892694e+00, 1.27857239e+00, 2.15294852e+00,
1.18125685e+00, 5.73634909e-01, 3.76918916e-01, 9.87516336e-01,
2.25391619e-01, 9.16387428e-01, 7.54394463e-02, 3.65803133e+00,
1.80265001e-01, 2.68288214e-01, 2.70784838e+00, 9.15058760e-01,
3.42802138e-01, 2.37261763e-01, 2.95515790e-01, 4.67580074e-02,
2.97412333e+00, 1.14650621e+00, 4.16693813e+00, 5.05983694e-01,
3.60441503e-02, 3.21850113e-01, 5.59235316e-01, 5.79494362e-01,
1.28505638e+00, 1.98828443e+00, 4.37289526e+00, 1.02276981e+00,
9.08632070e-01, 3.13261983e-01, 2.78139201e-01, 1.16550714e+00,
1.97801476e-01, 9.38301457e-01, 1.08370137e-01, 4.76550597e-01,
4.84589772e-01, 2.80202156e-01, 8.55404111e-01, 7.93531943e-01,
7.71923142e-01, 4.83715554e-01, 3.93039943e-01, 2.50478929e-01,
3.43996935e-01, 8.34142449e-01, 1.02139769e-01, 3.27166668e+00,
2.05498478e+00, 9.11921465e-02, 1.22512578e-01, 5.26384698e-01,
3.97577955e-01, 1.59609323e+00, 1.52438299e-01, 1.72311553e+00,
1.11266858e+00, 3.53558799e-01, 1.81135777e+00, 6.79781216e-01,
1.79580995e-01, 8.18128757e-01, 1.06164940e-01, 7.63931518e-01,
2.44263848e-01, 3.22498334e-01, 6.64609538e-02, 3.32904103e+00,
2.58844808e+00, 1.15860554e-01, 9.58357343e-02, 8.71582480e-01,
1.60068606e+00, 1.25896568e+00, 1.13077320e+00, 3.82953695e-01,
1.13330471e+00, 3.62819321e-01, 7.92637745e-01, 1.26864430e+00,
1.17804018e+00, 9.24540027e-01, 1.42274143e+00, 1.09571378e+00,
9.20047529e-01, 4.76536220e-01, 8.33490606e-01, 2.32257897e+00,
1.77853710e-01, 6.91422442e-01, 1.48066985e-01, 1.11194092e+00,
1.67442707e+00, 1.43908317e+00, 5.19773503e-01, 1.56492914e-01,
6.77141891e-01, 2.88224720e+00, 3.42396698e-02, 2.62582390e+00,
1.46445907e+00, 1.01560934e+00, 6.77355661e-01, 3.10042005e-04,
4.10971268e-01, 1.03309392e-01, 1.81001459e+00, 2.55127842e+00,
5.29844662e+00, 1.34631529e-01, 5.51932550e-01, 2.58152190e-02,
1.99090314e-01, 5.60453074e-01, 2.83290638e-01, 1.71058892e-01,
4.47827439e-01, 3.28428051e-01, 1.51477169e-01, 7.41568850e-01,
2.86727480e+00, 4.14212911e-02, 1.33935866e-01, 1.86178093e-01,
2.79158048e-01, 7.00857639e-01, 6.72041368e-01, 1.89073499e+00,
1.53272271e+00, 3.31899214e+00, 2.71274151e-02, 7.38614672e-02,
3.27922408e-03, 1.16895667e+00, 1.61097612e+00, 3.55342997e-01,
1.31997337e+00, 1.09336356e+00, 4.08150039e-01, 7.12326777e-01,
7.85913610e-01, 6.36525742e-01, 7.43592011e-01, 2.38335290e-01,
7.09944444e-01, 5.98738497e-01, 7.80885409e-01, 1.69871169e+00,
2.31612523e+00, 4.54690939e-01, 1.72414596e+00, 5.86836109e-01,
1.89403601e-01, 1.43615984e+00, 5.46621218e-01, 1.04609712e+00,
1.01301480e+00, 1.94049536e+00, 5.22422297e-01, 7.52445354e-01,
3.37617484e-01, 1.21980270e+00, 8.24626805e-01, 1.04697051e+00,
1.13826582e+00, 1.19611162e+00, 4.12132489e-01, 3.82694598e+00,
6.74009367e-01, 3.78477426e-01, 5.04558742e+00, 8.36598550e-01,
6.88114639e-01, 7.01650288e-01, 1.25659988e+00, 2.70015632e-01,
9.03985047e-01, 3.27353187e-01, 3.65307413e+00, 3.20136405e-01,
5.05533581e-01, 1.19475148e-01, 9.55225034e-01, 4.47768250e-01,
2.42089991e+00, 9.31313089e-01, 1.06342830e-01, 1.51802346e-01,
6.58765892e-01, 4.57522106e-01, 2.33776041e+00, 6.94539640e-01,
1.01818597e+00, 1.93337747e+00, 8.74427686e-01, 3.13191951e+00,
1.83389526e-01, 2.63303922e-01, 9.65751244e-02, 4.24613409e-02,
1.22944710e-01, 1.60261133e+00, 2.37405976e-01, 2.67989888e-01,
8.05479209e-01, 2.80000846e-01, 4.23548426e-02, 1.15864440e+00,
1.49158993e+00, 1.08838290e-01, 7.84326212e-02, 7.33925572e-02,
1.40824055e-01, 1.29622162e+00, 1.69602768e+00, 4.99128592e-01,
1.31775161e+00, 2.81043356e+00, 2.53330172e-01, 3.79053855e-01,
9.47833915e-01, 1.96369868e+00, 6.57931115e-01, 3.55463476e-02,
6.39395017e-01, 1.59680239e+00, 9.33865611e-01, 5.44049381e-01,
2.28568384e+00, 1.50016475e+00, 1.22924236e+00, 5.34128164e-01,
2.09262719e+00, 1.93746376e+00, 7.26735607e-01, 9.98261438e-01,
8.09102055e-01, 8.90602841e-01, 2.16955900e-02, 8.07507358e-01,
3.00067940e-01, 1.00966625e-01, 2.50763961e+00, 2.76052931e+00,
2.12792553e-01, 2.08773287e-01, 7.08299248e-01, 1.64557096e-01,
3.24983494e-02, 1.12277584e+00, 1.89836931e+00, 6.14644161e-01,
1.15357076e+00, 7.67356406e-01, 2.73723850e+00, 3.62539055e-01,
1.65323257e-01, 2.58205167e+00, 4.82031592e-01, 2.40903905e+00,
3.65120192e-01, 8.26966891e-02, 3.99350461e-01, 2.12576428e-01]])
• sigma_log__
(chain, draw)
float64
-0.5009 -0.09602 ... -0.9179 -1.548
array([[-5.00949087e-01, -9.60196452e-02, -3.32007258e-01,
2.89097095e-01, -1.62693389e+00, -5.04747080e+00,
-1.83468722e-01,  1.46283850e+00, -7.80716094e-02,
7.51282762e-01,  9.55707159e-01, -1.05261865e+00,
-4.57486108e-01, -1.32084555e+00, -1.62069100e+00,
-3.59060642e-01, -1.04347985e+00,  3.49101615e-02,
-1.06793129e+00, -1.58113962e+00,  5.62598418e-01,
7.76672070e-02, -1.50636352e+00, -4.78235020e-01,
7.53078858e-01, -7.85587390e-03,  1.59840855e+00,
-5.40477357e-01,  1.98455117e-01, -1.88706179e+00,
-2.66216522e+00,  9.91183662e-02, -7.22684034e-01,
-1.64551600e-01,  4.80187576e-01,  5.05193820e-01,
2.43779740e-01, -6.35501596e-01, -7.74316791e-01,
-1.18425420e-01, -3.22432242e-02, -1.75620060e+00,
-4.64577627e-01, -3.35488344e+00, -8.50074003e-01,
-9.52188469e-01,  7.98173033e-01, -2.63395303e-01,
-2.41881205e+00,  1.05359068e-01, -5.59558769e-01,
-1.47145994e-01, -7.05471839e-01, -1.21758803e+00,
-7.37896241e-01,  7.28848839e-01,  1.22162330e+00,
-8.91144574e-01, -3.51541582e-01, -1.23488344e+00,
-5.04380233e-01,  4.22933780e-01, -2.80126067e+00,
-9.81748926e-01, -1.54935200e+00, -5.82273341e-02,
6.77200855e-01, -1.22600669e+00, -1.91287399e+00,
-2.27056774e+00, -1.00763413e+00, -1.09694571e+00,
1.20889586e+00, -2.39370228e+00, -1.34997540e+00,
1.12524128e+00, -1.20841980e+00, -2.55414445e-01,
-1.27376177e+00,  2.97847622e-01, -1.87424892e+00,
4.29044522e-01,  5.05899676e-01,  7.68819768e-02,
-7.47182090e-01,  6.92857762e-01, -2.38317227e+00,
-2.83848322e-01,  4.05563899e-01, -4.79281194e-01,
-4.35533046e-01,  4.66977223e-01, -1.30940526e+00,
-1.38176791e+00, -3.08503272e+00,  3.63443048e-01,
-1.61761507e-01,  2.82047421e-01,  7.03317394e-01,
3.40277516e-01, -3.24892785e+00,  1.06622151e+00,
-1.97370520e+00, -8.54033086e-01, -7.16918110e-01,
1.19020854e+00,  1.32744564e+00, -8.42486397e-01,
-6.41018166e-01, -1.39770930e+00,  2.78463033e-01,
-2.12897987e+00,  1.41826961e-01,  3.52595775e-01,
1.30102766e+00, -1.05122338e+00, -9.61152703e-02,
-8.03535030e-01, -4.42823465e-01, -2.25353429e+00,
-1.33800855e-01, -7.85214531e-01,  3.10155673e-01,
-2.09848522e-01,  1.04805057e+00, -1.68817592e+00,
-1.78590454e+00, -1.44658701e+00, -6.88926386e-01,
3.00578216e-01, -4.94322691e-01, -2.59670523e-01,
-1.62480628e+00, -1.16948204e+00, -3.21673592e-01,
-1.10511309e+00, -1.14414428e+00,  6.50633197e-01,
-4.84372621e-01, -8.12698331e-01,  3.17323533e-01,
-1.69465798e+00, -3.09518317e+00, -7.45197315e-02,
-1.93584050e+00,  2.66589956e-01, -3.22855927e+00,
-2.20607399e-01, -1.59261161e-01, -2.26997117e-01,
-1.51242930e+00,  9.10484167e-01,  1.79692823e-01,
-8.09894402e-01,  1.03694352e-01, -1.72021471e+00,
-4.81955728e-01,  4.23542666e-01,  1.85037768e-02,
-1.52204477e+00,  3.77856247e-01,  1.31640295e+00,
-1.73293884e+00,  3.08126300e-01,  9.38603485e-01,
8.82771003e-02,  1.42622062e+00,  1.11862314e-02,
-1.32394863e+00,  2.89437490e-01, -2.76964379e+00,
-6.47531819e-01,  2.68915617e-02, -3.08051988e-01,
-1.39808287e+00,  6.78118019e-01, -1.58092690e+00,
-1.74998589e-01, -1.26095625e+00, -4.31907977e-02,
-1.02354897e+00, -3.20479545e+00, -5.40042765e+00,
3.79371300e-01, -1.90917191e+00,  5.38620004e-01,
3.55915866e-01, -3.50261534e+00,  9.92194271e-02,
-1.35406821e-01,  5.87721058e-01, -7.82777721e-01,
-4.09519981e-03,  1.21400519e+00, -1.78429211e-02,
-1.27979166e+00, -4.28386498e-01,  5.17012381e-01,
9.68861212e-02, -1.08657630e+00, -3.03134036e+00,
-3.75849146e+00,  9.48790821e-01,  7.31197249e-01,
-2.57130959e+00,  9.69761391e-01, -1.59660217e+00,
6.85979015e-01, -3.12355605e-01, -1.18639847e+00,
-6.45185210e-01,  1.95971879e-01, -2.01688681e+00,
3.64908059e-02,  1.08738281e+00, -4.12235611e-01,
7.04040849e-01, -1.18846887e+00,  1.10858862e+00,
-1.69130298e+00,  2.04393519e-02,  1.35439443e+00,
7.68599750e-02, -1.73571164e+00, -1.06069986e+00,
-8.45163717e-01,  9.46240617e-01, -1.08654608e+00,
-1.63588453e-01, -8.24851369e-01, -5.49534745e+00,
-6.33128806e-01, -8.67030933e-01,  7.41426235e-01,
2.45744133e-01,  7.66838307e-01,  1.66579000e-01,
-5.55762133e-01, -9.75725190e-01, -1.25622397e-02,
-1.48991586e+00, -8.73160470e-02, -2.58442498e+00,
1.29692511e+00, -1.71332728e+00, -1.31569345e+00,
9.96154362e-01, -8.87669972e-02, -1.07060185e+00,
-1.43859126e+00, -1.21903301e+00, -3.06276976e+00,
1.08994932e+00,  1.36719238e-01,  1.42718151e+00,
-6.81250835e-01, -3.32301069e+00, -1.13366933e+00,
-5.81184936e-01, -5.45599345e-01,  2.50802596e-01,
6.87272173e-01,  1.47542532e+00,  2.25144513e-02,
-9.58150298e-02, -1.16071543e+00, -1.27963357e+00,
1.53156305e-01, -1.62049140e+00, -6.36839989e-02,
-2.22220272e+00, -7.41181377e-01, -7.24452576e-01,
-1.27224395e+00, -1.56181277e-01, -2.31261484e-01,
-2.58870291e-01, -7.26258243e-01, -9.33844035e-01,
-1.38438048e+00, -1.06712253e+00, -1.81351089e-01,
-2.28141312e+00,  1.18529954e+00,  7.20268442e-01,
-2.39478650e+00, -2.09954158e+00, -6.41722968e-01,
-9.22364250e-01,  4.67558912e-01, -1.88099536e+00,
5.44134006e-01,  1.06761255e-01, -1.03970547e+00,
5.94076714e-01, -3.85984273e-01, -1.71712895e+00,
-2.00735550e-01, -2.24276136e+00, -2.69277130e-01,
-1.40950630e+00, -1.13165731e+00, -2.71114066e+00,
1.20268428e+00,  9.51058500e-01, -2.15536793e+00,
-2.34511965e+00, -1.37444777e-01,  4.70432325e-01,
2.30290491e-01,  1.22901645e-01, -9.59841197e-01,
1.25137884e-01, -1.01385031e+00, -2.32388978e-01,
2.37948848e-01,  1.63852196e-01, -7.84589329e-02,
3.52585594e-01,  9.14060088e-02, -8.33299487e-02,
-7.41211546e-01, -1.82132847e-01,  8.42678194e-01,
-1.72679392e+00, -3.69004294e-01, -1.91009051e+00,
1.06107066e-01,  5.15471056e-01,  3.64006227e-01,
-6.54362133e-01, -1.85474455e+00, -3.89874441e-01,
1.05857027e+00, -3.37437037e+00,  9.65394712e-01,
3.81485941e-01,  1.54887635e-02, -3.89558796e-01,
-8.07880277e+00, -8.89231975e-01, -2.27002699e+00,
5.93334905e-01,  9.36594574e-01,  1.66741369e+00,
-2.00521365e+00, -5.94329433e-01, -3.65679108e+00,
-1.61399672e+00, -5.79009762e-01, -1.26128192e+00,
-1.76574738e+00, -8.03347302e-01, -1.11343749e+00,
-1.88732037e+00, -2.98987269e-01,  1.05336203e+00,
-3.18396025e+00, -2.01039421e+00, -1.68105158e+00,
-1.27597718e+00, -3.55450496e-01, -3.97435381e-01,
6.36965635e-01,  4.27045704e-01,  1.19966116e+00,
-3.60721043e+00, -2.60556401e+00, -5.72014845e+00,
1.56111615e-01,  4.76840281e-01, -1.03467177e+00,
2.77611562e-01,  8.92587774e-02, -8.96120430e-01,
-3.39218517e-01, -2.40908403e-01, -4.51730419e-01,
-2.96262767e-01, -1.43407682e+00, -3.42568560e-01,
-5.12930343e-01, -2.47326863e-01,  5.29870133e-01,
8.39895629e-01, -7.88137345e-01,  5.44731831e-01,
-5.33009699e-01, -1.66387509e+00,  3.61972773e-01,
-6.03999188e-01,  4.50662080e-02,  1.29308330e-02,
6.62943281e-01, -6.49279020e-01, -2.84426904e-01,
-1.08584173e+00,  1.98689124e-01, -1.92824353e-01,
4.59007670e-02,  1.29505896e-01,  1.79075980e-01,
-8.86410407e-01,  1.34206709e+00, -3.94511270e-01,
-9.71598849e-01,  1.61851408e+00, -1.78410953e-01,
-3.73799829e-01, -3.54320164e-01,  2.28409564e-01,
-1.30927542e+00, -1.00942460e-01, -1.11671561e+00,
1.29556904e+00, -1.13900811e+00, -6.82140811e-01,
-2.12464690e+00, -4.58083289e-02, -8.03479479e-01,
8.84139336e-01, -7.11597649e-02, -2.24108715e+00,
-1.88517596e+00, -4.17387054e-01, -7.81930077e-01,
8.49193382e-01, -3.64506042e-01,  1.80225836e-02,
6.59268457e-01, -1.34185679e-01,  1.14164608e+00,
-1.69614283e+00, -1.33444632e+00, -2.33743408e+00,
-3.15916124e+00, -2.09602054e+00,  4.71634382e-01,
-1.43798363e+00, -1.31680603e+00, -2.16317888e-01,
-1.27296265e+00, -3.16167252e+00,  1.47250699e-01,
3.99842617e-01, -2.21789208e+00, -2.54551535e+00,
-2.61193275e+00, -1.96024400e+00,  2.59453583e-01,
5.28288858e-01, -6.94891516e-01,  2.75926955e-01,
1.03333876e+00, -1.37306161e+00, -9.70076986e-01,
-5.35759872e-02,  6.74829779e-01, -4.18655042e-01,
-3.33691787e+00, -4.47232835e-01,  4.68003121e-01,
-6.84227364e-02, -6.08715262e-01,  8.26665253e-01,
4.05574934e-01,  2.06398014e-01, -6.27119461e-01,
7.38420307e-01,  6.61379777e-01, -3.19192544e-01,
-1.74007474e-03, -2.11830221e-01, -1.15856696e-01,
-3.83064627e+00, -2.13803112e-01, -1.20374636e+00,
-2.29296526e+00,  9.19341917e-01,  1.01542244e+00,
-1.54743752e+00, -1.56650637e+00, -3.44888607e-01,
-1.80449768e+00, -3.42656598e+00,  1.15804045e-01,
6.40995259e-01, -4.86711779e-01,  1.42862143e-01,
-2.64803911e-01,  1.00694957e+00, -1.01462307e+00,
-1.79985259e+00,  9.48584306e-01, -7.29745623e-01,
8.79227932e-01, -1.00752869e+00, -2.49257571e+00,
-9.17915900e-01, -1.54845370e+00]])
• a
(chain, draw, Level)
float64
11.09 -0.5586 ... 7.722 0.2035
array([[[ 1.10912934e+01, -5.58631135e-01],
[ 7.79806961e-01,  3.17050405e-01],
[ 6.51313267e+00,  1.64390331e+01],
[ 1.32421940e+01, -1.41333285e+01],
[-4.86356452e+00,  9.64839633e+00],
[-1.59734304e+01, -4.69566292e+00],
[ 3.17469560e+00, -1.41174304e+01],
[-7.42098074e+00, -7.46532515e+00],
[ 1.31226523e+01,  1.65525839e+01],
[ 4.90186894e+00, -1.56035319e+01],
[-6.51711829e+00,  1.42736274e+01],
[-1.51294318e+01,  7.21029957e+00],
[ 1.63897159e+01, -1.04780080e+01],
[-1.24476247e+00,  1.31931192e+01],
[-3.93676658e+00,  4.96419888e-01],
[-8.46085377e+00,  3.43585152e+00],
[-1.96714333e+01,  4.19187031e+00],
[-1.02285144e+00,  4.72645687e+00],
[-2.29708049e+01, -1.46942494e+01],
[-1.81704169e+00, -8.83838430e+00],
[ 1.11939217e+00, -1.97378541e+01],
[-1.63932420e+01, -1.55864840e+01],
[-1.30872260e+01, -6.41788694e+00],
[ 7.55620242e+00, -3.81356080e+00],
[ 8.85752165e+00,  5.54010532e+00],
[ 7.54298880e+00,  1.20519246e+01],
[-4.05266098e+00, -1.65882859e+01],
[ 8.21597996e+00,  1.44701282e+01],
[ 3.60147500e-01,  3.87094626e+00],
[-1.17618643e+01,  2.51781387e+00],
[ 5.35695051e+00,  2.54361817e+00],
[ 7.30866964e+00, -2.71871302e+00],
[ 1.10250117e+01, -2.01928776e+01],
[-1.16672463e+01, -3.36571096e+00],
[-5.61841725e+00, -1.95753385e+01],
[-1.00205835e-01, -1.26847916e+01],
[-4.91229797e+00, -2.49141970e+00],
[ 1.53243149e+00, -1.74979555e+01],
[-1.47882495e+01, -1.13505950e+00],
[ 1.20930865e+01, -7.16740848e+00],
[ 3.59472816e+00, -1.35638073e+01],
[-3.95021132e+00, -1.16289753e+01],
[-1.07282628e+01,  1.91872475e+01],
[ 2.91909240e+00, -6.80951969e+00],
[-4.68277820e+00,  1.39549127e+01],
[ 2.12206396e+00, -8.92650315e+00],
[-5.69179216e+00,  2.72754773e+01],
[-8.46851833e-01,  2.12526482e-01],
[ 3.91915314e+00, -1.28888709e+01],
[-1.48340773e+01,  2.92525829e+00],
[-1.69003618e+01, -7.86143002e+00],
[ 1.42349456e+01, -2.67420540e+00],
[-3.74370911e+00, -1.84136443e+01],
[ 7.76540503e+00,  1.46492733e+01],
[-1.40164039e+01, -6.78990616e+00],
[-1.80370579e+01,  5.38619278e+00],
[-5.97721265e+00, -3.91575005e+00],
[ 1.99480350e+01,  5.27532937e-02],
[ 6.91202321e+00, -7.70653933e+00],
[ 3.42830242e+00,  9.52435687e+00],
[ 3.96111545e+00, -6.10288911e+00],
[ 8.32912194e+00,  1.65038324e+01],
[ 6.06910492e+00, -1.43294168e+01],
[-1.46797426e+01,  1.39936649e+01],
[-7.09034167e-01, -6.18201755e+00],
[-5.79802298e+00,  9.26085095e+00],
[-1.55010151e+00,  5.65401460e-01],
[ 3.24359609e+00,  1.05111062e+01],
[-1.49297991e+01, -9.05318928e+00],
[ 7.44218215e+00, -2.18553215e+00],
[-1.23137921e+01, -9.53470091e+00],
[ 1.25279109e+01, -1.93104691e+01],
[ 3.17676975e+00,  1.00544163e+01],
[ 7.53485555e+00, -1.49171879e+01],
[-1.51075136e+01, -1.19564980e+01],
[-1.21181293e+00,  2.24404049e+01],
[ 2.62348998e+00, -1.75276684e+00],
[-1.10113846e+01,  7.62268403e+00],
[ 1.13164066e+00, -8.00529184e+00],
[ 1.61006088e+01, -3.18629683e+00],
[ 4.95957738e+00,  3.39801805e+00],
[ 4.25185120e+00, -1.51354845e+01],
[-1.60493261e+01,  9.16411558e+00],
[-1.92903348e+00,  1.86431621e+01],
[ 1.05338029e+01,  6.16005456e+00],
[ 1.53160918e+01,  2.10899106e+01],
[-8.47376855e+00, -4.45736379e+00],
[-4.15078969e+00, -2.72484617e+00],
[-1.75790353e+01, -5.04236965e+00],
[ 3.83475881e+00, -1.48694273e+01],
[-7.04052084e-01, -5.59463935e+00],
[-9.09266160e+00, -3.77034207e+00],
[ 4.96758940e-01, -1.63549489e+00],
[-1.00338173e+01, -1.44432704e+01],
[ 8.11329935e+00, -2.20022735e+00],
[-3.85831829e+00, -5.67124082e+00],
[-1.12079305e+00,  1.02857060e+01],
[-2.54015557e+00,  3.05039893e+00],
[ 4.54610931e+00, -2.09760085e+01],
[ 2.08238457e+01, -3.71861993e+00],
[-1.95239969e+00, -1.02940857e+00],
[ 1.53614156e+01, -9.68401939e-01],
[-2.31617466e+00,  1.98197601e+01],
[-1.28438883e-01, -4.61371911e+00],
[-1.35684763e+01, -6.67473214e+00],
[ 8.11849716e-01,  9.26289395e+00],
[ 8.28465429e+00,  8.48917774e+00],
[ 9.34424965e+00, -6.32054817e+00],
[ 1.05780144e+01,  1.98671392e+00],
[-8.74834913e+00,  1.56889011e+00],
[ 3.25357811e+00,  1.75515012e+00],
[ 3.31450890e+00,  3.17401191e+00],
[-2.21651867e-02,  9.69333070e+00],
[ 7.86929186e+00,  4.26634417e+00],
[-3.92347309e+00, -6.68709677e+00],
[-1.41276638e+01,  9.78269392e+00],
[ 3.92764556e+00,  6.91518953e+00],
[ 6.00550102e+00,  4.05665529e+00],
[-1.25089756e+01, -2.23817194e-01],
[ 1.68901409e+01, -2.86268649e+00],
[ 8.22195287e+00, -8.67042039e+00],
[ 9.13638874e+00,  1.80770343e+00],
[ 3.88052972e+00, -5.89535172e+00],
[-1.63365743e+01,  4.11190786e+00],
[ 1.84510972e+01, -8.16289030e+00],
[-9.58489422e+00,  1.11407870e+01],
[-1.00785669e+00, -5.20373760e+00],
[ 5.95296083e+00, -2.79022985e+00],
[ 1.02603979e+01, -1.06657925e+01],
[ 5.90704349e+00, -9.31908440e-01],
[-1.41701208e-01, -2.64719989e+01],
[ 1.00582745e+00, -2.47540002e+00],
[ 3.19287829e+00,  5.41002176e+00],
[-3.54490290e+00,  9.74979077e+00],
[ 9.62127330e+00, -6.63240414e+00],
[-1.17289640e+01, -2.59044728e+00],
[-3.48585539e+00, -4.68873352e+00],
[-8.10667092e+00,  6.92029243e+00],
[-3.62100443e+00, -1.86590965e+01],
[-1.37017671e+01,  2.85001501e+00],
[-1.73172037e+01,  1.43867192e+01],
[-5.00703677e-01, -6.75217252e+00],
[-2.12116934e+00, -7.01774391e+00],
[ 5.70693222e+00, -2.84216406e+00],
[ 1.76652209e+00, -2.29598007e+00],
[-1.83293852e+01, -8.96097612e+00],
[-1.57738448e+01,  3.12053363e+00],
[ 1.04569074e+01, -2.82376816e+01],
[ 2.49481618e+00, -1.12987316e+00],
[ 9.40981585e+00,  1.27764555e+01],
[ 9.97171360e+00, -2.48420124e+00],
[-1.18166905e+00,  2.10587207e+01],
[-1.86516315e+01, -3.41413192e+00],
[-1.23958896e+01,  1.82127201e+00],
[-3.90004295e-01,  2.54531324e-01],
[ 2.14519586e+01, -8.34431733e-01],
[-1.25710760e+01,  8.34864594e-01],
[ 5.20520845e+00,  1.45612278e+01],
[-1.32344841e+01,  7.25228271e+00],
[ 1.23176415e+00,  2.77581007e+00],
[-7.37404426e-01, -1.30317790e+01],
[-7.95829885e+00,  9.51121115e+00],
[-9.15679434e-01,  1.89994539e+00],
[-1.03126545e+01,  1.05051632e+01],
[-2.05906592e+01, -2.09203110e+01],
[ 6.30805296e+00,  2.87044184e+00],
[-1.67779496e+01, -1.68378597e+01],
[-1.22285498e+01, -2.37739227e+00],
[-2.97322557e+00,  1.53458116e+01],
[ 1.76165485e+00, -9.27900141e+00],
[ 1.31762678e+00,  6.61444235e+00],
[ 8.77902659e+00,  1.04042458e+01],
[-2.29801329e+00,  2.55709128e+00],
[-2.11646480e+00,  7.67140223e+00],
[-2.26598756e+00, -2.97411955e+00],
[-7.46206131e+00, -3.73539931e+00],
[ 4.72609138e+00, -9.12819014e-01],
[-3.06737128e+00, -5.95299943e+00],
[-6.08360378e-01, -1.42601458e+01],
[ 4.62949709e+00,  1.24623387e+01],
[-7.90956129e+00,  8.19725565e+00],
[ 9.32681168e+00, -1.38689656e+01],
[-6.00811121e-01,  3.42299579e+00],
[ 7.41515646e+00, -3.20859389e+01],
[-1.60102380e+00,  1.45652388e+01],
[ 6.23314379e+00, -4.32613207e+00],
[-2.04745963e+01,  1.44663550e+01],
[-1.37089307e+00, -4.01357706e+00],
[-1.55969218e+01,  6.51351373e+00],
[-1.55107371e+00, -1.68728948e+01],
[ 6.78693264e+00, -2.00503324e+01],
[ 5.37550637e+00,  1.17333844e+01],
[ 8.25109559e+00, -7.92535923e-01],
[-1.01470675e+01, -1.47914831e+01],
[-1.70579255e+00,  7.53922291e+00],
[-5.79967494e+00,  2.86868689e+00],
[ 7.14991433e+00, -9.08205724e+00],
[-9.67034002e-01,  2.11432501e+00],
[ 2.24329596e+00, -8.64470703e-01],
[ 7.08634386e+00, -6.47030214e+00],
[ 2.60824603e+01,  1.18318031e+01],
[ 5.63853814e+00,  2.14808979e+00],
[-1.33506624e+00, -3.68468687e-01],
[ 2.41820896e+01, -8.12861662e+00],
[ 6.20681818e-01,  5.20262170e-01],
[ 2.84609403e+00,  6.35176376e+00],
[ 4.48374818e+00, -1.16631705e+01],
[-2.07278950e-01, -1.33147661e+01],
[-2.40451316e+00,  7.28974226e+00],
[-1.79977424e+01, -7.40133025e+00],
[ 9.02264459e+00,  8.51045275e+00],
[ 4.16669095e-01,  1.29521145e+01],
[ 1.50413813e+00, -2.31997639e+01],
[-4.24649726e+00,  9.06967764e+00],
[-1.26547858e+01, -2.76849577e+00],
[ 1.15916981e+01,  1.88154004e+01],
[ 1.98542026e+00, -1.86093712e+01],
[-1.53893150e-02, -1.78556796e+01],
[ 9.08707707e+00,  2.29622535e+01],
[-1.43985742e+01,  2.97622612e+00],
[-7.33158481e+00, -6.56634309e-01],
[ 3.24861307e+00, -2.31245166e-02],
[ 1.77616854e+01, -7.33120341e+00],
[ 1.77095504e+01,  1.01014878e+00],
[-9.37974552e+00, -1.02025667e+01],
[-8.37239863e+00,  6.79703947e+00],
[-5.08180514e+00,  8.19268155e+00],
[ 6.94052034e+00,  1.43008818e+01],
[ 1.13957636e+01, -1.95535448e+00],
[ 1.58585627e+01,  1.70877424e+01],
[ 8.01848673e+00, -7.53985577e+00],
[ 1.31531461e+01, -4.94595662e-01],
[ 1.51220080e+01, -2.17799317e+00],
[ 2.64721577e+00,  1.12273362e+01],
[ 3.86750639e+00, -3.84025675e+00],
[ 1.37920619e+00,  9.21288143e+00],
[-1.87113339e+01,  3.37902270e+00],
[ 3.75249009e+00,  2.36808266e+00],
[-1.55154986e+00,  2.30755323e+01],
[-1.71842734e+01, -7.27012699e+00],
[-8.55479692e+00, -1.09251172e+01],
[-1.25195105e+01,  3.08747379e+00],
[ 8.64135646e+00,  2.38531923e+01],
[ 1.62861886e+01, -1.91994656e+01],
[ 1.16329773e+01,  1.04259593e+01],
[-2.27389391e+00,  1.15225035e+00],
[-9.89592048e+00,  1.20162348e+01],
[-8.80870085e+00, -3.76842148e+00],
[-4.86851959e+00,  3.74794768e+00],
[ 8.46807931e+00,  5.03639119e+00],
[ 1.69284327e+01, -2.65030826e+00],
[ 7.41790955e+00,  5.44774754e+00],
[-1.59805066e+00,  3.69592437e-02],
[ 2.20902302e+00, -2.01744813e+01],
[ 3.71377025e+00,  3.24270584e+00],
[-3.16717641e+00,  6.73003452e+00],
[-1.34716970e+01,  1.88838023e+00],
[-4.12341675e+00,  1.72912599e+01],
[ 6.63292913e+00,  1.17160952e+01],
[ 1.17304260e+00, -2.82031761e+00],
[ 2.41283628e+00,  1.40583334e+00],
[ 7.29763500e-01,  7.37247897e+00],
[ 1.28903479e+01,  2.79873274e+00],
[-1.73910561e+01, -1.08883964e+01],
[ 2.13613120e+00,  1.50690102e+01],
[ 3.09349089e+00, -4.00810197e+00],
[ 1.19698292e+01,  1.02188158e+01],
[-1.06932506e+00, -5.69507103e+00],
[-1.05749802e+01,  7.29148979e+00],
[ 1.87526418e+01,  9.08544485e+00],
[-1.06179276e+01, -8.91082859e+00],
[ 1.05265652e+01, -3.28420852e+00],
[ 5.26692334e+00,  4.96918859e+00],
[-2.19353431e+00,  1.13695704e+01],
[ 6.84151708e+00,  1.02095789e+00],
[ 6.15084862e+00, -4.60330288e+00],
[-1.89861246e+00, -1.31543978e+01],
[-7.37382649e+00, -1.14054365e+01],
[-4.79950249e+00, -1.92471486e+01],
[-1.00877557e-01,  1.14377954e+01],
[ 4.11128332e+00, -4.16941826e+00],
[ 9.97095728e+00,  2.78453340e+00],
[-1.60203727e+01, -1.38123220e+01],
[-2.84693558e+00,  2.31577845e+00],
[ 6.19989353e+00,  4.48220882e+00],
[ 1.41523435e+00,  6.90815068e-01],
[-8.06181635e+00, -1.02667974e+01],
[ 1.08116887e+01,  6.28043613e+00],
[-6.92924392e+00,  1.41424864e+01],
[-2.24349936e+00, -7.40954378e+00],
[ 4.78829123e+00, -1.02148413e+01],
[ 9.37558165e+00,  1.25804185e+01],
[ 1.33318410e+00, -1.97907085e+00],
[-7.28645075e-01,  1.02346361e+01],
[ 1.43716880e+00,  5.03593612e+00],
[ 2.18157235e+01,  1.76380800e-01],
[-6.32779392e-01,  8.56477666e+00],
[ 1.85984659e+01, -5.62885885e+00],
[ 5.46759754e+00,  5.62027377e+00],
[-5.14780623e+00,  2.45906505e+01],
[-4.25271212e+00, -1.58445188e+00],
[-1.72584180e+00, -2.30022589e-02],
[-5.96803597e+00, -3.66270275e+00],
[ 1.12630413e+01, -4.59609082e+00],
[ 9.92200263e+00,  2.07576278e+01],
[-8.12240055e+00,  3.76161599e+00],
[ 9.82927641e+00,  5.65521693e+00],
[ 1.38034815e+01,  1.72194527e-01],
[ 8.56638758e+00,  1.62223226e+00],
[ 1.73411031e+01,  1.52484444e+01],
[ 2.07175094e+00,  2.07463642e+00],
[ 9.22700958e+00,  8.08768529e-01],
[ 2.31722279e+01, -1.67563540e-01],
[-1.71739172e+01, -9.24430655e+00],
[-1.54436258e+01,  8.41037891e+00],
[ 6.91312103e+00,  1.55967689e+00],
[ 4.94061298e+00,  1.57491619e+00],
[ 1.26188182e+00,  6.57352363e+00],
[-1.03499812e+01, -2.89031342e+00],
[-8.29885729e-01,  2.88312563e+00],
[ 1.67362984e+01, -1.85967842e+01],
[ 1.26279537e+01, -1.86722216e+01],
[-1.11320230e+01, -1.51793548e+01],
[-3.48553198e-01, -2.18482958e+01],
[ 3.12395843e+00, -9.91598309e+00],
[-9.48118036e+00,  3.30880042e+00],
[-6.32767354e-01, -1.14281509e+01],
[ 3.08475078e+01,  2.45128015e+00],
[-7.87320902e+00, -6.16835652e-01],
[ 9.00666763e+00,  4.23324110e+00],
[-1.00910925e+01,  1.48127042e+01],
[-1.82692120e+01,  3.51515322e+00],
[-3.03864094e+00, -7.16912308e+00],
[ 1.83082820e+00, -2.30868118e+00],
[-9.12177821e+00, -5.72711544e+00],
[-1.12990413e+01, -3.15935429e-02],
[-2.74750132e+00, -1.37060757e+00],
[ 1.18920773e+01, -1.59080727e+01],
[-1.00983734e+01, -4.36464702e+00],
[-1.14177893e+01,  1.52620984e+01],
[-1.43332172e+01, -4.75984866e-02],
[-1.49495176e+00,  5.66792579e+00],
[-6.14258359e+00,  3.04200479e+00],
[ 1.30333142e+01,  2.77610349e+00],
[-3.04623014e+00,  1.82217010e+01],
[ 5.28072224e+00, -6.11188275e+00],
[ 1.84676666e+01,  1.33395208e+01],
[-7.06445102e+00,  1.44862391e+01],
[-2.28858877e+00,  6.33640963e+00],
[-5.45525096e+00, -2.36200273e+01],
[ 1.48127388e+01,  8.61812658e+00],
[ 7.46251879e+00, -1.09123272e+01],
[-2.14215334e+00, -8.75794418e+00],
[ 1.10552352e+01, -9.75352399e+00],
[-5.05217588e+00, -1.20980706e+01],
[ 5.40043462e+00,  9.22790333e-01],
[-1.22184933e+00, -9.44342665e+00],
[-2.95076232e+00, -6.23453610e+00],
[ 3.72026432e+00,  1.27255661e+01],
[-8.61712652e+00, -2.85976393e-01],
[ 5.66346637e+00,  1.64858454e+01],
[-2.83566447e+00, -1.78091516e+01],
[-3.84614251e+00,  7.88246969e-01],
[-8.56684842e+00,  6.46852526e+00],
[-1.98986937e+01,  3.32898516e+00],
[-2.21194693e+00,  1.74499734e+01],
[ 2.54887176e+00, -2.23651878e+00],
[-1.31479009e-01,  2.58111054e+00],
[-1.99937527e-01, -1.60438911e+00],
[ 6.98328426e+00,  1.09627024e+01],
[ 5.57945695e-01,  6.95614379e+00],
[ 1.57981547e+01,  1.73202551e+01],
[-3.91369592e+00, -2.35830335e+00],
[ 3.84424421e+00, -1.45108268e+01],
[-1.79632147e+01, -2.69184090e+01],
[ 3.51648385e+00,  5.80692700e+00],
[-3.75958473e+00,  6.15159870e+00],
[-6.41336983e+00, -1.24523492e+01],
[-9.93667213e+00, -3.28786763e-01],
[-3.08440810e+00, -9.01742998e+00],
[-1.60680359e+01, -1.18522721e+01],
[-1.30091860e+00,  1.26892111e+00],
[ 3.08955637e+00, -4.81154822e+00],
[-8.40302628e+00, -1.22178314e+01],
[ 1.96590497e+01, -7.43560814e+00],
[-3.06392697e+00, -1.51303769e+01],
[-1.99627535e+01, -1.10773236e+00],
[ 2.02049049e+01,  1.58061759e-01],
[ 2.34557324e+01,  6.98335870e+00],
[ 3.11074729e+00,  9.95826959e+00],
[-8.69188739e+00,  1.04556580e+01],
[ 5.93349688e+00,  4.49153463e-01],
[ 3.31718324e+00,  5.91915775e+00],
[ 1.07842343e+01,  2.45815210e+01],
[-3.74132185e-01, -1.20369654e+01],
[ 1.19173257e+01, -1.31518626e+01],
[ 1.97626868e+00, -3.07949186e+00],
[ 1.07138051e+01, -5.15436508e+00],
[ 1.12495545e+01,  1.22600656e+01],
[-1.09704361e+01,  5.56421705e+00],
[-4.88999120e+00, -8.31696947e+00],
[ 3.41489299e+00,  1.61557357e+01],
[-5.74071691e+00, -2.09901393e+01],
[ 1.09210995e+01, -9.34045005e+00],
[ 1.10406933e+00, -1.60140885e+01],
[-2.16608865e+01, -6.57803353e+00],
[-5.46089136e+00, -1.80967547e+00],
[ 1.15714262e+01,  4.36162717e+00],
[-2.67520395e+00, -2.92026060e+00],
[-4.03322215e+00, -4.45431720e+00],
[ 2.31364658e+00, -2.54442076e+00],
[-1.07864776e+01, -2.37070446e+01],
[-1.60021804e+00, -2.46795208e+01],
[ 1.08338867e+01,  1.09171157e+01],
[-4.51024624e+00,  2.60195230e+01],
[ 7.59703335e+00,  5.31361569e+00],
[-8.73961748e-01,  4.34281275e+00],
[ 6.81436888e+00,  5.45943353e+00],
[-1.13767307e+01, -3.77804448e+00],
[ 1.97191227e+01,  1.03544541e+01],
[-1.18185462e+01,  1.23957396e+01],
[ 2.28720755e+00, -2.95635175e+00],
[-3.06050412e+00,  4.16547015e+00],
[ 5.86089444e+00, -9.40148715e+00],
[-1.19431549e+01,  4.33446702e+00],
[ 3.66823678e+00,  1.64435073e+01],
[-6.95729340e-01, -1.10636470e+01],
[-1.72225910e+01,  5.23338077e+00],
[ 5.19767720e+00, -3.43761815e-01],
[ 4.17075351e+00,  3.95480459e-01],
[ 9.38558220e+00, -5.72314188e+00],
[-1.37140505e+01,  7.51408603e+00],
[-7.05524753e+00, -1.54591670e+01],
[ 5.10455365e+00,  8.15866331e+00],
[-7.84395163e+00, -2.43561624e+00],
[-1.23989150e+00, -1.23429918e+01],
[-5.00404548e+00, -1.69088973e+01],
[ 5.78027769e+00, -1.28841258e+01],
[ 7.92373812e+00, -2.24555894e-01],
[-2.58856819e+00,  4.36973306e+00],
[-5.15559912e+00, -1.78768089e+01],
[-6.37798879e-02,  3.82768622e+00],
[-3.04037503e+00, -1.14271808e+01],
[ 7.52860244e+00, -7.36468182e+00],
[ 7.83199570e-02, -3.41446576e+00],
[ 1.26691887e+01, -3.67885407e+00],
[ 7.13661073e+00,  1.54583360e+01],
[-4.88414271e-01, -1.85440711e+00],
[-4.92797301e+00,  1.33648235e+01],
[ 5.54426365e+00,  1.30131322e+00],
[ 1.46755784e+01, -1.14653543e+01],
[-6.65182247e+00, -3.74440580e+00],
[ 5.67935797e+00,  4.22368784e+00],
[-8.08383595e+00, -1.50873877e+01],
[-1.57208863e+01,  1.39066567e+01],
[ 4.36923125e+00,  2.10070157e+00],
[-7.48958632e+00, -1.60060761e+00],
[ 1.33866791e+01,  3.12428514e+00],
[-2.17575515e+00,  1.70691976e+01],
[ 1.58284500e+01,  6.83303609e+00],
[ 1.62810737e+00, -2.53120317e+00],
[ 2.60799733e+00, -6.00868249e+00],
[-2.33717512e+00,  3.25516749e+00],
[-8.22112382e+00,  5.13821280e+00],
[ 1.38945446e+00, -3.26641352e+00],
[-4.25760593e+00,  3.48661541e+00],
[ 1.40392956e+00, -1.63046244e+00],
[-9.68257126e+00,  2.57349462e+00],
[-1.16297184e+01, -2.72575082e+00],
[-5.75775632e-01, -1.85581390e+01],
[-3.16449598e+00, -1.10872731e+01],
[ 5.49757455e-02,  1.23147245e+00],
[-1.20943836e+01, -7.58819992e+00],
[-1.55920940e+00,  1.21981073e+01],
[ 2.21606667e+01, -8.68574787e-01],
[-6.34869642e+00,  1.51807504e+01],
[ 9.23447354e+00, -1.02327895e+01],
[ 4.16987744e+00,  1.47113822e+01],
[ 6.00944370e+00, -1.28299211e+01],
[ 7.65229868e+00,  6.85026731e+00],
[-5.42406063e+00, -1.42711053e+01],
[-1.40501428e+01,  2.72478001e+01],
[-1.04067300e+01,  9.71243788e+00],
[-6.02714620e+00,  6.11926584e+00],
[ 5.07439206e+00,  9.01187290e+00],
[ 1.16959398e+01, -3.63549111e+00],
[-5.27310717e+00,  1.15465303e+01],
[-1.50001085e+01,  1.23088471e+01],
[ 5.55699174e+00, -5.97352760e+00],
[ 6.55763276e+00,  1.42500994e+01],
[-1.92772592e+00, -4.48191741e+00],
[ 7.87572270e+00, -1.34824019e+01],
[-1.06360774e+01, -6.93996839e+00],
[ 1.23288930e+00,  3.61990687e+00],
[-5.97386840e+00,  5.90328144e+00],
[ 8.19911826e+00, -1.92135152e+00],
[ 4.36467509e+00,  2.61531638e+00],
[ 4.31959050e+00,  1.13704604e+01],
[ 1.38105200e+01,  4.44546663e+00],
[ 7.72211018e+00,  2.03544154e-01]]])
• created_at :
2020-06-29T15:32:28.417696
arviz_version :
0.9.0
inference_library :
pymc3
inference_library_version :
3.9.2

• xarray.Dataset
• chain: 1
• draw: 500
• obs_id: 919
• chain
(chain)
int64
0
array([0])
• draw
(draw)
int64
0 1 2 3 4 5 ... 495 496 497 498 499
array([  0,   1,   2, ..., 497, 498, 499])
• obs_id
(obs_id)
int64
0 1 2 3 4 5 ... 914 915 916 917 918
array([  0,   1,   2, ..., 916, 917, 918])
• y
(chain, draw, obs_id)
float64
-0.5466 12.18 10.59 ... 7.887 7.613
array([[[-0.54657915, 12.18170279, 10.58691755, ..., 11.00291548,
11.32243991, 10.41567901],
[ 1.81628309,  2.67911246,  1.7244821 , ...,  1.06795196,
0.74351273,  1.6716244 ],
[15.66334425,  6.23158493,  5.62450633, ...,  7.17402321,
6.56727323,  6.76268299],
...,
[11.34632118,  4.28445206,  4.42525414, ...,  4.38683227,
4.34665407,  4.30903694],
[ 4.64346428, 14.28381186, 13.54161352, ..., 13.59667157,
13.05117542, 13.21853588],
[ 0.21777273,  7.89358481,  7.87376863, ...,  7.49356037,
7.88736178,  7.61291147]]])
• created_at :
2020-06-29T15:32:28.419110
arviz_version :
0.9.0
inference_library :
pymc3
inference_library_version :
3.9.2

• xarray.Dataset
• obs_id: 919
• obs_id
(obs_id)
int64
0 1 2 3 4 5 ... 914 915 916 917 918
array([  0,   1,   2, ..., 916, 917, 918])
• y
(obs_id)
float64
0.8329 0.8329 1.099 ... 1.335 1.099
array([ 0.83290912,  0.83290912,  1.09861229,  0.09531018,  1.16315081,
0.95551145,  0.47000363,  0.09531018, -0.22314355,  0.26236426,
0.26236426,  0.33647224,  0.40546511, -0.69314718,  0.18232156,
1.5260563 ,  0.33647224,  0.78845736,  1.79175947,  1.22377543,
0.64185389,  1.70474809,  1.85629799,  0.69314718,  1.90210753,
1.16315081,  1.93152141,  1.96009478,  2.05412373,  1.66770682,
1.5260563 ,  1.5040774 ,  1.06471074,  2.10413415,  0.53062825,
1.45861502,  1.70474809,  1.41098697,  0.87546874,  1.09861229,
0.40546511,  1.22377543,  1.09861229,  0.64185389, -1.2039728 ,
0.91629073,  0.18232156,  0.83290912, -0.35667494,  0.58778666,
1.09861229,  0.83290912,  0.58778666,  0.40546511,  0.69314718,
0.64185389,  0.26236426,  1.48160454,  1.5260563 ,  1.85629799,
1.54756251,  1.75785792,  0.83290912, -0.69314718,  1.54756251,
1.5040774 ,  1.90210753,  1.02961942,  1.09861229,  1.09861229,
1.98787435,  1.62924054,  0.99325177,  1.62924054,  2.57261223,
1.98787435,  1.93152141,  2.55722731,  1.77495235,  2.2617631 ,
1.80828877,  1.36097655,  2.66722821,  0.64185389,  1.94591015,
1.56861592,  2.2617631 ,  0.95551145,  1.91692261,  1.41098697,
2.32238772,  0.83290912,  0.64185389,  1.25276297,  1.74046617,
1.48160454,  1.38629436,  0.33647224,  1.45861502, -0.10536052,
0.74193734,  0.53062825,  2.56494936,  2.69462718,  1.56861592,
2.27212589, -2.30258509,  1.33500107,  2.01490302,  0.69314718,
1.68639895,  1.41098697,  2.05412373,  0.40546511,  2.31253542,
2.2512918 , -0.10536052,  1.5040774 ,  1.62924054,  0.78845736,
0.58778666,  2.10413415,  0.        ,  2.56494936,  0.99325177,
1.28093385,  3.28466357,  0.47000363,  2.57261223,  2.18605128,
2.97552957,  0.95551145,  2.20827441,  2.58021683,  1.30833282,
1.94591015,  1.58923521,  1.25276297,  0.        ,  1.25276297,
1.02961942,  0.40546511,  1.93152141,  2.41591378, -2.30258509,
0.95551145,  0.64185389,  0.53062825,  0.09531018,  0.        ,
1.09861229,  1.5040774 ,  0.47000363,  1.43508453,  0.95551145,
1.91692261,  1.48160454,  1.7227666 ,  1.30833282,  1.06471074,
2.68784749,  1.91692261,  2.09186406,  0.99325177,  1.06471074,
1.5040774 ,  0.58778666,  0.74193734,  0.74193734,  0.47000363,
2.27212589,  2.10413415,  1.28093385, -0.10536052,  1.64865863,
1.19392247,  2.38876279,  2.11625551,  1.85629799,  1.58923521,
1.80828877,  0.18232156,  2.17475172,  2.18605128,  1.93152141,
0.87546874,  0.53062825,  1.06471074,  1.88706965,  0.58778666,
1.54756251,  1.22377543,  1.5040774 ,  3.05870707,  2.21920348,
0.        ,  1.60943791,  1.62924054,  0.18232156,  2.04122033,
1.70474809,  1.30833282,  1.60943791,  1.56861592,  0.40546511,
1.25276297,  1.45861502,  0.95551145,  0.40546511,  0.40546511,
0.69314718,  1.58923521,  0.40546511,  1.36097655,  2.18605128,
1.48160454,  1.5040774 ,  1.5260563 ,  0.83290912, -0.51082562,
1.77495235,  1.70474809,  1.98787435,  1.75785792,  2.01490302,
1.58923521,  1.93152141,  1.87180218,  1.33500107,  1.7227666 ,
2.06686276,  1.5040774 ,  1.02961942,  1.25276297,  1.45861502,
0.87546874,  0.33647224,  1.66770682, -1.60943791,  0.95551145,
1.19392247,  1.19392247,  2.27212589,  1.45861502,  2.20827441,
1.85629799,  3.48737508,  2.58776404,  0.83290912,  1.74046617,
2.66722821,  1.94591015,  2.04122033,  2.29253476,  0.99325177,
3.77505715,  1.60943791,  1.60943791,  1.28093385,  1.58923521,
1.74046617,  1.28093385,  1.38629436,  1.91692261,  2.07944154,
1.22377543,  0.78845736,  0.53062825,  1.41098697,  0.64185389,
0.95551145,  2.42480273,  0.99325177,  1.38629436,  2.01490302,
0.33647224,  0.        , -0.69314718,  0.95551145,  1.80828877,
0.74193734,  1.70474809,  1.13140211,  1.09861229,  1.7227666 ,
1.43508453,  1.38629436,  2.7080502 ,  1.98787435,  0.87546874,
1.06471074,  1.5040774 ,  0.47000363,  2.16332303,  1.74046617,
2.16332303,  1.36097655,  0.64185389,  0.69314718,  1.7227666 ,
0.95551145, -0.10536052,  0.78845736,  1.06471074,  1.38629436,
1.48160454,  1.56861592,  1.06471074,  1.43508453,  0.53062825,
1.48160454, -0.22314355,  1.7227666 ,  1.22377543,  1.7227666 ,
0.95551145,  1.02961942,  2.14006616,  1.22377543,  1.19392247,
2.16332303,  0.58778666,  1.75785792,  2.57261223,  1.02961942,
1.56861592,  1.74046617,  2.63188884,  2.04122033,  1.75785792,
1.54756251,  2.04122033,  0.99325177,  1.5260563 ,  1.79175947,
0.83290912,  0.91629073,  1.41098697,  1.54756251,  1.54756251,
2.39789527,  2.04122033,  1.13140211,  0.47000363,  0.53062825,
2.8094027 ,  1.16315081,  1.64865863,  1.60943791,  1.80828877,
0.        ,  0.64185389,  1.38629436,  1.74046617, -0.69314718,
0.99325177,  1.30833282,  1.84054963,  3.16547505,  1.38629436,
1.09861229,  1.13140211,  1.56861592,  1.13140211,  1.45861502,
1.36097655,  1.13140211,  1.48160454,  1.09861229,  1.25276297,
2.1517622 ,  2.20827441,  1.58923521,  1.30833282,  0.83290912,
1.06471074, -0.10536052,  0.47000363,  1.54756251,  1.33500107,
1.30833282,  1.13140211,  0.83290912,  0.69314718,  0.99325177,
0.64185389,  0.91629073,  1.48160454,  0.99325177,  0.18232156,
1.22377543,  0.95551145,  2.2512918 ,  0.33647224,  2.14006616,
1.62924054,  1.09861229,  2.58021683,  2.73436751,  0.64185389,
1.36097655,  2.07944154,  0.99325177,  2.43361336,  1.43508453,
2.51769647,  1.91692261,  1.94591015,  1.5260563 ,  0.        ,
0.58778666,  0.40546511,  0.74193734,  0.09531018,  0.09531018,
1.06471074,  0.33647224,  2.43361336,  2.77881927,  0.33647224,
0.33647224,  0.53062825,  0.        ,  1.06471074, -0.51082562,
0.47000363,  1.97408103, -0.51082562,  2.32238772,  1.48160454,
1.22377543,  1.09861229,  2.53369681,  1.45861502,  1.5260563 ,
1.38629436,  1.22377543,  2.8678989 ,  2.37024374,  2.07944154,
1.28093385,  1.88706965,  1.94591015,  1.64865863,  2.49320545,
1.64865863,  2.19722458,  1.77495235,  1.54756251,  1.38629436,
0.47000363,  3.17387846,  0.        ,  0.40546511,  0.18232156,
1.06471074,  3.87743156,  0.        ,  2.12823171,  1.43508453,
-0.51082562,  1.91692261,  2.02814825,  2.2300144 , -0.51082562,
0.47000363,  2.34180581,  1.38629436,  0.64185389,  2.30258509,
0.87546874,  1.5040774 ,  1.06471074,  0.18232156,  0.26236426,
0.53062825,  3.23867845, -2.30258509,  2.37024374,  0.87546874,
1.38629436,  1.98787435,  0.78845736,  1.19392247, -0.51082562,
1.75785792,  0.40546511,  0.78845736,  1.5040774 ,  0.91629073,
1.60943791,  1.13140211,  1.13140211,  1.06471074,  1.38629436,
2.39789527,  1.87180218,  0.74193734,  1.13140211,  1.5260563 ,
0.78845736,  2.09186406,  0.33647224,  2.2300144 ,  0.18232156,
2.37024374,  3.18221184,  2.21920348,  2.50143595,  2.10413415,
2.38876279,  1.45861502,  2.76000994,  1.70474809,  1.84054963,
2.28238239,  2.10413415,  0.53062825,  0.53062825,  1.87180218,
1.5040774 ,  2.42480273,  2.31253542,  1.5260563 ,  2.09186406,
0.87546874,  1.19392247,  1.62924054,  1.43508453,  0.18232156,
0.74193734,  0.18232156,  1.09861229,  0.78845736,  2.06686276,
1.36097655,  0.95551145,  1.09861229,  0.58778666,  0.95551145,
2.2512918 , -0.35667494,  1.02961942,  0.18232156,  0.78845736,
2.49320545,  2.54160199,  1.19392247,  1.45861502,  1.36097655,
1.33500107,  1.77495235, -0.91629073,  1.43508453,  1.06471074,
0.69314718,  0.26236426,  0.26236426,  0.47000363,  2.2512918 ,
0.58778666,  2.50143595,  1.48160454,  1.94591015,  0.40546511,
0.95551145,  2.27212589,  1.36097655,  1.25276297,  1.93152141,
1.30833282,  0.83290912,  0.99325177,  0.78845736,  1.96009478,
0.26236426,  1.36097655,  1.28093385,  1.45861502,  0.53062825,
1.06471074,  2.16332303,  1.84054963,  1.66770682,  1.02961942,
0.26236426,  1.28093385,  1.7227666 ,  2.32238772,  1.7227666 ,
0.26236426,  1.60943791,  1.41098697,  1.28093385,  0.95551145,
0.26236426,  1.02961942,  0.58778666,  1.16315081, -0.22314355,
0.09531018,  0.69314718,  1.36097655,  2.19722458,  2.01490302,
3.03495299,  1.80828877,  0.78845736,  1.77495235,  2.28238239,
1.87180218,  1.54756251,  1.74046617,  2.94968834,  0.91629073,
1.13140211,  1.64865863,  2.05412373,  2.10413415,  1.56861592,
2.14006616,  0.53062825,  1.80828877,  0.18232156,  2.44234704,
1.48160454,  1.30833282,  2.34180581,  1.25276297,  1.16315081,
1.30833282,  1.02961942,  1.41098697,  0.26236426,  0.58778666,
1.45861502,  2.96527307,  2.21920348,  0.74193734,  2.44234704,
2.3321439 ,  0.78845736,  0.26236426,  1.19392247,  0.74193734,
1.48160454,  0.83290912,  1.70474809,  3.2308044 ,  1.64865863,
0.87546874,  1.19392247,  0.95551145,  1.06471074,  1.16315081,
0.53062825,  1.56861592,  1.41098697,  1.62924054,  0.47000363,
1.58923521, -0.10536052, -0.51082562,  0.91629073,  0.87546874,
1.54756251,  2.40694511,  2.7080502 ,  2.16332303,  1.5260563 ,
0.47000363,  1.38629436,  0.64185389,  0.53062825, -0.51082562,
-0.69314718, -0.51082562,  2.17475172,  0.53062825,  0.40546511,
2.17475172,  2.41591378,  0.47000363,  0.18232156,  0.        ,
-0.22314355,  1.45861502,  1.25276297,  0.78845736,  1.09861229,
0.64185389,  0.64185389,  0.91629073,  0.58778666, -0.10536052,
2.46809953,  0.64185389,  1.06471074,  1.28093385,  1.30833282,
1.28093385,  1.13140211,  1.19392247,  1.16315081,  1.22377543,
0.58778666,  1.74046617,  1.25276297,  0.47000363,  3.47506723,
0.18232156,  0.78845736, -0.10536052,  0.47000363,  0.33647224,
1.16315081,  1.98787435,  0.40546511,  0.33647224,  0.47000363,
1.62924054,  0.87546874,  0.91629073,  0.26236426,  1.70474809,
0.18232156,  0.40546511,  1.98787435,  0.18232156,  1.22377543,
1.19392247,  0.47000363,  1.30833282, -0.10536052,  0.53062825,
0.40546511,  1.02961942,  1.22377543,  0.        , -0.35667494,
0.74193734,  0.69314718,  0.        ,  1.70474809,  0.47000363,
1.16315081,  0.64185389,  0.        ,  1.22377543,  0.58778666,
1.16315081, -0.22314355,  1.48160454,  0.40546511,  0.64185389,
0.47000363,  0.83290912,  0.91629073,  1.02961942,  0.58778666,
0.18232156,  0.64185389, -1.2039728 ,  0.83290912,  1.54756251,
0.78845736,  0.74193734, -0.22314355,  1.87180218,  1.13140211,
0.74193734,  0.        ,  1.22377543,  0.64185389,  0.64185389,
0.83290912,  1.48160454,  2.02814825,  1.87180218,  2.12823171,
0.78845736,  1.22377543,  0.33647224,  1.62924054,  0.09531018,
1.96009478,  1.75785792,  2.32238772,  1.90210753,  0.99325177,
1.22377543,  0.47000363,  1.62924054,  2.01490302,  2.68102153,
0.64185389,  2.01490302,  0.99325177,  1.33500107,  0.69314718,
0.83290912,  1.62924054,  2.00148   ,  1.33500107,  1.09861229,
1.5040774 ,  2.14006616,  1.64865863,  1.30833282,  0.47000363,
2.16332303,  2.37024374,  2.09186406,  1.5260563 ,  1.13140211,
0.91629073,  0.47000363,  1.58923521,  1.93152141,  0.78845736,
1.80828877,  1.09861229,  1.91692261,  2.96527307,  1.41098697,
1.79175947,  2.20827441,  2.14006616,  0.18232156,  1.16315081,
2.4510051 ,  2.27212589,  1.09861229, -0.22314355,  1.19392247,
1.56861592,  1.58923521, -0.69314718,  2.24070969,  0.58778666,
0.        ,  2.3321439 ,  2.05412373,  0.83290912,  1.88706965,
2.50959926,  1.54756251,  1.84054963,  1.88706965,  1.06471074,
0.69314718,  0.26236426,  0.91629073,  0.09531018,  0.26236426,
0.53062825, -0.10536052,  0.58778666,  1.56861592,  0.58778666,
1.22377543, -0.10536052,  2.29253476,  1.68639895,  2.1517622 ,
0.69314718,  1.90210753,  1.36097655,  1.79175947,  1.60943791,
0.95551145,  2.37954613,  0.91629073,  0.78845736,  1.56861592,
1.33500107,  2.60268969,  1.09861229,  1.48160454,  1.36097655,
0.64185389,  0.47000363,  0.64185389,  0.33647224,  1.90210753,
3.02042489,  1.80828877,  2.63188884,  2.3321439 ,  1.75785792,
2.24070969,  1.25276297,  1.43508453,  2.45958884,  1.98787435,
1.56861592,  0.64185389, -0.22314355,  1.56861592,  2.3321439 ,
2.43361336,  2.04122033,  2.4765384 , -0.51082562,  1.91692261,
1.68639895,  1.16315081,  0.78845736,  2.00148   ,  1.64865863,
0.83290912,  0.87546874,  2.77258872,  2.2617631 ,  1.87180218,
1.5260563 ,  1.62924054,  1.33500107,  1.09861229])
• created_at :
2020-06-29T15:32:28.421251
arviz_version :
0.9.0
inference_library :
pymc3
inference_library_version :
3.9.2

• xarray.Dataset
• obs_id: 919
• obs_id
(obs_id)
int64
0 1 2 3 4 5 ... 914 915 916 917 918
array([  0,   1,   2, ..., 916, 917, 918])
• floor_idx
(obs_id)
int32
1 0 0 0 0 0 0 0 ... 1 0 0 0 0 0 0 0
array([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1,
0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1,
0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1,
0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0,
1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0,
0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0,
0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0,
1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1,
0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0,
1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0,
1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1,
0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0,
0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0,
0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1,
0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0,
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0,
0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0,
0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], dtype=int32)
• created_at :
2020-06-29T15:32:28.421885
arviz_version :
0.9.0
inference_library :
pymc3
inference_library_version :
3.9.2

We now want to calculate the highest density interval given by the posterior predictive on Radon levels. However, we are not interested in the HDI of each observation but in the HDI of each level. We can groupby xarray objects using variable or coordinate names or using other xarray objects with the same dimensions (obs_id in this case). az.hdi works with both xarray Datasets and groupby objects. Moreover, all calculations keep track and update the dimensions and coordinate values.

When calling aggregation functions, xarray by default reduces all the dimensions in each variable whereas ArviZ by default reduces only chain and draw dimensions. This generally means that we have to be explicit when calling Dataset.mean(dim=("chain", "draw") if using xarray functions but not with ArviZ ones – compare for example calls to .mean with calls to az.hdi. Notice how using labeled dimensions helps in understanding what exactly is being reduced with a quick glance at the code.

Now that we have some context on reducing dims in ArviZ and xarray, let’s move to the case at hand. In this particular case, we want ArviZ to reduce all dimensions in each groupby group. Here, each groupby will have the same 3 dimensions as the original input (chain, draw, obs_id) what will change is the length of the obs_id dimension, in the first group it will be the number of basement level observations and in the second the number of floor level observations. In az.hdi, the dimensions to be reduce can be specified with the input_core_dims argument.

[14]:
hdi_helper = lambda ds: az.hdi(ds, input_core_dims=[["chain", "draw", "obs_id"]])
hdi_ppc = pooled_idata.posterior_predictive.y.groupby(pooled_idata.constant_data.floor_idx).apply(hdi_helper).y
hdi_ppc
[14]:
xarray.DataArray
'y'
• floor_idx: 2
• hdi: 2
• -0.1339 2.842 -0.7079 2.278
array([[-0.13386863,  2.84175493],
[-0.70787421,  2.27755296]])
• hdi
(hdi)
<U6
'lower' 'higher'
hdi_prob :
0.94
array(['lower', 'higher'], dtype='<U6')
• floor_idx
(floor_idx)
int64
0 1
array([0, 1])

In addition, ArviZ has also included the hdi_prob as an attribute of the hdi coordinate, click on its file icon to see it!

We will now add one extra coordinate to the observed_data group: the Level labels (not indices). This will allow xarray to automatically generate the correct xlabel and xticklabels so we don’t have to worry about labeling too much. In this particular case we will only do one plot, which makes the adding of a coordinate a bit of an overkill. In many cases however, we will have several plots and using this approach will automate labeling for all plots. Eventually, we will sort by Level coordinate to make sure Basement is the first value and goes at the left of the plot.

[15]:
level_labels = pooled_idata.posterior.Level[pooled_idata.constant_data.floor_idx]
pooled_idata.observed_data = pooled_idata.observed_data.assign_coords(Level=level_labels).sortby("Level")

We can then use these samples in our plot:

[16]:
pooled_means = pooled_idata.posterior.mean(dim=("chain", "draw"))

_, ax = plt.subplots()
pooled_idata.observed_data.plot.scatter(x="Level", y="y", label="Observations", alpha=0.4, ax=ax)

az.plot_hdi(
[0, 1], hdi_data=hdi_ppc, fill_kwargs={"alpha": 0.2, "label": "Exp. distrib. of Radon levels"}, ax=ax
)

az.plot_hdi(
[0, 1], pooled_idata.posterior.a, fill_kwargs={"alpha": 0.5, "label": "Exp. mean HPD"}, ax=ax
)
ax.plot([0, 1], pooled_means.a, label="Exp. mean")

ax.legend(ncol=2, fontsize=9, frameon=True);

The 94% interval of the expected value is very narrow, and even narrower for basement measurements, meaning that the model is slightly more confident about these observations. The sampling distribution of individual radon levels is much wider. We can infer that floor level does account for some of the variation in radon levels. We can see however that the model underestimates the dispersion in radon levels across households – lots of them lie outside the light orange prediction envelope. So this model is a good start but we can’t stop there.

Let’s compare it to the unpooled model, where we estimate the radon level for each county:

[17]:
coords["County"] = mn_counties
with pm.Model(coords=coords) as unpooled_model:
floor_idx = pm.Data("floor_idx", floor, dims="obs_id")
county_idx = pm.Data("county_idx", county, dims="obs_id")
a = pm.Normal("a", 0.0, sigma=10.0, dims=("County", "Level"))

theta = a[county_idx, floor_idx]
sigma = pm.Exponential("sigma", 1.0)

y = pm.Normal("y", theta, sigma=sigma, observed=log_radon, dims="obs_id")
pm.model_to_graphviz(unpooled_model)
[17]:
[18]:
with unpooled_model:
unpooled_idata = pm.sample(return_inferencedata=True, random_seed=RANDOM_SEED)
Auto-assigning NUTS sampler...
Multiprocess sampling (4 chains in 4 jobs)
NUTS: [sigma, a]
100.00% [8000/8000 00:08<00:00 Sampling 4 chains, 0 divergences]
Sampling 4 chains for 1_000 tune and 1_000 draw iterations (4_000 + 4_000 draws total) took 8 seconds.

Sampling went fine again. Let’s look at the expected values for both basement (dimension 0) and floor (dimension 1) in each county:

[19]:
az.plot_forest(
unpooled_idata, var_names="a", figsize=(6, 32), r_hat=True, combined=True, textsize=8
);

Sampling was good for all counties, but you can see that some are more uncertain than others, and all of these uncertain estimates are for floor measurements. This probably comes from the fact that some counties just have a handful of floor measurements, so the model is pretty uncertain about them.

To identify counties with high radon levels, we can plot the ordered mean estimates, as well as their 94% HPD:

[20]:
unpooled_means = unpooled_idata.posterior.mean(dim=("chain", "draw"))
unpooled_hdi = az.hdi(unpooled_idata)

We will now take advantage of label based indexing for Datasets with the sel method and of automagical sorting capabilities. We first sort using the values of a specific 1D variable a. Then, thanks to unpooled_means and unpooled_hdi both having the County dimension, we can pass a 1D DataArray to sort the second dataset too.

[21]:
fig, axes = plt.subplots(1, 2, figsize=(12, 5.5))
xticks = np.arange(0,86,6)
fontdict = {"horizontalalignment": "right", "fontsize": 10}
for ax, level in zip(axes, ["Basement", "Floor"]):
unpooled_means_iter = unpooled_means.sel(Level=level).sortby("a")
unpooled_hdi_iter = unpooled_hdi.sel(Level=level).sortby(unpooled_means_iter.a)
unpooled_means_iter.plot.scatter(x="County", y="a", ax=ax, alpha=0.8)
ax.vlines(
np.arange(counties),
unpooled_hdi_iter.a.sel(hdi="lower"),
unpooled_hdi_iter.a.sel(hdi="higher"),
color="orange", alpha=0.6
)
ax.set(
title=f"{level.title()} estimates",
ylim=(-2, 4.5)
)
ax.set_xticks(xticks)
ax.set_xticklabels(unpooled_means_iter.County.values[xticks], fontdict=fontdict)
ax.tick_params(rotation=30)
fig.tight_layout();
/home/oriol/venvs/arviz-dev/lib/python3.6/site-packages/ipykernel_launcher.py:22: UserWarning: This figure was using constrained_layout==True, but that is incompatible with subplots_adjust and or tight_layout: setting constrained_layout==False.

There seems to be more dispersion in radon levels for floor measurements than for basement ones. Moreover, as we saw in the forest plot, floor estimates are globally more uncertain, especially in some counties. We speculated that this is due to smaller sample sizes in the data, but let’s verify it!

[22]:
n_floor_meas = srrs_mn.groupby("county").sum().floor
uncertainty = (
unpooled_hdi.a.sel(hdi="higher", Level="Floor") - unpooled_hdi.a.sel(hdi="lower", Level="Floor")
)

plt.plot(n_floor_meas, uncertainty, "o", alpha=0.4)
plt.xlabel("Nbr floor measurements in county")
plt.ylabel("Estimates' uncertainty");

Bingo! This makes sense: it’s very hard to estimate floor radon levels in counties where there are no floor measurements, and the model is telling us that by being very uncertain in its estimates for those counties. This is a classic issue with no-pooling models: when you estimate clusters independently from each other, what do you with small-sample-size counties?

Another way to see this phenomenon is to visually compare the pooled and unpooled estimates for a subset of counties representing a range of sample sizes:

In cases where label based indexing is not powerful enough (for example when repeated labels are present) we can still index xarray objects with boolean masks or positional indices. Here we create a mask with the isin method and index with where. Note that xarray objects are generally high dimensional and condition based indexing is bound to generate ragged arrays. Thus, xarray.where by default replaces the unselected values with NaNs. In our case, the variable we are indexing is 1D and we can therefore use drop=True to remove the values instead of replacing by NaN.

Like we did above, we add a couple of extra coordinates to help in data processing and plotting.

[23]:
SAMPLE_COUNTIES = (
"LAC QUI PARLE",
"AITKIN",
"KOOCHICHING",
"DOUGLAS",
"CLAY",
"STEARNS",
"RAMSEY",
"ST LOUIS",
)

unpooled_idata.observed_data = unpooled_idata.observed_data.assign_coords({
"County": ("obs_id", mn_counties[unpooled_idata.constant_data.county_idx]),
"Level": ("obs_id", np.array(["Basement", "Floor"])[unpooled_idata.constant_data.floor_idx])
})

fig, axes = plt.subplots(2, 4, figsize=(12, 6), sharey=True, sharex=True)
for ax, c in zip(axes.ravel(), SAMPLE_COUNTIES):

# plot obs:
unpooled_idata.observed_data.where(
).sortby("Level").plot.scatter(x="Level", y="y", ax=ax, alpha=.4)

# plot both models:
ax.plot([0, 1], unpooled_means.a.sel(County=c), "b")
ax.plot([0, 1], pooled_means.a, "r--")

ax.set_title(c)
ax.set_xlabel("")
fig.tight_layout();
/home/oriol/venvs/arviz-dev/lib/python3.6/site-packages/ipykernel_launcher.py:33: UserWarning: This figure was using constrained_layout==True, but that is incompatible with subplots_adjust and or tight_layout: setting constrained_layout==False.

Neither of these models are satisfactory:

• If we are trying to identify high-radon counties, pooling is useless – because, by definition, the pooled model estimates radon at the state-level. In other words, pooling leads to maximal underfitting: the variation across counties is not taken into account and only the overall population is estimated.

• We do not trust extreme unpooled estimates produced by models using few observations. This leads to maximal overfitting: only the within-county variations are taken into account and the overall population (i.e the state-level, which tells us about similarites across counties) is not estimated.

This issue is acute for small sample sizes, as seen above: in counties where we have few floor measurements, if radon levels are higher for those data points than for basement ones (Aitkin, Koochiching, Ramsey), the model will estimate that radon levels are higher in floors than basements for these counties. But we shouldn’t trust this conclusion, because both scientific knowledge and the situation in other counties tell us that it is usually the reverse (basement radon > floor radon). So unless we have a lot of observations telling us otherwise for a given county, we should be skeptical and shrink our county-estimates to the state-estimates – in other words, we should balance between cluster-level and population-level information, and the amount of shrinkage will depend on how extreme and how numerous the data in each cluster are.

But how do we do that? Well, ladies and gentlemen, let me introduce you to… hierarchical models!

## Multilevel and hierarchical models¶

When we pool our data, we imply that they are sampled from the same model. This ignores any variation among sampling units (other than sampling variance) – we assume that counties are all the same:

When we analyze data unpooled, we imply that they are sampled independently from separate models. At the opposite extreme from the pooled case, this approach claims that differences between sampling units are too large to combine them – we assume that counties have no similarity whatsoever:

In a hierarchical model, parameters are viewed as a sample from a population distribution of parameters. Thus, we view them as being neither entirely different or exactly the same. This is partial pooling:

We can use PyMC to easily specify multilevel models, and fit them using Markov chain Monte Carlo.

## Partial pooling model¶

The simplest partial pooling model for the household radon dataset is one which simply estimates radon levels, without any predictors at any level. A partial pooling model represents a compromise between the pooled and unpooled extremes, approximately a weighted average (based on sample size) of the unpooled county estimates and the pooled estimates.

$\hat{\alpha} \approx \frac{(n_j/\sigma_y^2)\bar{y}_j + (1/\sigma_{\alpha}^2)\bar{y}}{(n_j/\sigma_y^2) + (1/\sigma_{\alpha}^2)}$

Estimates for counties with smaller sample sizes will shrink towards the state-wide average.

Estimates for counties with larger sample sizes will be closer to the unpooled county estimates and will influence the the state-wide average.

[24]:
with pm.Model(coords=coords) as partial_pooling:
county_idx = pm.Data("county_idx", county, dims="obs_id")
# Hyperpriors:
a = pm.Normal("a", mu=0.0, sigma=10.0)
sigma_a = pm.Exponential("sigma_a", 1.0)

# Varying intercepts:
a_county = pm.Normal("a_county", mu=a, sigma=sigma_a, dims="County")

# Expected value per county:
theta = a_county[county_idx]
# Model error:
sigma = pm.Exponential("sigma", 1.0)

y = pm.Normal("y", theta, sigma=sigma, observed=log_radon, dims="obs_id")
pm.model_to_graphviz(partial_pooling)
[24]:
[25]:
with partial_pooling:
partial_pooling_idata = pm.sample(tune=2000, return_inferencedata=True, random_seed=RANDOM_SEED)
Auto-assigning NUTS sampler...
Multiprocess sampling (4 chains in 4 jobs)
NUTS: [sigma, a_county, sigma_a, a]
100.00% [12000/12000 00:07<00:00 Sampling 4 chains, 0 divergences]
Sampling 4 chains for 2_000 tune and 1_000 draw iterations (8_000 + 4_000 draws total) took 7 seconds.

To compare partial-pooling and no-pooling estimates, let’s run the unpooled model without the floor predictor:

[26]:
with pm.Model(coords=coords) as unpooled_bis:
county_idx = pm.Data("county_idx", county, dims="obs_id")
a_county = pm.Normal("a_county", 0.0, sigma=10.0, dims="County")

theta = a_county[county_idx]
sigma = pm.Exponential("sigma", 1.0)

y = pm.Normal("y", theta, sigma=sigma, observed=log_radon, dims="obs_id")

unpooled_idata_bis = pm.sample(tune=2000, return_inferencedata=True, random_seed=RANDOM_SEED)
Auto-assigning NUTS sampler...
Multiprocess sampling (4 chains in 4 jobs)
NUTS: [sigma, a_county]
100.00% [12000/12000 00:05<00:00 Sampling 4 chains, 0 divergences]
Sampling 4 chains for 2_000 tune and 1_000 draw iterations (8_000 + 4_000 draws total) took 6 seconds.

Now let’s compare both models’ estimates for all 85 counties. We’ll plot the estimates against each county’s sample size, to let you see more clearly what hierarchical models bring to the table:

[27]:
N_county = srrs_mn.groupby("county")["idnum"].count().values

fig, axes = plt.subplots(1, 2, figsize=(10, 4), sharex=True, sharey=True)
for ax, idata, level in zip(
axes,
(unpooled_idata_bis, partial_pooling_idata),
("no pooling", "partial pooling"),
):

# add variable with x values to xarray dataset
idata.posterior = idata.posterior.assign_coords({"N_county": ("County", N_county)})
# plot means
idata.posterior.mean(dim=("chain", "draw")).plot.scatter(x="N_county", y="a_county", ax=ax, alpha=0.9);
ax.hlines(
partial_pooling_idata.posterior.a.mean(),
0.9,
max(N_county) + 1,
alpha=0.4,
ls="--",
label="Est. population mean",
)

# plot hdi
hdi = az.hdi(idata).a_county
ax.vlines(N_county, hdi.sel(hdi="lower"), hdi.sel(hdi="higher"), color="orange", alpha=0.5)

ax.set(
title=f"{level.title()} Estimates",
xlabel="Nbr obs in county (log scale)",
xscale="log",
)
ax.legend(fontsize=10)
fig.tight_layout();
/home/oriol/venvs/arviz-dev/lib/python3.6/site-packages/ipykernel_launcher.py:34: UserWarning: This figure was using constrained_layout==True, but that is incompatible with subplots_adjust and or tight_layout: setting constrained_layout==False.

Notice the difference between the unpooled and partially-pooled estimates, particularly at smaller sample sizes: As expected, the former are both more extreme and more imprecise. Indeed, in the partially-pooled model, estimates in small-sample-size counties are informed by the population parameters – hence more precise estimates. Moreover, the smaller the sample size, the more regression towards the overall mean (the dashed gray line) – hence less extreme estimates. In other words, the model is skeptical of extreme deviations from the population mean in counties where data is sparse.

Now let’s try to integrate the floor predictor! To show you an example with a slope we’re gonna take the indicator variable road, but we could stay with the index variable approach that we used for the no-pooling model. Then we would have one intercept for each category – basement and floor.

## Varying intercept model¶

As above, this model allows intercepts to vary across county, according to a random effect. We just add a fixed slope for the predictor (i.e all counties will have the same slope):

$y_i = \alpha_{j[i]} + \beta x_{i} + \epsilon_i$

where

$\epsilon_i \sim N(0, \sigma_y^2)$

and the intercept random effect:

$\alpha_{j[i]} \sim N(\mu_{\alpha}, \sigma_{\alpha}^2)$

As with the the no-pooling model, we set a separate intercept for each county, but rather than fitting separate regression models for each county, multilevel modeling shares strength among counties, allowing for more reasonable inference in counties with little data. Here is what that looks in code:

[28]:
with pm.Model(coords=coords) as varying_intercept:
floor_idx = pm.Data("floor_idx", floor, dims="obs_id")
county_idx = pm.Data("county_idx", county, dims="obs_id")
# Hyperpriors:
a = pm.Normal("a", mu=0.0, sigma=10.0)
sigma_a = pm.Exponential("sigma_a", 1.0)

# Varying intercepts:
a_county = pm.Normal("a_county", mu=a, sigma=sigma_a, dims="County")
# Common slope:
b = pm.Normal("b", mu=0.0, sigma=10.0)

# Expected value per county:
theta = a_county[county_idx] + b * floor_idx
# Model error:
sigma = pm.Exponential("sigma", 1.0)

y = pm.Normal("y", theta, sigma=sigma, observed=log_radon, dims="obs_id")
pm.model_to_graphviz(varying_intercept)
[28]:

Let’s fit this bad boy with MCMC:

[29]:
with varying_intercept:
varying_intercept_idata = pm.sample(
)
Auto-assigning NUTS sampler...
Multiprocess sampling (4 chains in 4 jobs)
NUTS: [sigma, b, a_county, sigma_a, a]
100.00% [12000/12000 00:07<00:00 Sampling 4 chains, 0 divergences]
Sampling 4 chains for 2_000 tune and 1_000 draw iterations (8_000 + 4_000 draws total) took 8 seconds.
[30]:
az.plot_forest(
varying_intercept_idata, var_names=["a", "a_county"], r_hat=True, combined=True, textsize=9
);
[31]:
az.plot_trace(varying_intercept_idata, var_names=["a", "sigma_a", "b", "sigma"]);
[32]:
az.summary(varying_intercept_idata, var_names=["a", "sigma_a", "b", "sigma"], round_to=2)
[32]:
mean sd hdi_3% hdi_97% mcse_mean mcse_sd ess_mean ess_sd ess_bulk ess_tail r_hat
a 1.49 0.05 1.39 1.58 0.0 0.0 2439.58 2439.58 2438.68 2825.35 1.00
sigma_a 0.32 0.05 0.24 0.41 0.0 0.0 1358.99 1358.99 1309.91 2133.96 1.01
b -0.66 0.07 -0.78 -0.52 0.0 0.0 3555.35 3505.19 3536.51 2924.07 1.00
sigma 0.73 0.02 0.69 0.76 0.0 0.0 5898.53 5897.27 5887.97 2788.39 1.00

As we suspected, the estimate for the floor coefficient is reliably negative and centered around -0.66. This can be interpreted as houses without basements having about half ($$\exp(-0.66) = 0.52$$) the radon levels of those with basements, after accounting for county. Note that this is only the relative effect of floor on radon levels: conditional on being in a given county, radon is expected to be half lower in houses without basements than in houses with. To see how much difference a basement makes on the absolute level of radon, we’d have to push the parameters through the model, as we do with posterior predictive checks and as we’ll do just now.

To do so, we will take advantage of automatic broadcasting with xarray. We want to create a 2D array with dimensions (County, Level), our variable a_county already has the County dimension. b however is a scalar. We will multiply b with an xvals DataArray to introduce the Level dimension into the mix. xarray will handle everything from there, no loops nor reshapings required.

[33]:
xvals = xr.DataArray([0, 1], dims="Level", coords={"Level": ["Basement", "Floor"]})
post = varying_intercept_idata.posterior  # alias for readability
theta = (post.a_county + post.b * xvals).mean(dim=("chain", "draw")).to_dataset(name="Mean log radon")

_, ax = plt.subplots()
theta.plot.scatter(x="Level", y="Mean log radon", alpha=0.2, color="k", ax=ax) #scatter

The graph above shows, for each county, the expected log radon level and the average effect of having no basement – these are the absolute effects we were talking about. Two caveats though: 1. This graph doesn’t show the uncertainty for each county – how confident are we that the average estimates are where the graph shows? For that we’d need to combine the uncertainty in a_county and b, and this would of course vary by county. I didn’t show it here because the graph would get cluttered, but go ahead and do it for a subset of counties. 2. These are only average estimates at the county-level (theta in the model): they don’t take into account the variation by household. To add this other layer of uncertainty we’d need to take stock of the effect of sigma and generate samples from the y variable to see the effect on given households (that’s exactly the role of posterior predictive checks).

That being said, it is easy to show that the partial pooling model provides more objectively reasonable estimates than either the pooled or unpooled models, at least for counties with small sample sizes:

[34]:
fig, axes = plt.subplots(2, 4, figsize=(12, 6), sharey=True, sharex=True)
for ax, c in zip(axes.ravel(), SAMPLE_COUNTIES):

# plot obs:
unpooled_idata.observed_data.where(
).sortby("Level").plot.scatter(x="Level", y="y", ax=ax, alpha=.4)

# plot models:
ax.plot([0, 1], unpooled_means.a.sel(County=c), "k:", alpha=0.5, label="No pooling")
ax.plot([0, 1], pooled_means.a, "r--", label="Complete pooling")

ax.plot([0, 1], theta["Mean log radon"].sel(County=c), "b", label="Partial pooling")

ax.set_title(c); ax.set_xlabel(""); ax.set_ylabel("")
ax.tick_params(labelsize=10)

axes[0,0].legend(fontsize=8, frameon=True), axes[1,0].legend(fontsize=8, frameon=True)
fig.tight_layout();
/home/oriol/venvs/arviz-dev/lib/python3.6/site-packages/ipykernel_launcher.py:21: UserWarning: This figure was using constrained_layout==True, but that is incompatible with subplots_adjust and or tight_layout: setting constrained_layout==False.

Here we clearly see the notion that partial-pooling is a compromise between no pooling and complete pooling, as its mean estimates are usually between the other models’ estimates. And interestingly, the bigger (smaller) the sample size in a given county, the closer the partial-pooling estimates are to the no-pooling (complete-pooling) estimates.

We see however that counties vary by more than just their baseline rates: the effect of floor seems to be different from one county to another. It would be great if our model could take that into account, wouldn’t it? Well to do that, we need to allow the slope to vary by county – not only the intercept – and here is how you can do it with PyMC3.

## Varying intercept and slope model¶

The most general model allows both the intercept and slope to vary by county:

$y_i = \alpha_{j[i]} + \beta_{j[i]} x_{i} + \epsilon_i$
[35]:
with pm.Model(coords=coords) as varying_intercept_slope:
floor_idx = pm.Data("floor_idx", floor, dims="obs_id")
county_idx = pm.Data("county_idx", county, dims="obs_id")

# Hyperpriors:
a = pm.Normal("a", mu=0.0, sigma=5.0)
sigma_a = pm.Exponential("sigma_a", 1.0)
b = pm.Normal("b", mu=0.0, sigma=1.0)
sigma_b = pm.Exponential("sigma_b", 0.5)

# Varying intercepts:
a_county = pm.Normal("a_county", mu=a, sigma=sigma_a, dims="County")
# Varying slopes:
b_county = pm.Normal("b_county", mu=b, sigma=sigma_b, dims="County")

# Expected value per county:
theta = a_county[county_idx] + b_county[county_idx] * floor_idx
# Model error:
sigma = pm.Exponential("sigma", 1.0)

y = pm.Normal("y", theta, sigma=sigma, observed=log_radon, dims="obs_id")
pm.model_to_graphviz(varying_intercept_slope)
[35]:

Now, if you run this model, you’ll get divergences (some or a lot, depending on your random seed). We don’t want that – divergences are your Voldemort to your models. In these situations it’s usually wise to reparametrize your model using the “non-centered parametrization” (I know, it’s really not a great term, but please indulge me). We’re not gonna explain it here, but there are great resources out there. In a nutshell, it’s an algebraic trick that helps computation but leaves the model unchanged – the model is statistically equivalent to the “centered” version. In that case, here is what it would look like:

[36]:
with pm.Model(coords=coords) as varying_intercept_slope:
floor_idx = pm.Data("floor_idx", floor, dims="obs_id")
county_idx = pm.Data("county_idx", county, dims="obs_id")

# Hyperpriors:
a = pm.Normal("a", mu=0.0, sigma=5.0)
sigma_a = pm.Exponential("sigma_a", 1.0)
b = pm.Normal("b", mu=0.0, sigma=1.0)
sigma_b = pm.Exponential("sigma_b", 0.5)

# Varying intercepts:
za_county = pm.Normal("za_county", mu=0.0, sigma=1.0, dims="County")
# Varying slopes:
zb_county = pm.Normal("zb_county", mu=0.0, sigma=1.0, dims="County")

# Expected value per county:
theta = (
(a + za_county[county_idx] * sigma_a) +
(b + zb_county[county_idx] * sigma_b) * floor
)
# Model error:
sigma = pm.Exponential("sigma", 1.0)

y = pm.Normal("y", theta, sigma=sigma, observed=log_radon, dims="obs_id")

varying_intercept_slope_idata = pm.sample(
2000, tune=2000, target_accept=0.99, random_seed=RANDOM_SEED, return_inferencedata=True
)
Auto-assigning NUTS sampler...
Multiprocess sampling (4 chains in 4 jobs)
NUTS: [sigma, zb_county, za_county, sigma_b, b, sigma_a, a]
100.00% [16000/16000 01:24<00:00 Sampling 4 chains, 0 divergences]
Sampling 4 chains for 2_000 tune and 2_000 draw iterations (8_000 + 8_000 draws total) took 85 seconds.
The number of effective samples is smaller than 25% for some parameters.

True, the code is uglier (for you, not for the computer), but: 1. The interpretation stays pretty much the same: a and b are still the mean state-wide intercept and slope. sigma_a and sigma_b still estimate the dispersion across counties of the intercepts and slopes (the more alike the counties, the smaller the corresponding sigma). The big change is that now the counties estimates (za_county and zb_county) are z-scores. But the strategy to see what this means for mean radon levels per county is the same: push all these parameters through the model to get samples from theta. 2. We don’t have any divergence: the model sampled more efficiently and converged more quickly than in the centered form.

Notice however that we had to increase the number of tuning steps. Looking at the trace helps us understand why:

[37]:
az.plot_trace(varying_intercept_slope_idata, compact=True, chain_prop={"ls": "-"});

All chains look good and we get a negative b coefficient, illustrating the mean downward effect of no-basement on radon levels at the state level. But notice that sigma_b often gets very near zero – which would indicate that counties don’t vary that much in their answer to the floor “treatment”. That’s probably what bugged MCMC when using the centered parametrization: these situations usually yield a weird geometry for the sampler, causing the divergences. In other words, the non-centered form often perfoms better when one of the sigmas gets close to zero. But here, even with the non-centered model the sampler is not that comfortable with sigma_b: in fact if you look at the estimates with az.summary you’ll probably see that the number of effective samples is quite low for sigma_b.

Also note that sigma_a is not that big either – i.e counties do differ in their baseline radon levels, but not by a lot. However we don’t have that much of a problem to sample from this distribution because it’s much narrower than sigma_b and doesn’t get dangerously close to 0.

To wrap up this model, let’s plot the relationship between radon and floor for each county:

[38]:
xvals = xr.DataArray([0, 1], dims="Level", coords={"Level": ["Basement", "Floor"]})
post = varying_intercept_slope_idata.posterior  # alias for readability
avg_a_county = (post.a + post.za_county * post.sigma_a).mean(dim=("chain", "draw"))
avg_b_county = (post.b + post.zb_county * post.sigma_b).mean(dim=("chain", "draw"))
theta = (avg_a_county + avg_b_county * xvals).to_dataset(name="Mean log radon")

_, ax = plt.subplots()
theta.plot.scatter(x="Level", y="Mean log radon", alpha=0.2, color="k", ax=ax) #scatter

With the same caveats as earlier, we can see that now both the intercept and the slope vary by county – and isn’t that a marvel of statistics? But wait, there is more! We can (and maybe should) take into account the covariation between intercepts and slopes: when baseline radon is low in a given county, maybe that means the difference between floor and basement measurements will decrease – because there isn’t that much radon anyway. That would translate into a positive correlation between a_county and b_county, and adding that into our model would make even more efficient use the available data.

Or maybe the correlation is negative? In any case, we can’t know that unless we model it. To do that, we’ll use a multivariate Normal distribution instead of two different Normals for a_county and b_county. This simply means that each county’s parameters come from a common distribution with mean a for intercepts and b for slopes, and slopes and intercepts co-vary according to the covariance matrix S. In mathematical form:

$y \sim Normal(\theta, \sigma)$
$\theta = \alpha_{COUNTY} + \beta_{COUNTY} \times floor$
$\begin{split}\begin{bmatrix} \alpha_{COUNTY} \\ \beta_{COUNTY} \end{bmatrix} \sim MvNormal(\begin{bmatrix} \alpha \\ \beta \end{bmatrix}, \Sigma)\end{split}$
$\begin{split}\Sigma = \begin{pmatrix} \sigma_{\alpha} & 0 \\ 0 & \sigma_{\beta} \end{pmatrix} P \begin{pmatrix} \sigma_{\alpha} & 0 \\ 0 & \sigma_{\beta} \end{pmatrix}\end{split}$

where $$\alpha$$ and $$\beta$$ are the mean intercept and slope respectively, $$\sigma_{\alpha}$$ and $$\sigma_{\beta}$$ represent the variation in intercepts and slopes respectively, and $$P$$ is the correlation matrix of intercepts and slopes. In this case, as their is only one slope, $$P$$ contains only one relevant figure: the correlation between $$\alpha$$ and $$\beta$$.

This translates quite easily in PyMC3:

[39]:
coords["param"] = ["a", "b"]
coords["param_bis"] = ["a", "b"]
with pm.Model(coords=coords) as covariation_intercept_slope:
floor_idx = pm.Data("floor_idx", floor, dims="obs_id")
county_idx = pm.Data("county_idx", county, dims="obs_id")

# prior stddev in intercepts & slopes (variation across counties):
sd_dist = pm.Exponential.dist(0.5)

# get back standard deviations and rho:
chol, corr, stds = pm.LKJCholeskyCov(
"chol", n=2, eta=2.0, sd_dist=sd_dist, compute_corr=True
)

# prior for average intercept:
a = pm.Normal("a", mu=0.0, sigma=5.0)
# prior for average slope:
b = pm.Normal("b", mu=0.0, sigma=1.0)
# population of varying effects:
ab_county = pm.MvNormal(
"ab_county", mu=tt.stack([a, b]), chol=chol, dims=("County", "param")
)

# Expected value per county:
theta = ab_county[county_idx, 0] + ab_county[county_idx, 1] * floor_idx
# Model error:
sigma = pm.Exponential("sigma", 1.0)

y = pm.Normal("y", theta, sigma=sigma, observed=log_radon, dims="obs_id")
pm.model_to_graphviz(covariation_intercept_slope)
[39]:

This is by far the most complex model we’ve done so far, so it’s normal if you’re confused. Just take some time to let it sink in. The centered version mirrors the mathematical notions very closely, so you should be able to get the gist of it. Of course, you guessed it, we’re gonna need the non-centered version. There is actually just one change:

[40]:
with pm.Model(coords=coords) as covariation_intercept_slope:
floor_idx = pm.Data("floor_idx", floor, dims="obs_id")
county_idx = pm.Data("county_idx", county, dims="obs_id")

# prior stddev in intercepts & slopes (variation across counties):
sd_dist = pm.Exponential.dist(0.5)

# get back standard deviations and rho:
chol, corr, stds = pm.LKJCholeskyCov(
"chol", n=2, eta=2.0, sd_dist=sd_dist, compute_corr=True
)

# prior for average intercept:
a = pm.Normal("a", mu=0.0, sigma=5.0)
# prior for average slope:
b = pm.Normal("b", mu=0.0, sigma=1.0)
# population of varying effects:
z = pm.Normal("z", 0.0, 1.0, dims=("param", "County"))
ab_county = pm.Deterministic("ab_county", tt.dot(chol, z).T, dims=("County", "param"))

# Expected value per county:
theta = a + ab_county[county_idx, 0] + (b + ab_county[county_idx, 1]) * floor_idx
# Model error:
sigma = pm.Exponential("sigma", 1.0)

y = pm.Normal("y", theta, sigma=sigma, observed=log_radon, dims="obs_id")

covariation_intercept_slope_idata = pm.sample(
2000, tune=2000, target_accept=0.99, random_seed=RANDOM_SEED, return_inferencedata=True,
idata_kwargs={"dims": {"chol_stds": ["param"], "chol_corr": ["param", "param_bis"]}}
)
Auto-assigning NUTS sampler...
Multiprocess sampling (4 chains in 4 jobs)
NUTS: [sigma, z, b, a, chol]
100.00% [16000/16000 03:47<00:00 Sampling 4 chains, 0 divergences]
Sampling 4 chains for 2_000 tune and 2_000 draw iterations (8_000 + 8_000 draws total) took 228 seconds.
The number of effective samples is smaller than 25% for some parameters.
[41]:
az.plot_trace(
covariation_intercept_slope_idata,
var_names=["~z", "~chol"],
lines=[("chol_corr", {}, 0.0)],
compact=True,
chain_prop={"ls": "-"}
);

So the correlation between slopes and intercepts seems to be negative: when a_county increases, b_county tends to decrease. In other words, when basement radon in a county gets bigger, the difference with floor radon tends to get bigger too (because floor readings get smaller while basement readings get bigger). But again, the uncertainty is wide on Rho so it’s possible the correlation goes the other way around or is simply close to zero.

And how much variation is there across counties? It’s not easy to read sigma_ab above, so let’s do a forest plot and compare the estimates with the model that doesn’t include the covariation between slopes and intercepts:

[42]:
az.plot_forest(
[varying_intercept_slope_idata, covariation_intercept_slope_idata],
model_names=["No covariation", "With covariation"],
var_names=["a", "b", "sigma_a", "sigma_b", "chol_stds", "chol_corr"],
combined=True,
figsize=(8, 6),
);

The estimates are very close to each other, both for the means and the standard deviations. But remember, the information given by Rho is only seen at the county level: in theory it uses even more information from the data to get an even more informed pooling of information for all county parameters. So let’s visually compare estimates of both models at the county level:

[43]:
# posterior means of covariation model:
a_county_cov = (
covariation_intercept_slope_idata.posterior["a"]
+ covariation_intercept_slope_idata.posterior["ab_county"].sel(param="a")
).mean(dim=("chain", "draw"))
b_county_cov = (
covariation_intercept_slope_idata.posterior["b"]
+ covariation_intercept_slope_idata.posterior["ab_county"].sel(param="b")
).mean(dim=("chain", "draw"))

# plot both and connect with lines
plt.scatter(avg_a_county, avg_b_county, label="No cov estimates", alpha=0.6)
plt.scatter(
a_county_cov,
b_county_cov,
facecolors="none",
edgecolors="k",
lw=1,
label="With cov estimates",
alpha=0.8,
)
plt.plot([avg_a_county, a_county_cov], [avg_b_county, b_county_cov], "k-", alpha=0.5)
plt.xlabel("Intercept")
plt.ylabel("Slope")
plt.legend();

The negative correlation is somewhat clear here: when the intercept increases, the slope decreases. So we understand why the model put most of the posterior weight into negative territory for Rho. Nevertheless, the negativity isn’t that obvious, which is why the model gives a non-trivial posterior probability to the possibility that Rho could in fact be zero or positive.

Interestingly, the differences between both models occur at extreme slope and intercept values. This is because the second model used the slightly negative correlation between intercepts and slopes to adjust their estimates: when intercepts are larger (smaller) than average, the model pushes down (up) the associated slopes.

Globally, there is a lot of agreement here: modeling the correlation didn’t change inference that much. We already saw that radon levels tended to be lower in floors than basements, and when we checked the posterior distributions of the average effects (a and b) and standard deviations, we noticed that they were almost identical. But on average the model with covariation will be more accurate – because it squeezes additional information from the data, to shrink estimates in both dimensions.

A primary strength of multilevel models is the ability to handle predictors on multiple levels simultaneously. If we consider the varying-intercepts model above:

$y_i = \alpha_{j[i]} + \beta x_{i} + \epsilon_i$

we may, instead of a simple random effect to describe variation in the expected radon value, specify another regression model with a county-level covariate. Here, we use the county uranium reading $$u_j$$, which is thought to be related to radon levels:

$\alpha_j = \gamma_0 + \gamma_1 u_j + \zeta_j$
$\zeta_j \sim N(0, \sigma_{\alpha}^2)$

Thus, we are now incorporating a house-level predictor (floor or basement) as well as a county-level predictor (uranium).

Note that the model has both indicator variables for each county, plus a county-level covariate. In classical regression, this would result in collinearity. In a multilevel model, the partial pooling of the intercepts towards the expected value of the group-level linear model avoids this.

Group-level predictors also serve to reduce group-level variation, $$\sigma_{\alpha}$$ (here it would be the variation across counties, sigma_a). An important implication of this is that the group-level estimate induces stronger pooling – by definition, a smaller $$\sigma_{\alpha}$$ means a stronger shrinkage of counties parameters towards the overall state mean.

This is fairly straightforward to implement in PyMC3 – we just add another level:

[44]:
with pm.Model(coords=coords) as hierarchical_intercept:
floor_idx = pm.Data("floor_idx", floor, dims="obs_id")
county_idx = pm.Data("county_idx", county, dims="obs_id")
uranium = pm.Data("uranium", u, dims="County")

# Hyperpriors:
g = pm.Normal("g", mu=0.0, sigma=10.0, shape=2)
sigma_a = pm.Exponential("sigma_a", 1.0)

# Varying intercepts uranium model:
a = g[0] + g[1] * uranium
a_county = pm.Normal("a_county", mu=a, sigma=sigma_a, dims="County")
# Common slope:
b = pm.Normal("b", mu=0.0, sigma=1.0)

# Expected value per county:
theta = a_county[county_idx] + b * floor_idx
# Model error:
sigma = pm.Exponential("sigma", 1.0)

y = pm.Normal("y", theta, sigma=sigma, observed=log_radon, dims="obs_id")
pm.model_to_graphviz(hierarchical_intercept)
[44]:

Do you see the new level, with sigma_a and g, which is two-dimensional because it contains the linear model for a_county? Now, if we run this model we’re gonna get… divergences, you guessed it! So we’re gonna switch to the non-centered form again:

[45]:
with pm.Model(coords=coords) as hierarchical_intercept:
floor_idx = pm.Data("floor_idx", floor, dims="obs_id")
county_idx = pm.Data("county_idx", county, dims="obs_id")
uranium = pm.Data("uranium", u, dims="County")

# Hyperpriors:
g = pm.Normal("g", mu=0.0, sigma=10.0, shape=2)
sigma_a = pm.Exponential("sigma_a", 1.0)

# Varying intercepts uranium model:
a = pm.Deterministic("a", g[0] + g[1] * uranium, dims="County")
za_county = pm.Normal("za_county", mu=0.0, sigma=1.0, dims="County")
a_county = pm.Deterministic("a_county", a + za_county * sigma_a, dims="County")
# Common slope:
b = pm.Normal("b", mu=0.0, sigma=1.0)

# Expected value per county:
theta = a_county[county_idx] + b * floor_idx
# Model error:
sigma = pm.Exponential("sigma", 1.0)

y = pm.Normal("y", theta, sigma=sigma, observed=log_radon, dims="obs_id")

hierarchical_intercept_idata = pm.sample(
2000, tune=2000, target_accept=0.99, random_seed=RANDOM_SEED, return_inferencedata=True
)
Auto-assigning NUTS sampler...
Multiprocess sampling (4 chains in 4 jobs)
NUTS: [sigma, b, za_county, sigma_a, g]
100.00% [16000/16000 00:49<00:00 Sampling 4 chains, 0 divergences]
Sampling 4 chains for 2_000 tune and 2_000 draw iterations (8_000 + 8_000 draws total) took 50 seconds.
The number of effective samples is smaller than 25% for some parameters.
[46]:
uranium = hierarchical_intercept_idata.constant_data.uranium
post = hierarchical_intercept_idata.posterior.assign_coords(uranium=uranium)
avg_a = post["a"].mean(dim=("chain", "draw")).sortby("uranium")
avg_a_county = post["a_county"].mean(dim=("chain", "draw"))
avg_a_county_hdi = az.hdi(post, var_names="a_county")["a_county"]

_, ax = plt.subplots()
ax.plot(
avg_a.uranium, avg_a, "k--", alpha=0.6, label="Mean intercept"
)
az.plot_hdi(
uranium,
post["a"],
fill_kwargs={"alpha": 0.1, "color": "k", "label": "Mean intercept HPD"},
ax=ax,
)
ax.scatter(uranium, avg_a_county, alpha=0.8, label="Mean county-intercept")
ax.vlines(
uranium,
avg_a_county_hdi.sel(hdi="lower"),
avg_a_county_hdi.sel(hdi="higher"),
alpha=0.5,
color="orange"
)
plt.xlabel("County-level uranium")
plt.ylabel("Intercept estimate")
plt.legend(fontsize=9);

Uranium is indeed much associated with baseline radon levels in each county. The graph above shows the average relationship and its uncertainty: the baseline radon level in an average county as a function of uranium, as well as the 94% HPD of this radon level (grey line and envelope). The blue points and orange bars represent the relationship between baseline radon and uranium, but now for each county. As you see, the uncertainty is bigger now, because it adds on top of the average uncertainty – each county has its idyosyncracies after all.

If we compare the county-intercepts for this model with those of the partial-pooling model without a county-level covariate:

[47]:
az.plot_forest(
[varying_intercept_idata, hierarchical_intercept_idata],
model_names=["W/t. county pred.", "With county pred."],
var_names=["a_county"],
combined=True,
figsize=(6, 40),
textsize=9
);

We see that the compatibility intervals are narrower for the model including the county-level covariate. This is expected, as the effect of a covariate is to reduce the variation in the outcome variable – provided the covariate is of predictive value. More importantly, with this model we were able to squeeze even more information out of the data.

## Correlations among levels¶

In some instances, having predictors at multiple levels can reveal correlation between individual-level variables and group residuals. We can account for this by including the average of the individual predictors as a covariate in the model for the group intercept:

$\alpha_j = \gamma_0 + \gamma_1 u_j + \gamma_2 \bar{x} + \zeta_j$

These are broadly referred to as contextual effects.

To add these effects to our model, let’s create a new variable containing the mean of floor in each county and add that to our previous model:

[48]:
avg_floor_data = srrs_mn.groupby("county")["floor"].mean().rename(county_lookup).values

with pm.Model(coords=coords) as contextual_effect:
floor_idx = pm.Data("floor_idx", floor, dims="obs_id")
county_idx = pm.Data("county_idx", county, dims="obs_id")
uranium = pm.Data("uranium", u, dims="County")
avg_floor = pm.Data("avg_floor", avg_floor_data, dims="County")

# Hyperpriors:
g = pm.Normal("g", mu=0.0, sigma=10.0, shape=3)
sigma_a = pm.Exponential("sigma_a", 1.0)

# Varying intercepts uranium model:
a = pm.Deterministic("a", g[0] + g[1] * u + g[2] * avg_floor, dims="County")
za_county = pm.Normal("za_county", mu=0.0, sigma=1.0, dims="County")
a_county = pm.Deterministic("a_county", a + za_county * sigma_a, dims="County")
# Common slope:
b = pm.Normal("b", mu=0.0, sigma=1.0)

# Expected value per county:
theta = a_county[county_idx] + b * floor_idx
# Model error:
sigma = pm.Exponential("sigma", 1.0)

y = pm.Normal("y", theta, sigma=sigma, observed=log_radon, dims="obs_id")

contextual_effect_idata = pm.sample(
2000, tune=2000, target_accept=0.99, random_seed=RANDOM_SEED, return_inferencedata=True
)
Auto-assigning NUTS sampler...
Multiprocess sampling (4 chains in 4 jobs)
NUTS: [sigma, b, za_county, sigma_a, g]
100.00% [16000/16000 00:59<00:00 Sampling 4 chains, 0 divergences]
Sampling 4 chains for 2_000 tune and 2_000 draw iterations (8_000 + 8_000 draws total) took 60 seconds.
The number of effective samples is smaller than 25% for some parameters.
[49]:
az.summary(contextual_effect_idata, var_names=["g"], round_to=2)
[49]:
mean sd hdi_3% hdi_97% mcse_mean mcse_sd ess_mean ess_sd ess_bulk ess_tail r_hat
g[0] 1.43 0.05 1.34 1.52 0.0 0.0 3845.53 3834.56 3848.68 4886.02 1.0
g[1] 0.70 0.09 0.54 0.86 0.0 0.0 4969.84 4969.84 4995.60 5415.66 1.0
g[2] 0.39 0.20 0.02 0.76 0.0 0.0 4459.62 4402.24 4460.29 5349.41 1.0

So we might infer from this that counties with higher proportions of houses without basements tend to have higher baseline levels of radon. This seems to be new, as up to this point we saw that floor was negatively associated with radon levels. But remember this was at the household-level: radon tends to be higher in houses with basements. But at the county-level it seems that the less basements on average in the county, the more radon. So it’s not that contradictory. What’s more, the estimate for $$\gamma_2$$ is quite uncertain and overlaps with zero, so it’s possible that the relationship is not that strong. And finally, let’s note that $$\gamma_2$$ estimates something else than uranium’s effect, as this is already taken into account by $$\gamma_1$$ – it answers the question “once we know uranium level in the county, is there any value in learning about the proportion of houses without basements?”.

All of this is to say that we shouldn’t interpret this causally: there is no credible mecanism by which a basement (or absence thereof) causes radon emissions. More probably, our causal graph is missing something: a confounding variable, one that influences both basement construction and radon levels, is lurking somewhere in the dark… Perhaps is it the type of soil, which might influence what type of structures are built and the level of radon? Maybe adding this to our model would help with causal inference.

## Prediction¶

Gelman (2006) used cross-validation tests to check the prediction error of the unpooled, pooled, and partially-pooled models

root mean squared cross-validation prediction errors:

• unpooled = 0.86

• pooled = 0.84

• multilevel = 0.79

There are two types of prediction that can be made in a multilevel model:

1. a new individual within an existing group

2. a new individual within a new group

The first type is the easiest one, as we’ve generally already sampled from the existing group. For this model, the first type of posterior prediction is the only one making sense, as counties are not added or deleted every day. So, if we wanted to make a prediction for, say, a new house with no basement in St. Louis and Kanabec counties, we just need to sample from the radon model with the appropriate intercept:

[50]:
county_lookup["ST LOUIS"], county_lookup["KANABEC"]
[50]:
(69, 31)

That is,

$\tilde{y}_i \sim N(\alpha_{69} + \beta (x_i=1), \sigma_y^2)$

Because we judiciously set the county index and floor values as shared variables earlier, we can modify them directly to the desired values (69 and 1 respectively) and sample corresponding posterior predictions, without having to redefine and recompile our model. Using the model just above:

[51]:
prediction_coords = {"obs_id": ["ST LOUIS", "KANABEC"]}
with contextual_effect:
pm.set_data({"county_idx": np.array([69, 31]), "floor_idx": np.array([1, 1])})
stl_pred = pm.fast_sample_posterior_predictive(
contextual_effect_idata.posterior, random_seed=RANDOM_SEED
)
az.from_pymc3_predictions(
stl_pred, idata_orig=contextual_effect_idata, inplace=True, coords=prediction_coords
)
[52]:
az.plot_posterior(contextual_effect_idata, group="predictions");

## Benefits of Multilevel Models¶

• Accounting for natural hierarchical structure of observational data.

• Estimation of coefficients for (under-represented) groups.

• Incorporating individual- and group-level information when estimating group-level coefficients.

• Allowing for variation among individual-level coefficients across groups.

## References¶

• Gelman, A., & Hill, J. (2006), Data Analysis Using Regression and Multilevel/Hierarchical Models (1st ed.), Cambridge University Press.

• Gelman, A. (2006), Multilevel (Hierarchical) modeling: what it can and cannot do, Technometrics, 48(3), 432–435.

• McElreath, R. (2020), Statistical Rethinking - A Bayesian Course with Examples in R and Stan (2nd ed.), CRC Press.

[53]: