Skip to content

Commit 304729a

Browse files
tweak flow of diagnostics slides
1 parent 1c91341 commit 304729a

File tree

11 files changed

+385
-182
lines changed

11 files changed

+385
-182
lines changed

slides/raw/08-pscore-diagnostics.html

Lines changed: 269 additions & 138 deletions
Large diffs are not rendered by default.

slides/raw/08-pscore-diagnostics.qmd

Lines changed: 55 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,58 @@ smds <- tidy_smd(
4747
)
4848
```
4949

50+
## Calculating SMDs
51+
52+
```{r}
53+
#| message: false
54+
#| warning: false
55+
#| echo: false
56+
#| eval: true
57+
library(halfmoon)
58+
library(tidyverse)
59+
library(broom)
60+
library(causaldata)
61+
library(propensity)
62+
63+
propensity_model <- glm(
64+
qsmk ~ sex +
65+
race + age + I(age^2) + education +
66+
smokeintensity + I(smokeintensity^2) +
67+
smokeyrs + I(smokeyrs^2) + exercise + active +
68+
wt71 + I(wt71^2),
69+
family = binomial(),
70+
data = nhefs_complete
71+
)
72+
73+
nhefs_complete_wts <- propensity_model |>
74+
augment(type.predict = "response", data = nhefs_complete) |>
75+
mutate(w_ate = wt_ate(.fitted, qsmk))
76+
```
77+
78+
79+
```{r}
80+
#| output-location: slide
81+
#| eval: true
82+
vars <- c(
83+
"sex", "race", "age", "education",
84+
"smokeintensity", "smokeyrs",
85+
"exercise", "active", "wt71"
86+
)
87+
88+
smds <- tidy_smd(
89+
nhefs_complete_wts,
90+
.vars = all_of(vars),
91+
.group = qsmk,
92+
.wts = w_ate,
93+
make_dummy_vars = TRUE
94+
)
95+
96+
smds
97+
```
98+
5099
---
51100

52-
## SMD in R ![](img/hex/halfmoon.png){.absolute top=0 right=0 width=140}
101+
## Plotting SMDs ![](img/hex/halfmoon.png){.absolute top=0 right=0 width=140}
53102

54103
<br />
55104

@@ -76,37 +125,7 @@ ggplot(
76125
#| eval: true
77126
#| message: false
78127
#| warning: false
79-
library(halfmoon)
80-
library(tidyverse)
81-
library(broom)
82-
library(causaldata)
83-
library(propensity)
84-
85-
propensity_model <- glm(
86-
qsmk ~ sex +
87-
race + age + I(age^2) + education +
88-
smokeintensity + I(smokeintensity^2) +
89-
smokeyrs + I(smokeyrs^2) + exercise + active +
90-
wt71 + I(wt71^2),
91-
family = binomial(),
92-
data = nhefs_complete
93-
)
94-
95-
df <- propensity_model |>
96-
augment(type.predict = "response", data = nhefs_complete) |>
97-
mutate(w_ate = wt_ate(.fitted, qsmk))
98-
99-
vars <- c("sex", "race", "age", "education", "smokeintensity", "smokeyrs",
100-
"exercise", "active", "wt71")
101-
102-
plot_df <- tidy_smd(
103-
df,
104-
all_of(vars),
105-
qsmk,
106-
w_ate,
107-
make_dummy_vars = TRUE
108-
)
109-
plot_df |>
128+
smds |>
110129
arrange(method, abs(smd)) |>
111130
mutate(variable = fct_inorder(variable)) |>
112131
ggplot(
@@ -134,7 +153,7 @@ For continuous variables, it can be helpful to look at the _whole_ distribution
134153
#| message: false
135154
#| warning: false
136155
#| eval: true
137-
ggplot(df, aes(x = wt71, color = factor(qsmk))) +
156+
ggplot(nhefs_complete_wts, aes(x = wt71, color = factor(qsmk))) +
138157
geom_ecdf() +
139158
scale_color_manual("Quit smoking", values = c("#5154B8", "#5DB854"),
140159
labels = c("Yes", "No")) +
@@ -148,7 +167,7 @@ ggplot(df, aes(x = wt71, color = factor(qsmk))) +
148167
#| code-line-numbers: "|1|2"
149168
#| eval: true
150169
#| output-location: slide
151-
ggplot(df, aes(x = wt71, color = factor(qsmk))) +
170+
ggplot(nhefs_complete_wts, aes(x = wt71, color = factor(qsmk))) +
152171
geom_ecdf() +
153172
scale_color_manual(
154173
"Quit smoking",
@@ -166,7 +185,7 @@ ggplot(df, aes(x = wt71, color = factor(qsmk))) +
166185
#| eval: true
167186
#| code-line-numbers: "|2"
168187
#| output-location: slide
169-
ggplot(df, aes(x = wt71, color = factor(qsmk))) +
188+
ggplot(nhefs_complete_wts, aes(x = wt71, color = factor(qsmk))) +
170189
geom_ecdf(aes(weights = w_ate)) +
171190
scale_color_manual(
172191
"Quit smoking",
@@ -228,7 +247,7 @@ library(gtsummary)
228247
229248
svy_des <- svydesign(
230249
ids = ~ 1,
231-
data = df |> select(wt71, race, age, sex, smokeintensity, smokeyrs, exercise, active, w_ate, qsmk),
250+
data = nhefs_complete_wts |> select(wt71, race, age, sex, smokeintensity, smokeyrs, exercise, active, w_ate, qsmk),
232251
weights = ~ w_ate
233252
)
234253
theme_gtsummary_compact()
174 KB
Loading
88.4 KB
Loading
-3.23 KB
Loading
170 KB
Loading
174 KB
Loading

slides/raw/08-pscore-diagnostics_files/libs/quarto-html/quarto-syntax-highlighting.css

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

slides/raw/08-pscore-diagnostics_files/libs/revealjs/dist/theme/quarto.css

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

slides/raw/08-pscore-diagnostics_files/libs/revealjs/plugin/quarto-line-highlight/line-highlight.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ window.QuartoLineHighlight = function () {
3838
divSourceCode.forEach((el) => {
3939
if (el.hasAttribute(kCodeLineNumbersAttr)) {
4040
const codeLineAttr = el.getAttribute(kCodeLineNumbersAttr);
41-
el.removeAttribute("data-code-line-numbers");
41+
el.removeAttribute(kCodeLineNumbersAttr);
4242
if (handleLinesSelector(deck, codeLineAttr)) {
4343
// Only process if attr is a string to select lines to highlights
4444
// e.g "1|3,6|8-11"
@@ -165,17 +165,17 @@ window.QuartoLineHighlight = function () {
165165
if (typeof highlight.last === "number") {
166166
spanToHighlight = [].slice.call(
167167
codeBlock.querySelectorAll(
168-
":scope > span:nth-child(n+" +
168+
":scope > span:nth-of-type(n+" +
169169
highlight.first +
170-
"):nth-child(-n+" +
170+
"):nth-of-type(-n+" +
171171
highlight.last +
172172
")"
173173
)
174174
);
175175
} else if (typeof highlight.first === "number") {
176176
spanToHighlight = [].slice.call(
177177
codeBlock.querySelectorAll(
178-
":scope > span:nth-child(" + highlight.first + ")"
178+
":scope > span:nth-of-type(" + highlight.first + ")"
179179
)
180180
);
181181
}

0 commit comments

Comments
 (0)