Skip to content

Commit d1edc41

Browse files
Merge pull request #62 from r-causal/qa-clean-up
2 parents cf90fd9 + c7a0385 commit d1edc41

13 files changed

+27
-63
lines changed

exercises/01-whole-game-exercises.qmd

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ smk_wt_dag <- dagify(
9090
# specify causal question:
9191
exposure = "qsmk",
9292
outcome = "wt82_71",
93+
coords = time_ordered_coords(),
9394
# set up labels:
9495
# here, I'll use the same variable names as the data set, but I'll label them
9596
# with clearer names
@@ -113,7 +114,8 @@ smk_wt_dag <- dagify(
113114
"smokeintensity" = "smoking\nintensity",
114115
"smokeyrs" = "yrs of\nsmoking"
115116
)
116-
) |>tidy_dagitty(layout = "star")
117+
) |>
118+
tidy_dagitty()
117119
118120
smk_wt_dag
119121
```
@@ -313,9 +315,13 @@ fit_ipw <- function(split, ...) {
313315
# calculate inverse probability weights
314316
.df <- propensity_model |>
315317
augment(type.predict = "response", data = .df) |>
316-
mutate(wts = wt_ate(.fitted, qsmk))
318+
mutate(wts = wt_ate(
319+
.fitted,
320+
qsmk,
321+
exposure_type = "binary"
322+
))
317323
318-
# fit correctly bootsrapped ipw model
324+
# fit correctly bootstrapped ipw model
319325
lm(wt82_71 ~ qsmk, data = .df, weights = wts) |>
320326
tidy()
321327
}

exercises/03-ci-with-group-by-and-summarise-exercises.qmd

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ sim2 |>
7777
names_prefix = "x_") |>
7878
summarise(estimate = x_1 - x_0, .groups = "drop") |>
7979
summarise(estimate = mean(estimate))
80-
8180
```
8281

8382
## Your Turn 3
@@ -108,8 +107,8 @@ sim3 |>
108107
values_from = avg_y,
109108
names_prefix = "x_"
110109
) |>
111-
summarise(estimate = x_1 - x_0)
112-
110+
summarise(estimate = x_1 - x_0) |>
111+
summarise(estimate = mean(estimate))
113112
```
114113

115114
# Take aways

exercises/04-dags-exercises.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ coffee_cancer_dag_to <- dagify(
103103
)
104104
)
105105
106-
_____(_____, use_labels = TRUE, use_text = FALSE)
106+
_____(_____, use_labels = "label", text = FALSE)
107107
```
108108

109109
# Take aways

exercises/05-quartets-exercises.qmd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,7 @@ For each of the following 4 datasets, fit a linear linear model examining the re
4343
* `causal_mediator_time`
4444
* `causal_m_bias_time`
4545

46+
```{r}
47+
48+
```
49+

exercises/07-pscores-using-exercises.qmd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ We are interested in examining the relationship between whether there were "Extr
1717
Below is the propensity score model you created in the previous exercise.
1818

1919
```{r}
20-
#| eval: false
2120
seven_dwarfs <- seven_dwarfs_train_2018 |>
2221
filter(hour == 9)
2322

exercises/08-pscores-diagnostics-exercises.qmd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ We are interested in examining the relationship between whether there were "Extr
1818
Below is the propensity score model and weights you created in the previous exercise.
1919

2020
```{r}
21-
#| eval: false
2221
seven_dwarfs <- seven_dwarfs_train_2018 |>
2322
filter(hour == 9)
2423

exercises/09-outcome-model-exercises.qmd

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ library(tidyverse)
1010
library(broom)
1111
library(touringplans)
1212
library(rsample)
13+
library(propensity)
1314
1415
seven_dwarfs <- seven_dwarfs_train_2018 |>
1516
filter(hour == 9)
@@ -56,9 +57,9 @@ ipw_results |>
5657
mutate(
5758
estimate = map_dbl(
5859
boot_fits,
59-
# pull the `estimate` for `qsmk` for each fit
60+
# pull the `estimate` for `extra_magic_morning` for each fit
6061
\(.fit) .fit |>
61-
filter(term == "qsmk") |>
62+
filter(term == "extra_magic_morning") |>
6263
pull(estimate)
6364
)
6465
) |>
@@ -73,6 +74,8 @@ Calculate the confidence interval
7374
#| eval: false
7475
boot_estimate <- ____(____, ____) |>
7576
filter(term == ____)
77+
78+
boot_estimate
7679
```
7780

7881

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ fit_gcomp <- function(split, ...) {
184184
185185
186186
# calculate ATE
187-
bind_cols(predicted_yes, predicted_no) |>
187+
bind_cols(predicted_thirty, predicted_sixty) |>
188188
summarize(
189189
mean_thirty = mean(thirty_posted_minutes),
190190
mean_sixty = mean(sixty_posted_minutes),

exercises/11-tipr-exercises.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ We are interested in examining the relationship between whether there were "Extr
1212

1313
## Your turn
1414

15-
Use the `tip_coef()` function to conduct a sensitivity analysis for the estimate from your previous exercises.
15+
Use the `tip_coef()` function to conduct a sensitivity analysis for the estimate from your previous exercises. Use the lower bound of the confidence interval for the effect and `0.1` for the exposure-confounder effect.
1616

1717
```{r}
1818

exercises/13-bonus-selection-bias-exercises.qmd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ library(tidyverse)
99
library(broom)
1010
library(propensity)
1111
library(causaldata)
12+
library(rsample)
1213
```
1314

1415
In this example, we'll consider loss to follow-up in the NHEFS study. We'll use the binary exposure we used earlier in the workshop: does quitting smoking (`smk`) increase weight (`wt82_71`)? This time, however, we'll adjust for loss to followup (people who dropped out of the study between observation periods) using inverse probability of censoring weights.

0 commit comments

Comments
 (0)