---
title: "citsr Package Examples"
author: "Hanmin Gu"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{citsr Package Examples}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

# Overview

This vignette demonstrates how to use the `citsr` package for conducting 
Controlled Interrupted Time Series (CITS) analysis. The package provides 
functions for model fitting using generalized least squares (GLS), visualizing 
fitted trajectories with confidence intervals, and generating counterfactual 
predictions for treatment groups.

```{r setup, include=FALSE}
library(citsr)
```

# 1. Example Data

The package includes a built-in simulated dataset named `df_cits_example`.

```{r load-data, eval=FALSE}
data("df_cits_example", package = "citsr")
head(df_cits_example)
```

# 2. Fit CITS Model

```{r fit-cits, eval=FALSE}
res <- cits(
  data = df_cits_example,
  y_col = "y",
  T_col = "T",
  I_col = "I",
  E_col = "E"
)

summary(res$model)
```

# 3. Visualize Fitted Values with 95% Confidence Intervals

```{r plot-fitted, eval=FALSE}
plot_fitted <- plot_cits_result(
  res,
  y_col = "y",
  T_col = "T",
  E_col = "E"
)
plot_fitted
```

# 4. Visualize Counterfactual Trajectory for Treatment Group

```{r plot-cf, eval=FALSE}
plot_cf <- plot_cits_result_cf(
  res,
  y_col = "y",
  T_col = "T",
  I_col = "I",
  E_col = "E",
  intervention_time = 50
)
plot_cf
```
