cits: Controlled Interrupted Time Series (CITS) Estimation

View source: R/cits.R

citsR Documentation

Controlled Interrupted Time Series (CITS) Estimation

Description

Fit a generalized least squares (GLS) Controlled Interrupted Time Series (CITS) model with optional autoregressive–moving-average (ARMA) correlation. Robust standard errors (CR2) are computed using the clubSandwich package. Interaction terms are automatically created if not provided.

Usage

cits(
  data,
  y_col,
  T_col,
  I_col,
  E_col,
  TI_col = NULL,
  ET_col = NULL,
  EI_col = NULL,
  ETI_col = NULL,
  p_range = 0:3,
  q_range = 0:3
)

Arguments

data

A data frame containing the variables for CITS analysis.

y_col

Outcome variable column name (string).

T_col

Time index column name (string).

I_col

Intervention indicator column name (string). Numeric: 1 indicates the intervention is applied at that time, 0 otherwise.

E_col

Group indicator column name (string). Numeric: 1 indicates the treatment/experimental group, 0 indicates the control group.

TI_col

Optional: Column name for the T × I interaction (default = NULL). Will be computed if NULL.

ET_col

Optional: Column name for the E × T interaction (default = NULL). Will be computed if NULL.

EI_col

Optional: Column name for the E × I interaction (default = NULL). Will be computed if NULL.

ETI_col

Optional: Column name for the E × T × I interaction (default = NULL). Will be computed if NULL.

p_range

Range of autoregressive (AR) terms to search (default = 0:3).

q_range

Range of moving average (MA) terms to search (default = 0:3).

Details

This function fits a controlled interrupted time series (CITS) model using generalized least squares (GLS). It automatically calculates interaction terms if they are not provided in the input data. If ARMA fitting fails or produces non-stationary estimates, the function falls back to GLS without correlation.

The treatment group ('E_col = 1') is the group that receives the intervention, while 'E_col = 0' denotes the control group. The intervention indicator ('I_col') marks whether the intervention is applied at a given time point.

Value

A list containing:

model

The fitted GLS model object.

robust_se

CR2 robust covariance matrix from clubSandwich.

data

Data frame including fitted values and standard errors.

best_p

Selected AR order based on AIC.

best_q

Selected MA order based on AIC.

arma_used

Logical: TRUE if ARMA correlation selected, else FALSE.

Examples

df <- data.frame(
  T = 1:100,
  E = rep(c(0,1), each = 100),
  I = c(rep(0,50), rep(1,50), rep(0,50), rep(1,50)),
  y = rnorm(200)
)

# Use lightweight ARMA search for examples (CRAN speed requirement)
res <- cits(
  df,
  y_col = "y",
  T_col = "T",
  I_col = "I",
  E_col = "E",
  p_range = 0:1,
  q_range = 0:0
)

summary(res$model)


citsr documentation built on July 12, 2026, 5:07 p.m.