Kernel: Python 3
In [1]:
/home/osvaldo/anaconda3/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
from ._conv import register_converters as _register_converters
Code 5.1
In [2]:
In [3]:
Auto-assigning NUTS sampler...
Initializing NUTS using jitter+adapt_diag...
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [sigma_interval__, bA, a]
100%|██████████| 2000/2000 [00:01<00:00, 1027.91it/s]
In [4]:
Code 5.2
In [5]:
Code 5.3
In [6]:
In [7]:
Auto-assigning NUTS sampler...
Initializing NUTS using jitter+adapt_diag...
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [sigma_interval__, bA, a]
100%|██████████| 2000/2000 [00:01<00:00, 1166.50it/s]
In [8]:
In [9]:
Code 5.4
In [10]:
Auto-assigning NUTS sampler...
Initializing NUTS using jitter+adapt_diag...
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [sigma_interval__, bA, a]
100%|██████████| 2000/2000 [00:02<00:00, 699.95it/s]
In [11]:
In [12]:
mean | sd | mc_error | hpd_5.5 | hpd_94.5 | n_eff | Rhat | |
---|---|---|---|---|---|---|---|
a | 9.688 | 0.219 | 0.005 | 9.337 | 10.036 | 1820.070 | 1.0 |
bA__0 | -0.122 | 0.289 | 0.007 | -0.579 | 0.339 | 1506.622 | 1.0 |
bA__1 | -1.120 | 0.288 | 0.007 | -1.578 | -0.676 | 1540.244 | 1.0 |
sigma | 1.522 | 0.157 | 0.003 | 1.277 | 1.771 | 1561.718 | 1.0 |
Code 5.5
In [14]:
Code 5.6
In [15]:
Auto-assigning NUTS sampler...
Initializing NUTS using jitter+adapt_diag...
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [sigma_interval__, b, a]
100%|██████████| 2000/2000 [00:01<00:00, 1320.20it/s]
In [16]:
Code 5.7
In [17]:
Code 5.8
In [18]:
Code 5.9
In [19]:
Code 5.10
In [20]:
Code 5.11
In [21]:
100%|██████████| 1000/1000 [00:00<00:00, 2766.11it/s]
Code 5.12
In [22]:
Code 5.14
In [23]:
Code 5.15
In [24]:
Code 5.16
In [25]:
clade | species | kcal.per.g | perc.fat | perc.protein | perc.lactose | mass | neocortex.perc | |
---|---|---|---|---|---|---|---|---|
0 | Strepsirrhine | Eulemur fulvus | 0.49 | 16.60 | 15.42 | 67.98 | 1.95 | 55.16 |
1 | Strepsirrhine | E macaco | 0.51 | 19.27 | 16.91 | 63.82 | 2.09 | NaN |
2 | Strepsirrhine | E mongoz | 0.46 | 14.11 | 16.85 | 69.04 | 2.51 | NaN |
3 | Strepsirrhine | E rubriventer | 0.48 | 14.91 | 13.18 | 71.91 | 1.62 | NaN |
4 | Strepsirrhine | Lemur catta | 0.60 | 27.28 | 19.50 | 53.22 | 2.19 | NaN |
Code 5.17 to 5.20
In [26]:
In [27]:
Auto-assigning NUTS sampler...
Initializing NUTS using jitter+adapt_diag...
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [sigma_interval__, bn, a]
100%|██████████| 2000/2000 [00:09<00:00, 217.22it/s]
There were 4 divergences after tuning. Increase `target_accept` or reparameterize.
The number of effective samples is smaller than 25% for some parameters.
In [28]:
Code 5.21
In [31]:
mean | sd | mc_error | hpd_5.5 | hpd_94.5 | n_eff | Rhat | |
---|---|---|---|---|---|---|---|
a | 0.338 | 0.554 | 0.024 | -0.540 | 1.205 | 536.423 | 1.0 |
bn | 0.005 | 0.008 | 0.000 | -0.008 | 0.018 | 536.629 | 1.0 |
sigma | 0.196 | 0.041 | 0.002 | 0.134 | 0.254 | 474.932 | 1.0 |
Code 5.22
In [32]:
0.09955421253996859
Code 5.23
In [33]:
Code 5.24
In [34]:
Code 5.25
In [35]:
Auto-assigning NUTS sampler...
Initializing NUTS using jitter+adapt_diag...
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [sigma_interval__, bn, a]
100%|██████████| 2000/2000 [00:01<00:00, 1062.03it/s]
In [36]:
mean | sd | mc_error | hpd_5.5 | hpd_94.5 | n_eff | Rhat | |
---|---|---|---|---|---|---|---|
a | 0.703 | 0.058 | 0.002 | 0.609 | 0.791 | 900.755 | 1.000 |
bn | -0.031 | 0.024 | 0.001 | -0.072 | 0.003 | 914.185 | 0.999 |
sigma | 0.182 | 0.037 | 0.001 | 0.126 | 0.232 | 1031.675 | 1.000 |
Code 5.26
In [37]:
Auto-assigning NUTS sampler...
Initializing NUTS using jitter+adapt_diag...
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [sigma_interval__, bn, a]
100%|██████████| 2000/2000 [00:16<00:00, 123.40it/s]
There were 3 divergences after tuning. Increase `target_accept` or reparameterize.
There were 11 divergences after tuning. Increase `target_accept` or reparameterize.
The number of effective samples is smaller than 25% for some parameters.
In [38]:
mean | sd | mc_error | hpd_5.5 | hpd_94.5 | n_eff | Rhat | |
---|---|---|---|---|---|---|---|
a | -1.109 | 0.579 | 0.023 | -1.959 | -0.097 | 480.448 | 1.000 |
bn__0 | 0.028 | 0.009 | 0.000 | 0.013 | 0.042 | 470.322 | 1.000 |
bn__1 | -0.097 | 0.028 | 0.001 | -0.140 | -0.051 | 574.242 | 0.999 |
sigma | 0.140 | 0.030 | 0.001 | 0.093 | 0.179 | 282.447 | 1.001 |
Code 5.27
In [39]:
Code 5.28
In [40]:
Code 5.29
In [41]:
Code 5.30
In [42]:
Auto-assigning NUTS sampler...
Initializing NUTS using jitter+adapt_diag...
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [sigma_interval__, br, bl, a]
100%|██████████| 2000/2000 [01:49<00:00, 18.31it/s]
In [43]:
mean | sd | mc_error | hpd_5.5 | hpd_94.5 | n_eff | Rhat | |
---|---|---|---|---|---|---|---|
a | 0.706 | 0.265 | 0.008 | 0.292 | 1.126 | 978.995 | 1.0 |
bl | 3.498 | 1.882 | 0.065 | 0.728 | 6.536 | 773.283 | 1.0 |
br | -1.443 | 1.890 | 0.065 | -4.147 | 1.677 | 774.994 | 1.0 |
sigma | 0.577 | 0.040 | 0.001 | 0.516 | 0.637 | 1097.410 | 1.0 |
Code 5.31
In [45]:
Code 5.32
In [46]:
Code 5.33
In [47]:
Code 5.34
In [48]:
Auto-assigning NUTS sampler...
Initializing NUTS using jitter+adapt_diag...
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [sigma_interval__, bl, a]
100%|██████████| 2000/2000 [00:04<00:00, 497.31it/s]
In [49]:
mean | sd | mc_error | hpd_5.5 | hpd_94.5 | n_eff | Rhat | |
---|---|---|---|---|---|---|---|
a | 0.678 | 0.253 | 0.009 | 0.288 | 1.083 | 598.443 | 1.0 |
bl | 2.062 | 0.056 | 0.002 | 1.972 | 2.150 | 555.537 | 1.0 |
sigma | 0.573 | 0.042 | 0.001 | 0.508 | 0.639 | 1022.338 | 1.0 |
Code 5.35
In [50]:
clade | species | kcal.per.g | perc.fat | perc.protein | perc.lactose | mass | neocortex.perc | |
---|---|---|---|---|---|---|---|---|
0 | Strepsirrhine | Eulemur fulvus | 0.49 | 16.60 | 15.42 | 67.98 | 1.95 | 55.16 |
1 | Strepsirrhine | E macaco | 0.51 | 19.27 | 16.91 | 63.82 | 2.09 | NaN |
2 | Strepsirrhine | E mongoz | 0.46 | 14.11 | 16.85 | 69.04 | 2.51 | NaN |
3 | Strepsirrhine | E rubriventer | 0.48 | 14.91 | 13.18 | 71.91 | 1.62 | NaN |
4 | Strepsirrhine | Lemur catta | 0.60 | 27.28 | 19.50 | 53.22 | 2.19 | NaN |
Code 5.36
In [51]:
Auto-assigning NUTS sampler...
Initializing NUTS using jitter+adapt_diag...
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [sigma_interval__, bf, a]
100%|██████████| 2000/2000 [00:03<00:00, 584.32it/s]
In [52]:
mean | sd | mc_error | hpd_5.5 | hpd_94.5 | n_eff | Rhat | |
---|---|---|---|---|---|---|---|
a | 0.296 | 0.038 | 0.001 | 0.230 | 0.352 | 669.791 | 1.000 |
bf | 0.010 | 0.001 | 0.000 | 0.009 | 0.012 | 672.732 | 1.000 |
sigma | 0.079 | 0.012 | 0.000 | 0.061 | 0.097 | 804.753 | 1.003 |
In [53]:
Auto-assigning NUTS sampler...
Initializing NUTS using jitter+adapt_diag...
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [sigma_interval__, bl, a]
100%|██████████| 2000/2000 [00:04<00:00, 422.39it/s]
In [54]:
mean | sd | mc_error | hpd_5.5 | hpd_94.5 | n_eff | Rhat | |
---|---|---|---|---|---|---|---|
a | 1.164 | 0.048 | 0.002 | 1.088 | 1.239 | 641.491 | 1.001 |
bl | -0.011 | 0.001 | 0.000 | -0.012 | -0.009 | 692.192 | 1.001 |
sigma | 0.067 | 0.009 | 0.000 | 0.052 | 0.081 | 910.639 | 1.002 |
Code 5.37
In [55]:
Auto-assigning NUTS sampler...
Initializing NUTS using jitter+adapt_diag...
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [sigma_interval__, bl, bf, a]
100%|██████████| 2000/2000 [00:14<00:00, 137.25it/s]
The acceptance probability does not match the target. It is 0.8913043977304509, but should be close to 0.8. Try to increase the number of tuning steps.
There were 10 divergences after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.7166625089873978, but should be close to 0.8. Try to increase the number of tuning steps.
The number of effective samples is smaller than 25% for some parameters.
In [56]:
mean | sd | mc_error | hpd_5.5 | hpd_94.5 | n_eff | Rhat | |
---|---|---|---|---|---|---|---|
a | 0.995 | 0.223 | 0.01 | 0.635 | 1.348 | 485.708 | 1.001 |
bf | 0.002 | 0.003 | 0.00 | -0.002 | 0.006 | 495.420 | 1.001 |
bl | -0.009 | 0.003 | 0.00 | -0.013 | -0.004 | 494.107 | 1.001 |
sigma | 0.068 | 0.011 | 0.00 | 0.051 | 0.081 | 491.258 | 1.002 |
Code 5.38
In [57]:
Code 5.39
In [58]:
-0.9416373456839282
Code 5.40
In [59]:
Code 5.41
In [60]:
Code 5.42
In [61]:
Auto-assigning NUTS sampler...
Initializing NUTS using jitter+adapt_diag...
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [sigma_interval__, bf, bt, bh, a]
100%|██████████| 2000/2000 [00:09<00:00, 219.22it/s]
In [62]:
mean | sd | mc_error | hpd_5.5 | hpd_94.5 | n_eff | Rhat | |
---|---|---|---|---|---|---|---|
a | 5.152 | 0.522 | 0.015 | 4.346 | 5.958 | 945.669 | 1.000 |
bh | 0.990 | 0.052 | 0.002 | 0.912 | 1.072 | 942.363 | 1.000 |
bt | -0.047 | 0.206 | 0.005 | -0.362 | 0.287 | 1353.866 | 1.000 |
bf | -2.668 | 0.232 | 0.006 | -3.051 | -2.326 | 1269.197 | 1.000 |
sigma | 0.985 | 0.071 | 0.002 | 0.876 | 1.094 | 1499.170 | 1.001 |
Code 5.43
In [63]:
Auto-assigning NUTS sampler...
Initializing NUTS using jitter+adapt_diag...
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [sigma_interval__, bt, bh, a]
100%|██████████| 2000/2000 [00:06<00:00, 323.02it/s]
The acceptance probability does not match the target. It is 0.9031963539075056, but should be close to 0.8. Try to increase the number of tuning steps.
In [64]:
mean | sd | mc_error | hpd_5.5 | hpd_94.5 | n_eff | Rhat | |
---|---|---|---|---|---|---|---|
a | 4.289 | 0.801 | 0.026 | 2.849 | 5.387 | 808.481 | 0.999 |
bh | 0.962 | 0.081 | 0.003 | 0.836 | 1.088 | 828.823 | 1.000 |
bt | 0.770 | 0.294 | 0.008 | 0.283 | 1.216 | 1210.581 | 1.000 |
sigma | 1.502 | 0.111 | 0.003 | 1.328 | 1.679 | 1320.224 | 1.000 |
Code 5.44
In [65]:
height | weight | age | male | |
---|---|---|---|---|
0 | 151.765 | 47.825606 | 63.0 | 1 |
1 | 139.700 | 36.485807 | 63.0 | 0 |
2 | 136.525 | 31.864838 | 65.0 | 0 |
3 | 156.845 | 53.041915 | 41.0 | 1 |
4 | 145.415 | 41.276872 | 51.0 | 0 |
Code 5.45
In [66]:
Auto-assigning NUTS sampler...
Initializing NUTS using jitter+adapt_diag...
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [sigma_interval__, bm, a]
100%|██████████| 2000/2000 [00:02<00:00, 838.72it/s]
In [67]:
mean | sd | mc_error | hpd_5.5 | hpd_94.5 | n_eff | Rhat | |
---|---|---|---|---|---|---|---|
a | 134.842 | 1.631 | 0.048 | 132.307 | 137.442 | 966.190 | 1.0 |
bm | 7.222 | 2.354 | 0.069 | 3.571 | 11.139 | 974.984 | 1.0 |
sigma | 27.405 | 0.798 | 0.020 | 26.216 | 28.720 | 1916.216 | 1.0 |
Code 5.46
In [68]:
array([138.85167759, 145.38548207])
Code 5.47
In [69]:
Auto-assigning NUTS sampler...
Initializing NUTS using jitter+adapt_diag...
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [sigma_interval__, am, af]
100%|██████████| 2000/2000 [00:01<00:00, 1144.87it/s]
Code 5.48
In [70]:
Code 5.49
In [71]:
array([0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0])
Code 5.50
In [72]:
Code 5.51
In [73]:
Auto-assigning NUTS sampler...
Initializing NUTS using jitter+adapt_diag...
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [sigma_interval__, b_S, b_OWM, b_NWM, a]
100%|██████████| 2000/2000 [00:02<00:00, 689.23it/s]
In [74]:
mean | sd | mc_error | hpd_5.5 | hpd_94.5 | n_eff | Rhat | |
---|---|---|---|---|---|---|---|
a | 0.546 | 0.044 | 0.001 | 0.472 | 0.612 | 986.461 | 1.0 |
b_NWM | 0.166 | 0.062 | 0.002 | 0.079 | 0.272 | 1144.439 | 1.0 |
b_OWM | 0.243 | 0.068 | 0.002 | 0.139 | 0.350 | 1063.904 | 1.0 |
b_S | -0.036 | 0.073 | 0.002 | -0.155 | 0.078 | 1195.937 | 1.0 |
sigma | 0.130 | 0.019 | 0.000 | 0.103 | 0.163 | 1166.728 | 1.0 |
Code 5.52
In [75]:
mean | sd | hpd_5.5 | hpd_94.5 | |
---|---|---|---|---|
mu_ape | 0.546 | 0.044 | 0.472 | 0.612 |
mu_NWM | 0.712 | 0.044 | 0.643 | 0.780 |
b_OWM | 0.243 | 0.068 | 0.139 | 0.350 |
b_S | -0.036 | 0.073 | -0.155 | 0.078 |
Code 5.53
In [76]:
(-0.20627036770774942, -0.07802395845314053, 0.05473488710942071)
Code 5.54
In [77]:
Code 5.55
In [78]:
Auto-assigning NUTS sampler...
Initializing NUTS using jitter+adapt_diag...
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [sigma_interval__, mu]
100%|██████████| 2000/2000 [00:01<00:00, 1755.60it/s]
In [79]:
mean | sd | mc_error | hpd_5.5 | hpd_94.5 | n_eff | Rhat | |
---|---|---|---|---|---|---|---|
mu | 0.641 | 0.032 | 0.001 | 0.588 | 0.688 | 1877.261 | 1.0 |
sigma | 0.168 | 0.023 | 0.001 | 0.131 | 0.201 | 1930.809 | 1.0 |
The following cells (5.56-5.61) correspond to example code for the use of R's function: lm. Therefore they have no output.
Code 5.62
In [80]:
In [81]:
This notebook was createad on a computer x86_64 running debian stretch/sid and using:
Python 3.6.3
IPython 6.2.1
PyMC3 3.3
NumPy 1.14.1
Pandas 0.22.0
SciPy 1.0.0
Matplotlib 2.1.2
Seaborn 0.8.1