# =========================================================================
# Example 1: Complex Testlet Design
# =========================================================================
# Define the Testlet Blueprint
trt_design <- list(
# Testlet 1: Rasch Testlet Model (High dependence: var=0.8)
list(model = "RaschT", n_items = 5, testlet_id = "Read_A",
testlet_var = 0.8, b = c(-1, 1)),
# Testlet 2: 2PL Testlet Model (Default dependence: var=0.5)
list(model = "2PLT", n_items = 5, testlet_id = "Read_B",
a = c(0.7, 1.3)),
# Testlet 3: Graded Response Testlet (Polytomous, 4 categories)
list(model = "GRT", n_items = 4, testlet_id = "Survey",
categories = 4, testlet_var = 0.2)
)
# Run Simulation
trt_data <- sim_trt(n_people = 500, item_structure = trt_design)
# Inspect Results
# 1. Responses
head(trt_data$resp)
# 2. Item Parameters
# (Notice 'testlet_loading' equals 'discrimination' for standard models)
head(trt_data$true_item_params)
# 3. Person Parameters (Ability + Gamma for each testlet)
head(trt_data$true_person_params)
# =========================================================================
# Example 2: Manual Control (Theta, Gamma, and Parameters)
# =========================================================================
# 1. Manual Theta (e.g., everyone has high ability)
manual_theta <- rep(2.0, 100)
# 2. Manual Gamma (e.g., zero effect for T1)
manual_gamma <- rep(0, 100)
# 3. Item Parameters: Exact Match vs Range Sampling
custom_structure <- list(
# Case A: Manual Gamma Vector
list(model = "2PLT", n_items = 5, testlet_id = "T1",
gamma_vector = manual_gamma),
# Case B: Exact Parameter Match (Length of 'a' equals n_items)
list(model = "2PLT", n_items = 2, testlet_id = "T2",
a = c(0.5, 2.5)),
# Case C: Range Sampling (Length of 'a' is 2, but n_items != 2)
list(model = "2PLT", n_items = 5, testlet_id = "T3",
a = c(0.5, 2.5))
)
res_custom <- sim_trt(n_people = 100, theta = manual_theta,
item_structure = custom_structure)
# Verify Manual Theta
print(mean(res_custom$true_person_params$ability)) # Should be 2.0
# Verify Manual Gamma (T1 should be 0)
print(head(res_custom$true_person_params$testlet_T1))
# Verify Exact Match (T2 discrimination should be 0.5 and 2.5)
print(res_custom$true_item_params[res_custom$true_item_params$testlet_id == "T2",
"discrimination"])
Run the code above in your browser using DataLab