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
Copy file name to clipboardExpand all lines: exercises/14-bonus-continuous-pscores-exercises.qmd
+11-11Lines changed: 11 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ library(propensity)
13
13
14
14
For this set of exercises, we'll use propensity scores for continuous exposures.
15
15
16
-
In the touringplans data set, we have information about the posted waiting times for rides. We also have a limited amount of data on the observed, actual times. The question that we will consider is this: Do posted wait times (`avg_spostmin`) for the Seven Dwarves Mine Train at 8 am affect actual wait times (`avg_sactmin`) at 9 am? Here’s our DAG:
16
+
In the touringplans data set, we have information about the posted waiting times for rides. We also have a limited amount of data on the observed, actual times. The question that we will consider is this: Do posted wait times (`wait_minutes_posted_avg`) for the Seven Dwarves Mine Train at 8 am affect actual wait times (`wait_minutes_actual_avg`) at 9 am? Here’s our DAG:
17
17
18
18
```{r}
19
19
#| echo: false
@@ -83,31 +83,31 @@ dagify(
83
83
)
84
84
```
85
85
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.
87
87
88
88
You don't need to update any code here, so just run this.
89
89
90
90
```{r}
91
91
eight <- seven_dwarfs_train_2018 |>
92
-
filter(hour == 8) |>
93
-
select(-avg_sactmin)
92
+
filter(wait_hour == 8) |>
93
+
select(-wait_minutes_actual_avg)
94
94
95
95
nine <- seven_dwarfs_train_2018 |>
96
-
filter(hour == 9) |>
97
-
select(date, avg_sactmin)
96
+
filter(wait_hour == 9) |>
97
+
select(date, wait_minutes_actual_avg)
98
98
99
99
wait_times <- eight |>
100
100
left_join(nine, by = "date") |>
101
-
drop_na(avg_sactmin)
101
+
drop_na(wait_minutes_actual_avg)
102
102
```
103
103
104
104
# Your Turn 1
105
105
106
-
First, let’s calculate the propensity score model, which will be the denominator in our stabilized weights (more to come on that soon). We’ll fit a model using `lm()` for `avg_spostmin` with our covariates, then use the fitted predictions of `avg_spostmin` (`.fitted`, `.sigma`) to calculate the density using `dnorm()`.
106
+
First, let’s calculate the propensity score model, which will be the denominator in our stabilized weights (more to come on that soon). We’ll fit a model using `lm()` for `wait_minutes_posted_avg` with our covariates, then use the fitted predictions of `wait_minutes_posted_avg` (`.fitted`, `.sigma`) to calculate the density using `dnorm()`.
107
107
108
-
1. Fit a model using `lm()` with `avg_spostmin` as the outcome and the confounders identified in the DAG.
108
+
1. Fit a model using `lm()` with `wait_minutes_posted_avg` as the outcome and the confounders identified in the DAG.
109
109
2. Use `augment()` to add model predictions to the data frame.
110
-
3. In `wt_ate()`, calculate the weights using `avg_postmin`, `.fitted`, and `.sigma`.
110
+
3. In `wt_ate()`, calculate the weights using `wait_minutes_posted_avg`, `.fitted`, and `.sigma`.
111
111
112
112
```{r}
113
113
post_time_model <- lm(
@@ -169,7 +169,7 @@ Now, let's fit the outcome model!
169
169
```{r}
170
170
lm(___ ~ ___, weights = ___, data = wait_times_swts) |>
0 commit comments