sim.questionnaire.multi: Simulate multiple questionnaires with custom linear model...

View source: R/sim.questionnaire.R

sim.questionnaire.multiR Documentation

Simulate multiple questionnaires with custom linear model relationships

Description

Simulate multiple questionnaires with custom linear model relationships

Usage

sim.questionnaire.multi(
  N = 100,
  questionnaires,
  linear_model = NULL,
  linear_models = NULL,
  correlations = NULL,
  seed = NULL,
  debug = FALSE,
  max_retries = 20,
  verbose = TRUE
)

Arguments

N

Number of participants

questionnaires

List of questionnaire specifications. Each element should be a list with: - n_items: number of items - likert: vector of possible Likert scale values - total_mean: mean of total score distribution - total_sd: standard deviation of desired total score distribution - total_min: minimum possible total score (optional, will be calculated if not provided) - total_max: maximum possible total score (optional, will be calculated if not provided)

linear_model

(For backward compatibility or single models) A list specifying a single linear model.

linear_models

(Recommended) A list of lists, where each inner list specifies a linear model to be applied sequentially. Use this for mediation or other path models.

correlations

Optional correlation matrix between questionnaire total scores

seed

Random seed for reproducibility

debug

If TRUE, returns additional diagnostic information about the linear model

max_retries

The maximum number of attempts to generate a dataset that matches the desired coefficient signs.

verbose

If TRUE, prints messages about retry attempts for matching coefficient signs.

Value

Data frame with item-level responses and total scores for all questionnaires

Examples

# Example 1: Single moderation model (backward compatible)
set.seed(456)
simdat_single_mod <- sim.questionnaire.multi(
   N = 200,
   questionnaires = list(
     Anxiety = list(n_items = 10, likert = 1:5, total_mean = 30, total_sd = 6),
     Depression = list(n_items = 12, likert = 1:5, total_mean = 28, total_sd = 7),
     Stress = list(n_items = 8, likert = 1:7, total_mean = 15, total_sd = 4)
   ),
   linear_model = list(
     formula = "Stress ~ Anxiety + Depression + Anxiety*Depression",
     desired_coefficient_signs = list(Anxiety = 1, Depression = -1, "Anxiety:Depression" = -1)
   )
)
summary(lm(Stress_total ~ Anxiety_total * Depression_total, data = simdat_single_mod))

# Example 2: Mediation model (IV -> M -> DV)
set.seed(111)
simdat_mediation <- sim.questionnaire.multi(
  N = 150,
  questionnaires = list(
    Workload = list(n_items = 10, likert = 1:5, total_mean = 30, total_sd = 5),
    Burnout = list(n_items = 8, likert = 1:7, total_mean = 35, total_sd = 6),
    Satisfaction = list(n_items = 6, likert = 0:10, total_mean = 40, total_sd = 8)
  ),
  linear_models = list(
    list(formula = "Burnout ~ Workload", desired_coefficient_signs = list(Workload = 1)),
    list(formula = "Satisfaction ~ Burnout + Workload", desired_coefficient_signs = list(Burnout = -1, Workload = -1))
  ),
  max_retries = 10
)
summary(lm(Burnout_total ~ Workload_total, data = simdat_mediation))
summary(lm(Satisfaction_total ~ Burnout_total + Workload_total, data = simdat_mediation))

ccamp83/mu documentation built on July 4, 2025, 6:20 p.m.