Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

PyMCでのIRTモデルの実装例

既製品の標準的なモデル(2PLMなど)はパッケージで最尤推定すれば十分だが、Pythonの場合はIRT用のパッケージ(例えば pyirt)が数年前に更新が止まっている。

複雑な、独自のモデルはベイズモデリングする必要があり、PyMCやPyStanなどが候補になる。

2PLM

データの生成

Source
Loading...
Source
Loading...
<Axes: xlabel='raw_score', ylabel='Count'>
<Figure size 400x200 with 1 Axes>
/tmp/ipykernel_22305/1755574120.py:4: FutureWarning: The default of observed=False is deprecated and will be changed to True in a future version of pandas. Pass observed=False to retain current behavior or observed=True to adopt the future default and silence this warning.
  d = df.groupby("raw_score_cat")[item_col].mean().reset_index()
<Figure size 400x200 with 1 Axes>
Loading...

モデルの定義

注意点として、aaに非負制約をかけないとMCMCが収束しにくい(θ−b\theta-bの値とaaの値次第で同値の尤度が出てきて一意に決まらないので)

pm.LogNormal(mu=0.0, sigma=np.sqrt(0.5)) や pm.HalfNormal などが使われる事が多い様子

Loading...

推定

Initializing NUTS using jitter+adapt_diag...
Multiprocess sampling (4 chains in 4 jobs)
NUTS: [a, b, theta]
Loading...
Loading...
Sampling 4 chains for 1_000 tune and 1_000 draw iterations (4_000 + 4_000 draws total) took 22 seconds.
CPU times: user 5.51 s, sys: 255 ms, total: 5.77 s
Wall time: 26 s

EAP推定量

Loading...
<Figure size 1200x400 with 3 Axes>

MAP推定量

Loading...
Loading...
<Figure size 1200x400 with 3 Axes>

事後分布

一部の項目のaj,bja_j, b_j

Source
<Figure size 400x400 with 4 Axes>

一部の回答者のθi\theta_i

Source
<Figure size 400x200 with 2 Axes>