Kernel: Python 3
In [1]:
/home/agustina/anaconda3/lib/python3.5/site-packages/statsmodels/compat/pandas.py:56: FutureWarning: The pandas.core.datetools module is deprecated and will be removed in a future version. Please use the pandas.tseries module instead.
from pandas.core import datetools
Code 6.1
In [2]:
brain | mass | species | |
---|---|---|---|
0 | 438 | 37.0 | afarensis |
1 | 452 | 35.5 | africanus |
2 | 612 | 34.5 | habilis |
3 | 521 | 41.5 | boisei |
4 | 752 | 55.5 | rudolfensis |
5 | 871 | 61.0 | ergaster |
6 | 1350 | 53.5 | sapiens |
Code 6.2
In [3]:
Code 6.3
In [4]:
0.4901580479490838
Code 6.4
In [5]:
Code 6.5
In [6]:
Code 6.6
In [7]:
Code 6.7
In [8]:
Code 6.8
In [9]:
Code 6.9
In [10]:
0.6108643020548935
Code 6.10
In [11]:
94.924989685887581
Code 6.11
In [12]:
100%|██████████| 2000/2000 [00:05<00:00, 338.85it/s]
In [13]:
In [14]:
100.48254797793284
Code 6.12 - 14
The overthinking section corresponding to cells 6.12-14 is not ported because it requires an ad-hoc rethinking package function. Feel free to contribute code to this section.
Code 6.15
In [15]:
In [16]:
100%|██████████| 2000/2000 [00:12<00:00, 161.13it/s]
Code 6.16
In [17]:
In [18]:
Code 6.17
In [19]:
/home/agustina/anaconda3/lib/python3.5/site-packages/ipykernel/__main__.py:5: DeprecationWarning: `logsumexp` is deprecated!
Importing `logsumexp` from scipy.misc is deprecated in scipy 1.0.0. Use `scipy.special.logsumexp` instead.
Code 6.18
In [20]:
Code 6.19
In [21]:
412.49046436448634
Code 6.20
In [22]:
14.88328369492803
Code 6.21
In [23]:
(17, 9)
Code 6.22
In [24]:
In [25]:
100%|██████████| 2000/2000 [00:08<00:00, 243.55it/s]
87%|████████▋ | 1747/2000 [02:33<00:22, 11.39it/s]/home/agustina/anaconda3/lib/python3.5/site-packages/pymc3/step_methods/hmc/nuts.py:468: UserWarning: Chain 1 contains 1 diverging samples after tuning. If increasing `target_accept` does not help try to reparameterize.
% (self._chain_id, n_diverging))
100%|█████████▉| 1999/2000 [02:45<00:00, 12.10it/s]/home/agustina/anaconda3/lib/python3.5/site-packages/pymc3/step_methods/hmc/nuts.py:468: UserWarning: Chain 0 contains 2 diverging samples after tuning. If increasing `target_accept` does not help try to reparameterize.
% (self._chain_id, n_diverging))
100%|██████████| 2000/2000 [02:45<00:00, 12.10it/s]
100%|██████████| 2000/2000 [00:28<00:00, 69.65it/s]
100%|██████████| 2000/2000 [04:31<00:00, 7.38it/s]/home/agustina/anaconda3/lib/python3.5/site-packages/pymc3/step_methods/hmc/nuts.py:452: UserWarning: The acceptance probability in chain 0 does not match the target. It is 0.681715916019, but should be close to 0.8. Try to increase the number of tuning steps.
% (self._chain_id, mean_accept, target_accept))
/home/agustina/anaconda3/lib/python3.5/site-packages/pymc3/step_methods/hmc/nuts.py:468: UserWarning: Chain 0 contains 25 diverging samples after tuning. If increasing `target_accept` does not help try to reparameterize.
% (self._chain_id, n_diverging))
/home/agustina/anaconda3/lib/python3.5/site-packages/pymc3/step_methods/hmc/nuts.py:468: UserWarning: Chain 1 contains 5 diverging samples after tuning. If increasing `target_accept` does not help try to reparameterize.
% (self._chain_id, n_diverging))
Code 6.23
In [26]:
/home/agustina/anaconda3/lib/python3.5/site-packages/pymc3/stats.py:220: UserWarning: For one or more samples the posterior variance of the
log predictive densities exceeds 0.4. This could be indication of
WAIC starting to fail see http://arxiv.org/abs/1507.04544 for details
""")
WAIC_r(WAIC=-17.054227823698863, WAIC_se=4.8600477062566103, p_WAIC=2.9504889764816951)
Code 6.24
In [27]:
WAIC | pWAIC | dWAIC | weight | SE | dSE | warning | |
---|---|---|---|---|---|---|---|
model | |||||||
m6.14 | -17.05 | 2.95 | 0 | 0.96 | 4.86 | 0 | 1 |
m6.13 | -9.22 | 1.88 | 7.84 | 0.02 | 3.99 | 3.25 | 1 |
m6.11 | -8.63 | 1.36 | 8.43 | 0.01 | 3.58 | 4.61 | 1 |
m6.12 | -7.18 | 1.93 | 9.88 | 0.01 | 3.15 | 4.76 | 1 |
Code 6.25
In [28]:
Code 6.26
In [29]:
-0.69650384567058254
Code 6.27
Compare function already checks number of observations to be equal.
In [30]:
m6_11 | m6_12 | m6_13 | m6_14 | |
---|---|---|---|---|
alpha | 0.657464 | 0.342740 | 0.706000 | -1.074019 |
beta | NaN | 0.466021 | -0.031884 | NaN |
beta__0 | NaN | NaN | NaN | -0.095749 |
beta__1 | NaN | NaN | NaN | 2.774855 |
sigma | 0.188901 | 0.192944 | 0.183208 | 0.139930 |
Code 6.28
In [31]:
In [32]:
Code 6.29
In [33]:
In [34]:
100%|██████████| 10000/10000 [00:37<00:00, 264.13it/s]
Code 6.30
In [35]:
100%|██████████| 10000/10000 [00:28<00:00, 355.45it/s]
In [36]:
In [37]:
This notebook was createad on a computer x86_64 running debian stretch/sid and using:
Python 3.5.4
IPython 4.1.2
PyMC3 3.2
NumPy 1.13.3
Pandas 0.21.0
SciPy 1.0.0
Matplotlib 2.0.2