sim.PCM: Simulate Item Responses for Partial Credit and Rasch Models...

View source: R/sim.PCM.R

sim.PCMR Documentation

Simulate Item Responses for Partial Credit and Rasch Models with Varying Levels

Description

Simulate polytomous item responses based on item difficulty thresholds (delta) and person abilities (theta) for the Partial Credit Model (PCM) and the Rasch Model as a special case. The function allows items to have varying numbers of levels, making it useful for generating data in contexts such as item response theory (IRT) models for polytomous items (e.g., Likert scales).

Usage

sim.PCM(pN, iN, lN, itemLevels = NULL, delta = NULL, delta.l = NULL, theta = NULL)

Arguments

pN

integer. The number of people (respondents) to simulate.

iN

integer. The number of items in the test or survey.

lN

integer. The default number of levels (categories) for each polytomous item. Must be greater than or equal to 2. This is used if itemLevels is not provided.

itemLevels

integer vector. An optional vector specifying the number of levels for each item. If provided, the length must equal iN. If not provided, all items are assumed to have lN levels.

delta

matrix. An optional matrix of item thresholds with dimensions iN by the maximum number of levels in itemLevels. If not provided, the function will generate thresholds internally. The first column must contain zeros or the function will automatically prepend a column of zeros. If provided as a vector, it will be converted into a single-column matrix.

delta.l

numeric vector. An optional vector of common level thresholds (with length lN - 1). This vector represents the difficulty of each level. If not provided, the function will generate it.

theta

numeric vector. An optional vector of person abilities. If not provided, abilities will be drawn from a standard normal distribution (mean = 0, sd = 1).

Details

This function generates polytomous item responses using a logistic IRT model. It first creates or uses given person abilities (theta) and item thresholds (delta). Responses are simulated by computing the probability of a person responding in each category of an item based on their ability and the item's threshold. The function allows for items to have different numbers of response categories through the itemLevels argument.

Value

A list with the following components:

pN

The number of people (respondents).

iN

The number of items.

lN

The default number of levels (categories) for the polytomous items.

itemLevels

A vector specifying the number of levels for each item.

M

A list of iN matrices containing logits (differences between person ability and item threshold) for each person and item.

CM

A list of iN matrices containing cumulative probabilities for each person and item.

U

A pN by iN matrix of uniform random values used to generate the responses.

theta

A numeric vector of person abilities.

delta.l

(Optional) A vector of common level thresholds if it was generated internally.

delta.il

(Optional) A matrix of item-specific deviations for thresholds if delta.l was generated internally.

delta

A matrix of item thresholds.

resp

A pN by iN matrix of simulated responses. Each entry corresponds to the level chosen by the person for the respective item.

Author(s)

David Torres Irribarra

See Also

runif, rnorm

Examples

# Simulate 100 respondents, 5 items, and 3 levels (e.g., Likert scale with 3 options)
simulated_data <- sim.PCM(pN = 100, iN = 5, lN = 3)

# Simulate with custom item thresholds
custom_delta <- matrix(c(-0.5, -1, -2, 1, 0.5, 1), nrow = 3)
simulated_data_custom <- sim.PCM(pN = 50, iN = 3, lN = 3, delta = custom_delta)

# Simulate with custom person abilities
custom_theta <- rnorm(100, mean = 0, sd = 1.5)
simulated_data_theta <- sim.PCM(pN = 100, iN = 5, lN = 3, theta = custom_theta)

# Rasch model simulation (dichotomous items)
# 50 persons with abilities ranging from -3 to 3
rasch_theta <- seq(-3, 3, length.out = 50)
rasch_delta <- matrix(c(0,1.5,0,-1,0,0.5,0,-0.5,0,1,0,-1.5,0,2,0,-2,0,0.8,0,-0.8)
                      , ncol = 2, byrow = TRUE)
simulated_rasch <- sim.PCM(pN = 50, iN = 10, lN = 2, delta = rasch_delta, theta = rasch_theta)

# Simulation with items having different numbers of levels
# 4 items with 5 levels, 3 items with dichotomous responses, and 3 items with 3 levels
# Simulate with a total of 10 items and varying levels
simulated_mixed_levels <- sim.PCM(pN = 50, iN = 10, lN = 5, 
                                  itemLevels = c(5, 5, 5, 5, 2, 2, 2, 3, 3, 3))

WrightMap documentation built on Sept. 24, 2024, 9:07 a.m.