Skip to content

Commit f93e92e

Browse files
update exercises
1 parent 00c79fe commit f93e92e

File tree

2 files changed

+29
-38
lines changed

2 files changed

+29
-38
lines changed

exercises/01-whole-game-exercises.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ The main goal here is to *break* the non-causal associations between quitting sm
192192

193193
Standardized mean differences (SMD) are a simple measurement of differences that work across variable types. In general, the closer to 0 we are, the better job we have done eliminating the non-causal relationships we drew in our DAG. Note that low SMDs for everything we adjust for does *not* mean that there is not something else that might confound our study. Unmeasured confounders or misspecified DAGs can still distort our effects, even if our SMDs look great!
194194

195-
We'll use the {smd}t package to calculate the SMDs, then visualize them.
195+
We'll use the {smd} package to calculate the SMDs, then visualize them.
196196

197197
```{r}
198198
vars <- c("sex", "race", "age", "education", "smokeintensity", "smokeyrs",

exercises/05-pscores-diagnostics-exercises.Rmd

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -31,55 +31,46 @@ df <- propensity_model %>%
3131

3232
_After updating the code chunks below, change `eval = TRUE` before knitting._
3333

34-
Create the survey design object to incorporate the weights.
34+
Calculate the standardized mean differences with and without weights
3535

3636
```{r, eval = FALSE}
37-
svy_des <- ____(
38-
ids = ~ 1,
39-
data = ___,
40-
weights = ___
41-
)
42-
```
43-
44-
Create the **unweighted** standardized mean differences data frame
45-
46-
```{r, eval = FALSE}
47-
smd_table_unweighted <- ____(
48-
vars = _____,
49-
strata = _____,
50-
data = ____,
51-
test = FALSE)
37+
smds <- df %>%
38+
summarise(
39+
across(
40+
# variables to calculate SMD for
41+
________,
42+
list(
43+
unweighted = ~_____(.x, qsmk)$estimate,
44+
weighted = ~_____(.x, qsmk, w = ___)$estimate
45+
)
46+
)
47+
5248
```
5349

54-
Create the **weighted** standardized mean differences data frame
50+
Pivot `smds` so that it is in tidy format with the columns "SMD", "variable", and "Method".
5551

5652
```{r, eval = FALSE}
57-
smd_table <- ____(
58-
vars = _____,
59-
strata = _____,
60-
data = ____,
61-
test = FALSE)
62-
```
63-
64-
Create a data frame that merges `smd_table_unweighted` and `smd_table` and pivots it to prepare for plotting
65-
66-
```{r, eval = FALSE}
67-
plot_df <- data.frame(
68-
var = rownames(____),
69-
Unadjusted = _____,
70-
Weighted = _____) %>%
71-
pivot_longer(-var, names_to = "Method", values_to = "SMD")
53+
plot_df <- smds %>%
54+
pivot_longer(
55+
_______,
56+
values_to = "___",
57+
names_to = c("___", "___"),
58+
59+
# don't change this one. We really mean _!
60+
names_sep = "_"
61+
)
7262
```
7363

7464
Create the Love Plot using ggplot
7565

7666
```{r, eval = FALSE}
77-
ggplot(data = _____,
78-
mapping = aes(x = ____, y = ____, group = ____, color = ____)) +
79-
geom_line() +
67+
ggplot(
68+
data = ____,
69+
aes(x = abs(____), y = ____, group = ____, color = ____)
70+
) +
71+
geom_line(orientation = "y") +
8072
geom_point() +
81-
geom_hline(yintercept = 0.1, color = "black", size = 0.1) +
82-
coord_flip()
73+
geom_vline(xintercept = 0.1, color = "black", size = 0.1)
8374
```
8475

8576

0 commit comments

Comments
 (0)