Monitoring and Surveillance of Behavioral Health in the Context of Public Health Emergencies
A Toolkit for Public Health Officials
Contents
H: Sample Code to Conduct Suggested Analyses
R—Building and Plotting a Basic ARIMA Model
This code (Summary 1) uses an automated function to fit an ARIMA model to data. It then plots the ARIMA model predictions against the observed values. It assumes two inputs: a signal vector, called signal_raw, and a corresponding vector of dates, called dates.
Here is a preview of the data frame used to generate this plot:
arima_df
|date | observed| residual| prediction|
|:----------|--------:|--------:|----------:|
|2019-06-20 | 0.031| 0.000| 0.031|
|2019-06-21 | 0.032| 0.001| 0.031|
|2019-06-22 | 0.030| -0.001| 0.032|
|2019-06-23 | 0.032| 0.001| 0.031|
|2019-06-24 | 0.031| -0.001| 0.032|
|2019-06-25 | 0.028| -0.003| 0.031|
R—Building and Plotting a Basic Change-Point Analysis
This code (Summary 2) fits and plots a CPA. First, it plots a graph to help choose the appropriate penalty for the CPA algorithm; then, it fits a model and plots this CPA output against the observed values. The code assumes two inputs: a signal vector, called signal_raw, and a corresponding vector of dates, called dates.
Summary 2 Output of Sample Code for a Change-Point Analysis
Here is a preview of the data frame used to generate this plot:
cpt_df
|date | observed| ts_cp|
|:----------|--------:|-----:|
|2019-06-20 | 0.031| 0.03|
|2019-06-21 | 0.032| 0.03|
|2019-06-22 | 0.030| 0.03|
|2019-06-23 | 0.032| 0.03|
|2019-06-24 | 0.031| 0.03|
|2019-06-25 | 0.028| 0.03|
Stata—Building and Plotting a Simple Interrupted Time Series Analysis
This code fits and plots a simple ITSA. First, it formats the data as time-series data. Next, it fits a model to estimate the effect of an intervention (or series of interventions) on an outcome that is variable-ordered as a time series, with observations in both the pre- and post-intervention periods. Finally, the code plots the model-fitted values, along with the actual values of the outcome variable over time.
In the code, we format the data as a time series, where the time variable is date.
\* Format as time series \*
tsset date
Next, we estimate a simple ITSA with a single treatment date—March 11, 2020 (trperiod(11mar2020))—to test whether the declaration of the COVID-19 pandemic is associated with a significant change in level or trend of total 2-1-1 calls (calls_total) in a specific county. To control for day-of-the-week seasonality, we include day-of-the-week dummies (dow2 dow3 dow4 dow5 dow6 dow7). We do not have a comparison series (i.e., calls in a different county), so we estimate the model for a single treatment group. Because autocorrelation is present for the seven preceding periods (days), we account for autocorrelation using lag(7); posttrend produces post-treatment trend estimates; and fig produces a line plot of the predicted outcome variable combined with a scatterplot of the actual values of the outcome variable over time.
\* ITSA \*
itsa calls_total dow2 dow3 dow4 dow5 dow6 dow7 if covid==1, single trperiod(11mar2020) lag(7) fig posttrend
The plot output from this code, shown in Summary 3, can be further formatted as needed.
Summary 3 Output of Sample Code for ITSA