def create_synthetic_mirt_dichotomous(difficulty, discrimination, thetas, seed=None)
Creates dichotomous multidimensional synthetic IRT data.
Assumes the model P(theta) = 1.0 / (1 + exp(-1 * (dot(discrimination,theta) + difficulty)))
difficulty
discrimination
thetas
seed
synthetic_data
n_factors = 3 n_items = 15 n_people = 500 difficulty = np.linspace(-2.5, 2.5, n_items) discrimination = np.random.randn(n_items, n_factors) thetas = np.random.randn(n_factors, n_people)
synthetic_data = create_synthetic_mirt_dichotomous(difficulty, discrimination, thetas)
def create_synthetic_mirt_dichotomous(difficulty, discrimination, thetas,
seed=None):
""" Creates dichotomous multidimensional synthetic IRT data.
Assumes the model
P(theta) = 1.0 / (1 + exp(-1 * (dot(discrimination,theta) + difficulty)))
Args:
difficulty: [array, M] of difficulty parameters
discrimination: [2-D array, MxN] of discrimination parameters
thetas: [2-D array, NxP] of person abilities
seed: Optional setting to reproduce results
Returns:
synthetic_data: (2d array) realization of possible response given parameters
Example:
n_factors = 3
n_items = 15
n_people = 500
difficulty = np.linspace(-2.5, 2.5, n_items)
discrimination = np.random.randn(n_items, n_factors)
thetas = np.random.randn(n_factors, n_people)
synthetic_data = create_synthetic_mirt_dichotomous(difficulty, discrimination, thetas)
"""
if seed:
np.random.seed(seed)
# If the input is just a vector of discriminations
if (np.ndim(discrimination) == 1) or (discrimination.shape[0] == 1):
discrimination = np.vstack((discrimination,) * difficulty.shape[0])
# Inline computation of the logistic kernel
kernel_terms = discrimination @ thetas
kernel_terms += difficulty[:, None]
continuous_output = 1.0 / (1.0 + np.exp(-kernel_terms))
# convert to binary based on probability
random_compare = np.random.rand(*continuous_output.shape)
return random_compare <= continuous_output