Skip to contents

Grouping variables can be supplied explicitly; when NULL the function falls back to common SCED name patterns and, for the within-case grouping, to structure-based detection (non-numeric column with 2-20 levels).

Usage

build_default_random_effects(
  model_data,
  scd_type,
  case_var = NULL,
  nest_var = NULL,
  study_var = NULL
)

Arguments

model_data

A data frame used for model fitting.

scd_type

A string indicating the SCD design type (e.g., "reversal", "changing_criterion", "multiple_baseline").

case_var, nest_var, study_var

Optional column names for the case-level grouping, the within-case grouping (e.g., behavior, skill, task), and the study-level grouping. Each defaults to NULL (auto-detect).

Value

A character string representing the random effects formula, or NULL if no case variable is found.

Examples

d <- data.frame(
  case = rep(c("C1", "C2"), each = 10),
  phase = rep(c("A", "B"), 10),
  level_AB = rep(c(0, 1), 10),
  outcome = rnorm(20)
)
build_default_random_effects(d, scd_type = "ab")
#> [1] "(1 + level_AB | case)"