Skip to content

Instantly share code, notes, and snippets.

@1pha
Last active February 2, 2021 04:26
Show Gist options
  • Save 1pha/f8c860cd84ee6279a6f2d1fd5db9819f to your computer and use it in GitHub Desktop.
Save 1pha/f8c860cd84ee6279a6f2d1fd5db9819f to your computer and use it in GitHub Desktop.
3 Parameter item characteristic curve from Item response theory (IRT), written with python
from scipy.stats import norm
import numpy as np
import matplotlib.pyplot as plt
a, b, c = 1, 0, 0
D = 1.702
def normal_ogive(theta, a=1, b=0, c=0):
return c + (1 - c) * norm.cdf(a*(theta - b))
def logistic(theta, a=1, b=0, c=0, D=1.702):
return c + (1 - c) / (1+np.exp(-D *a * (theta - b)))
def plot_params(a=1, b=0, c=0, D=1.702):
thetas = np.linspace(-3, 3)
title = f'Discrimination(a)={a}, Diff(b)={b}, Guess(c)={c}, Scaling(D)={D}'
plt.figure(figsize=(8, 6))
plt.title(title)
plt.plot(thetas, normal_ogive(thetas, a, b, c), label='Normal Ogive')
plt.plot(thetas, logistic(thetas, a, b, c, D), label='Logistic')
plt.legend(prop={'size': 13})
plt.grid()
plt.show()
plot_params()
@1pha
Copy link
Author

1pha commented Feb 1, 2021

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment