Skip to content

Commit d7893b8

Browse files
committed
fix ex 10
1 parent 5cb66a2 commit d7893b8

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

exercises/10-continuous-g-computation-exercises.qmd

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,29 +83,29 @@ dagify(
8383
)
8484
```
8585

86-
First, let’s wrangle our data to address our question: do posted wait times at 8 affect actual weight times at 9? We’ll join the baseline data (all covariates and posted wait time at 8) with the outcome (average actual time). We also have a lot of missingness for `avg_sactmin`, so we’ll drop unobserved values for now.
86+
First, let’s wrangle our data to address our question: do posted wait times at 8 affect actual weight times at 9? We’ll join the baseline data (all covariates and posted wait time at 8) with the outcome (average actual time). We also have a lot of missingness for `wait_minutes_actual_avg`, so we’ll drop unobserved values for now.
8787

8888
You don't need to update any code here, so just run this.
8989

9090
```{r}
9191
eight <- seven_dwarfs_train_2018 |>
9292
filter(hour == 8) |>
93-
select(-avg_sactmin)
93+
select(-wait_minutes_actual_avg)
9494
9595
nine <- seven_dwarfs_train_2018 |>
9696
filter(hour == 9) |>
97-
select(date, avg_sactmin)
97+
select(date, wait_minutes_actual_avg)
9898
9999
wait_times <- eight |>
100100
left_join(nine, by = "date") |>
101-
drop_na(avg_sactmin)
101+
drop_na(wait_minutes_actual_avg)
102102
```
103103

104104
# Your Turn 1
105105

106-
For the parametric G-formula, we'll use a single model to fit a causal model of Posted Waiting Times (`avg_spostmin`) on Actual Waiting Times (`avg_sactmin`) where we include all covariates, much as we normally fit regression models. However, instead of interpreting the coefficients, we'll calculate the estimate by predicting on cloned data sets.
106+
For the parametric G-formula, we'll use a single model to fit a causal model of Posted Waiting Times (`wait_minutes_posted_avg`) on Actual Waiting Times (`wait_minutes_actual_avg`) where we include all covariates, much as we normally fit regression models. However, instead of interpreting the coefficients, we'll calculate the estimate by predicting on cloned data sets.
107107

108-
Two additional differences in our model: we'll use a natural cubic spline on the exposure, `avg_spostmin`, using `ns()` from the splines package, and we'll include an interaction term between `avg_spostmin` and `extra_magic_mornin g`. These complicate the interpretation of the coefficient of the model in normal regression but have virtually no downside (as long as we have a reasonable sample size) in g-computation, because we still get an easily interpretable result.
108+
Two additional differences in our model: we'll use a natural cubic spline on the exposure, `wait_minutes_posted_avg`, using `ns()` from the splines package, and we'll include an interaction term between `wait_minutes_posted_avg` and `park_extra_magic_morning`. These complicate the interpretation of the coefficient of the model in normal regression but have virtually no downside (as long as we have a reasonable sample size) in g-computation, because we still get an easily interpretable result.
109109

110110
First, let's fit the model.
111111

@@ -114,14 +114,14 @@ First, let's fit the model.
114114

115115
```{r}
116116
_______ ___ _______(
117-
avg_sactmin ~ ns(_______, df = 5)*extra_magic_morning + _______ + _______ + _______,
117+
wait_minutes_actual_avg ~ ns(_______, df = 5)*park_extra_magic_morning + _______ + _______ + _______,
118118
data = seven_dwarfs
119119
)
120120
```
121121

122122
# Your Turn 2
123123

124-
Now that we've fit a model, we need to clone our data set. To do this, we'll simply mutate it so that in one set, all participants have `avg_spostmin` set to 30 minutes and in another, all participants have `avg_spostmin` set to 60 minutes.
124+
Now that we've fit a model, we need to clone our data set. To do this, we'll simply mutate it so that in one set, all participants have `wait_minutes_posted_avg` set to 30 minutes and in another, all participants have `wait_minutes_posted_avg` set to 60 minutes.
125125

126126
1. Create the cloned data sets, called `thirty` and `sixty`.
127127
2. For both data sets, use `standardized_model` and `augment()` to get the predicted values. Use the `newdata` argument in `augment()` with the relevant cloned data set. Then, select only the fitted value. Rename `.fitted` to either `thirty_posted_minutes` or `sixty_posted_minutes` (use the pattern `select(new_name = old_name)`).

0 commit comments

Comments
 (0)