
Segmented level-change and slope-change effects for single-case data
level_slope_computation.RdFits a segmented AB time-series model separately to each study-case series and returns the immediate intervention level change and change in time slope, with model-based variances and their covariance.
Arguments
- data
Data frame containing repeated observations.
- studyID, subjectID, outcome_name, phase_name
Character strings naming the study, case, outcome, and phase columns.
- time_name
Character string naming the ordered measurement-time column.
- phase_order
Character vector giving the baseline and intervention labels, in that order. If
NULL, factor-level or alphabetical order is used.- improvement
Whether an increase or decrease in the outcome is beneficial.
- correlation
Either
"independence"for ordinary least squares or"ar1"for feasible generalized least squares with an estimated AR(1) residual correlation.- na_option
Currently only
"listwise"is supported.
Value
A data frame with two rows per study-case: level_change and
slope_change. cov_level_slope is repeated on both rows to allow the two
estimates to be retained as dependent effects in later synthesis.
Details
This function supports a single transition from baseline to intervention: all baseline times must precede all intervention times. The AR(1) option estimates rho from ordinary least-squares residuals; its reported variance treats that estimated rho as fixed and is therefore approximate.
Examples
dat <- data.frame(study = "S1", case = "A", time = 1:8,
phase = rep(c("A", "B"), each = 4),
outcome = c(1, 2, 2, 3, 5, 6, 7, 8))
level_slope_computation(dat, "study", "case", "outcome", "phase", "time")
#> study_id case_id effect_id metric yi vi
#> S1.A.level_change S1 A level_change level_change 1.5 0.11
#> S1.A.slope_change S1 A slope_change slope_change 0.4 0.02
#> cov_level_slope residual_df autocorrelation correlation
#> S1.A.level_change 0.01 4 NA independence
#> S1.A.slope_change 0.01 4 NA independence