https://github.com/randcorporation/optic
optic: Simulation Tool for Causal Inference Using Longitudinal Data
https://github.com/randcorporation/optic
causal-inference diff-in-diff longitudinal-data simulation
Last synced: 3 months ago
JSON representation
optic: Simulation Tool for Causal Inference Using Longitudinal Data
- Host: GitHub
- URL: https://github.com/randcorporation/optic
- Owner: RANDCorporation
- License: gpl-3.0
- Created: 2023-03-06T17:20:27.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2025-07-25T14:45:38.000Z (6 months ago)
- Last Synced: 2025-10-22T03:48:17.839Z (3 months ago)
- Topics: causal-inference, diff-in-diff, longitudinal-data, simulation
- Language: R
- Homepage: https://randcorporation.github.io/optic/
- Size: 50.6 MB
- Stars: 9
- Watchers: 2
- Forks: 1
- Open Issues: 12
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- License: LICENSE
Awesome Lists containing this project
README
---
output: github_document
bibliography: ./vignettes/optic_refs.json
#csl: https://www.zotero.org/styles/lancet
link-citations: yes
linkcolor: blue
nocite: '@*'
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# optic
**Simulation Tool for Causal Inference Using Longitudinal Data**
[](https://github.com/RANDCorporation/optic/actions)
[](https://github.com/RANDCorporation/optic/actions)
The `optic` R package helps you scrutinize candidate causal inference models using **your own** longitudinal data. Researchers from the Opioid Policy Tools and Information Center (OPTIC) initially created the tool to examine longitudinal data related to opioids, but its framework can be used with longitudinal data on topics other than opioids.
## Background and Rationale
Recent difference-in-differences (DID) literature revealed issues with the traditional DID model, but we found it very difficult to evaluate the relative performance of different causal inference methods using our own data. Thus, we designed a series of simulations [@griffinMovingClassicDifferenceindifferences2021; @griffinMethodologicalConsiderationsEstimating2023] to study the performance of various methods under different scenarios. Our publications to date are as follows:
1. In @griffinMovingClassicDifferenceindifferences2021, we use real-world data on opioid mortality rates to assess commonly used statistical models for DID designs, which are widely used in state policy evaluations. These experiments demonstrated notable limitations of those methods. In contrast, the optimal model we identified—the autoregressive (AR) model—showed a lot of promise. That said, do not just take our word for it; try it out with your own data and see how various approaches perform relative to one another. See the “Usage” section for details.
2. In @griffinMethodologicalConsiderationsEstimating2023, we demonstrate that it is critical to be able to control for effects of co-occurring policies and understand the potential bias that might arise from not controlling for those policies. Our package can help you assess the impact of co-occurring policies on the performance of commonly used statistical models in state policy evaluations.
Assessing those methods in a systematic way might be challenging, but you can now use our `optic` R package to simulate policy effects and compare causal inference models using your own data.
The package supports the traditional two-way fixed effects DID model and the AR model, as well as other leading methods, such as augmented synthetic control and the Callaway-Sant’Anna approach to DID [@ben-michaelAugmentedSyntheticControl2021; @callawayDifferenceinDifferencesMultipleTime2021].
### Why `optic`?
`optic` is named after the **Opioid Policy Tools and Information Center (OPTIC)** project.
## Installation
You will need [R (version 4.1.0 or above)](https://www.r-project.org) to use this package. You can install the `optic` R package from the `R` console:
``` r
# install from CRAN:
install.packages("optic")
# or install the development version from github:
# install remotes if needed
install.packages("remotes")
remotes::install_github("RANDCorporation/optic")
```
## Usage
The [introductory vignette](https://randcorporation.github.io/optic/articles/intro_optic.html) provides a working example using a sample `overdoses` dataset provided with the package. `optic` provides three main functions: `optic_model`, `optic_simulation`, and `dispatch_simulations`. Use `optic_model` to define model specifications for each causal model to be tested in the simulation experiment. Then, pass your models, your data, and your parameters to the `optic_simulation` function, which specifies a set of simulations to be performed for each `optic_model` included in your `list` of models. Finally, use `dispatch_simulations` to run your simulations in parallel.
## Contact
Reach out to [Beth Ann Griffin](https://www.rand.org/about/people/g/griffin_beth_ann.html) for questions related to this repository.
## License
Copyright (C) 2023 by The [RAND Corporation](https://www.rand.org). This repository is released as open-source software under a GPL-3.0 license. See the LICENSE file.
## About this Tool
This research was financially supported through a National Institute on Drug Abuse grant (P50DA046351) to the RAND Corporation and carried out within the Access and Delivery Program in RAND Health Care.
RAND Health Care, a division of the RAND Corporation, promotes healthier societies by improving health care systems in the United States and other countries. We do this by providing health care decisionmakers, practitioners, and consumers with actionable, rigorous, objective evidence to support their most complex decisions. For more information, see [www.rand.org/health-care](https://www.rand.org/health-care), or contact
**RAND Health Care Communications**
1776 Main Street
P.O. Box 2138
Santa Monica, CA 90407-2138
(310) 393-0411, ext. 7775
RAND_Health-Care@rand.org
## References