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
Let's fit a model with these variables. Note that we'll fit all continuous variables with squared terms, as well, to allow them a bit of flexibility.
@@ -214,11 +213,9 @@ plot_df <- tidy_smd(
214
213
215
214
ggplot(
216
215
data = plot_df,
217
-
mapping = aes(x = abs(smd), y = variable, group = weights, color = weights)
216
+
mapping = aes(x = abs(smd), y = variable, group = method, color = method)
218
217
) +
219
-
geom_line(orientation = "y") +
220
-
geom_point() +
221
-
geom_vline(xintercept = 0.1, color = "black", size = 0.1)
218
+
geom_love()
222
219
```
223
220
224
221
These look pretty good! Some variables are better than others, but weighting appears to have done a much better job eliminating these differences than an unadjusted analysis.
@@ -269,10 +266,10 @@ But we have other problem that we need to address. While we're just using `lm()`
269
266
```{r}
270
267
# also see robustbase, survey, gee, and others
271
268
library(estimatr)
272
-
ipw_model_robust <- lm_robust( #<<
273
-
wt82_71 ~ qsmk, #<<
269
+
ipw_model_robust <- lm_robust(
270
+
wt82_71 ~ qsmk,
274
271
data = nhefs_complete_uc,
275
-
weights = wts #<<
272
+
weights = wts
276
273
)
277
274
278
275
ipw_estimate_robust <- ipw_model_robust |>
@@ -373,4 +370,3 @@ So, we have a final estimate for our causal effect: on average, a person who qui
373
370
# Take aways
374
371
* The broad strokes for a causal analysis are: 1) identify your causal question 2) make your assumptions clear 3) check your assumptions as best you can and 4) use the right estimator for the question you're trying to ask. As scientists, we should be able to critique each of these steps, and that's a good thing!
375
372
* To create marginal structural models, first fit a propensity model for the weights with the exposure as the outcome. Then, use the inverse of the predicted probabilities as weights in a model with just the outcome and exposure.
376
-
* See more at https://causalinferencebookr.netlify.com
0 commit comments