0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

StanとRでベイズ統計モデリング(アヒル本)をPythonにしてみる - 7.5 交絡

Last updated at Posted at 2018-08-18

実行環境

インポート

import pandas as pd
import pystan
import matplotlib.pyplot as plt
from matplotlib.figure import figaspect
from matplotlib.markers import MarkerStyle
%matplotlib inline

データ読み込み

d = pd.read_csv('./data/data-50m.txt')
d['Age'] = pd.Categorical(d['Age'])

7.5 交絡

_, (ax1, ax2) = plt.subplots(1, 2, figsize=figaspect(3/8), sharex=True, sharey=True)
ax1.scatter('Weight', 'Y', data=d)
for i, age in enumerate(d['Age'].cat.categories):
    ax2.scatter('Weight', 'Y', data=d.query('Age==@age'), marker=MarkerStyle.filled_markers[i], label=age)
ax2.legend(title='Age')
for ax in [ax1, ax2]:
    plt.setp(ax, xlabel='Weight', ylabel='Y')
plt.show()

fig7-8.png

data = {col: d[col] for col in d.columns}
data['N'] = d.index.size
fit = pystan.stan('./stan/model7-5.stan', data=data, seed=1234)
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?