create_synthetic_irt_dichotomous

def create_synthetic_irt_dichotomous(difficulty, discrimination, thetas, guessing=0, seed=None)

Creates dichotomous unidimensional synthetic IRT data.

Creates synthetic IRT data to test parameters estimation functions.
Only for use with dichotomous outputs

Assumes the model P(theta) = 1.0 / (1 + exp(discrimination * (theta - difficulty)))

Args

difficulty
[array] of difficulty parameters
discrimination
[array | number] of discrimination parameters
thetas
[array] of person abilities
guessing
[array | number] of guessing parameters associated with items
seed
Optional setting to reproduce results

Returns

synthetic_data
(2d array) realization of possible response given parameters
Expand source code
def create_synthetic_irt_dichotomous(difficulty, discrimination, thetas,
                                     guessing=0, seed=None):
    """ Creates dichotomous unidimensional synthetic IRT data.

    Creates synthetic IRT data to test parameters estimation functions.  
    Only for use with dichotomous outputs

    Assumes the model
        P(theta) = 1.0 / (1 + exp(discrimination * (theta - difficulty)))

    Args:
        difficulty: [array] of difficulty parameters
        discrimination:  [array | number] of discrimination parameters
        thetas: [array] of person abilities
        guessing: [array | number] of guessing parameters associated with items
        seed: Optional setting to reproduce results

    Returns:
        synthetic_data: (2d array) realization of possible response given parameters

    """
    if seed:
        np.random.seed(seed)

    if np.ndim(guessing) < 1:
        guessing = np.full_like(difficulty, guessing)

    continuous_output = irt_evaluation(difficulty, discrimination, thetas)

    # Add guessing parameters
    continuous_output *= (1.0 - guessing[:, None])
    continuous_output += guessing[:, None]

    # convert to binary based on probability
    random_compare = np.random.rand(*continuous_output.shape)

    return random_compare <= continuous_output