You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First, let's visualize the data to see the intervention's effect. We can clearly see both the immediate jump at day 200 and the change in trend afterward.
94
+
95
+
```{r}
96
+
library(ggplot2)
97
+
library(see)
98
+
99
+
# Visualize the simulated data
100
+
ggplot(dat, aes(x = time, y = outcome, colour = event, group = event)) +
101
+
geom_point(alpha = 0.5) +
102
+
geom_smooth(method = "lm") +
103
+
labs(title = "Interrupted Time Series Analysis", x = "Time (Days)", y = "Outcome") +
104
+
theme_modern(show.ticks = TRUE) +
105
+
scale_color_flat()
89
106
```
90
107
91
108
# Modeling the Time Series
@@ -106,13 +123,13 @@ With our model fitted, we can now use `modelbased` to quantify and test the inte
106
123
107
124
## 1. The Interruption: Level Change
108
125
109
-
First, let's examine what the model estimates for the outcome right before and right after the intervention at `time = 200`. We can use `estimate_means()` to get the predicted values at `time = 199` and `time = 200` for both the factual (`event = 1`) and counterfactual (`event = 0`) scenarios.
126
+
First, let's examine what the model estimates for the outcome right before and right after the intervention at `time = 200`. We can use `estimate_means()` to get the predicted values at `time = 199` and `time = 200` for both the factual (`event = Post-Event`) and counterfactual (`event = Pre-Event`) scenarios.
110
127
111
128
```{r}
112
129
estimate_means(mod, by = c("time=c(199,200)", "event"))
113
130
```
114
131
115
-
To directly test if the immediate "jump" or "level change" at the moment of the intervention is statistically significant, we can use `estimate_contrasts()`. We ask for the difference between `event = 1` and `event = 0` specifically at `time = 200`.
132
+
To directly test if the immediate "jump" or "level change" at the moment of the intervention is statistically significant, we can use `estimate_contrasts()`. We ask for the difference between `event = Post-Event` and `event = Pre-Event` specifically at `time = 200`.
116
133
117
134
```{r}
118
135
estimate_contrasts(mod, contrast = "event", by = "time=200")
@@ -122,7 +139,7 @@ The output shows a large, statistically significant difference of about 1020. Th
122
139
123
140
## 2. The Change in Trend: Slope Change
124
141
125
-
Next, we want to know if the intervention changed the long-term trend of the outcome. We can use `estimate_slopes()` to compute the slope of `time` for the pre-intervention period (`event = 0`) and the post-intervention period (`event = 1`).
142
+
Next, we want to know if the intervention changed the long-term trend of the outcome. We can use `estimate_slopes()` to compute the slope of `time` for the pre-intervention period (`event = Pre-Event`) and the post-intervention period (`event = Post-Event`).
126
143
127
144
```{r}
128
145
estimate_slopes(mod, trend = "time", by = "event")
0 commit comments