The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.

Title: Controlled Interrupted Time Series Analysis and Visualization
Version: 0.1.3
Description: Implements controlled interrupted time series (CITS) analysis for evaluating interventions in comparative time-series data. The package provides tools for preparing panel time-series datasets, fitting models using generalized least squares (GLS) with optional autoregressive–moving-average (ARMA) error structures, and computing fitted values and robust standard errors using cluster-robust variance estimators (CR2). Visualization functions enable clear presentation of estimated effects and counterfactual trajectories following interventions. Background on methods for causal inference in interrupted time series can be found in Linden and Adams (2011) <doi:10.1111/j.1365-2753.2010.01504.x> and Lopez Bernal, Cummins, and Gasparrini (2018) <doi:10.1093/ije/dyy135>.
License: MIT + file LICENSE
Imports: dplyr, nlme, clubSandwich, ggplot2, stats, AICcmodavg
Suggests: knitr, rmarkdown, lmtest, testthat (≥ 3.0.0)
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.3.2
Depends: R (≥ 3.5)
VignetteBuilder: knitr
Config/testthat/edition: 3
NeedsCompilation: no
Packaged: 2025-12-17 07:50:07 UTC; Gu
Author: Hanmin Gu [aut, cre]
Maintainer: Hanmin Gu <ghm21zzang@gmail.com>
Repository: CRAN
Date/Publication: 2025-12-22 17:20:07 UTC

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)


Example CITS Dataset

Description

A simulated example dataset used in the citsr package vignette and examples.

Usage

df_cits_example

Format

A data frame with 240 rows and 4 variables:

T

Time index (1–120 repeated for two groups).

E

Group indicator (0 = control, 1 = treatment).

I

Intervention indicator (0/1).

y

Numeric outcome variable.

Source

Simulated data generated for package examples.


CITS Automatic Analysis and Visualization

Description

Visualizes the results of a controlled interrupted time series (CITS) model fitted using 'cits()'. The function plots observed data points, fitted values, and 95

Usage

plot_cits_result(
  res,
  y_col = "y",
  T_col = "T",
  E_col = "E",
  intervention_time = NULL
)

Arguments

res

A list returned by 'cits()', containing model output and fitted values.

y_col

Name of the outcome variable (string). Corresponds to 'y' in 'cits()'.

T_col

Name of the time index variable (string). Corresponds to 'T' in 'cits()'.

E_col

Name of the group indicator variable (string). Corresponds to 'E' in 'cits()'.

intervention_time

Optional numeric. If provided, a vertical dashed line is drawn at this time to mark the intervention point.

Value

A ggplot object showing observed points, fitted lines, confidence ribbons, and (optionally) the intervention line.

Examples

# Synthetic example
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
)

plot_cits_result(res)


CITS Automatic Analysis and Counterfactual Visualization

Description

Visualizes the results of a controlled interrupted time series (CITS) model fitted using 'cits()', and generates a counterfactual trajectory for the treatment group (E = 1) by setting the intervention indicator ('I') to 0 after the intervention time. The function displays observed points, fitted values, 95 with a vertical marker for the intervention.

Usage

plot_cits_result_cf(
  res,
  y_col = "y",
  T_col = "T",
  I_col = "I",
  E_col = "E",
  intervention_time
)

Arguments

res

A list returned by 'cits()', containing model output and fitted values.

y_col

Name of the outcome variable (string). Corresponds to 'y' in 'cits()'.

T_col

Name of the time index variable (string). Corresponds to 'T' in 'cits()'.

I_col

Name of the intervention indicator variable (string). Corresponds to 'I' in 'cits()'.

E_col

Name of the group indicator variable (string). Corresponds to 'E' in 'cits()'.

intervention_time

Numeric. Time point at which the intervention occurs.

Value

A ggplot object showing observed points, fitted lines, confidence ribbons, a counterfactual trajectory for the treatment group, and an intervention marker.

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
)

plot_cits_result_cf(res, intervention_time = 10)

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.