simulate_bkt_data: Simulate Data from a Bayesian Knowledge Tracing (BKT) Model

View source: R/simulation.R

simulate_bkt_dataR Documentation

Simulate Data from a Bayesian Knowledge Tracing (BKT) Model

Description

This function generates simulated student response data based on the BKT model. Each student is modeled as having a latent skill mastery state that can evolve over a sequence of activities according to specified learning, guessing, and slipping probabilities. The generated dataset can be used for testing, model evaluation, or demonstration purposes.

Usage

simulate_bkt_data(
  prior,
  guess,
  slip,
  learn,
  num_students,
  min_questions,
  max_questions,
  output_file = NULL
)

Arguments

prior

Numeric. Initial probability that a student has mastered the skill before any questions. Corresponds to the BKT parameter \(P_p\).

guess

Numeric. Probability that a student answers correctly despite not mastering the skill. Corresponds to the BKT parameter \(P_g\).

slip

Numeric. Probability that a student answers incorrectly despite mastering the skill. Corresponds to the BKT parameter \(P_s\).

learn

Numeric. Probability that a student transitions from the unmastered to mastered state after each activity. Corresponds to the BKT parameter \(P_l\).

num_students

Integer. Number of students to simulate.

min_questions

Integer. Minimum number of questions (activities) per student.

max_questions

Integer. Maximum number of questions (activities) per student. Each student's actual sequence length is randomly drawn from 1 to max_questions.

output_file

Character. Optional file path. If provided, the generated dataset will be written to a CSV file.

Details

The simulated responses follow the standard BKT transition logic:

P(K_{t+1} = 1) = P(K_t = 1) + (1 - P(K_t = 1)) \times P_l

and the observed correctness is drawn as:

P(C_t = 1) = P(K_t = 1)(1 - P_s) + (1 - P(K_t = 1))P_g.

Value

A data frame with the following columns:

  • order_id: Integer, the order of the question within a student's sequence.

  • correct: Binary (0/1), indicating whether the student answered correctly.

  • student_id: Integer, the unique identifier for each student.

  • skill_name: Character, the skill associated with the responses (currently fixed as "mathematic").

Examples

prior <- 0.2
guess <- 0.1
slip <- 0.1
learn <- 0.3
num_students <- 5
min_questions <- 5
max_questions <- 10

simulated_data <- simulate_bkt_data(
    prior = prior,
    guess = guess,
    slip = slip,
    learn = learn,
    num_students = num_students,
    min_questions = min_questions,
    max_questions = max_questions
)
head(simulated_data)


BKT documentation built on Sept. 5, 2026, 5:07 p.m.