knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
DynamicEffectSim allows researchers to simulate and visualize dynamic causal relationships using univariate ARIMA models. This tool makes it possible to simulate interventions whose effects grow stronger or weaker over time. The benefit of using ARIMA models is that they account for autoregressive processes, moving averages, and seasonality. Future versions of the package will also accommodate multivariate ARIMA models.
DynamicEffectSim has two core functions.
arima_ts_sim
: Simulates a time series with a time-varying intervention. The simulation includes both a treated and control counterfactual states.
dsim_effect_plot
: Plots the time series using ggplot2. The user can specify whether they want to plot the treated time series, the untreated time series, the pointwise effect of the intervention, or the cumulative effect of the intervention.
# install.packages("devtools") library(devtools) devtools::install_github("gl-smith/DynamicEffectSim")
This is a basic example which shows you how to simulate and plot a time series with an intervention that attenuates over time. The results of the simulation are stored as a tibble.
library(tidyverse) library(assertthat) library(DynamicEffectSim) attenuating_effect <- arima_ts_sim( model = list(ar = 0.02), change_type = "attenuation", treat_start = 75, ts_length = 500, intercept = 4, effect = 10, delta = .05 ) glimpse(attenuating_effect)
The dsim_effect_plot
makes it easy to plot the simulated time series. The default option returns a plot of the "treated" time series.
dsim_effect_plot(attenuating_effect)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.