Skip to content

Commit a9459f9

Browse files
Merge pull request #77 from r-causal/analysis-as-df
`analysis()` -> `as.data.frame()`
2 parents 82a6ffd + 6ff6184 commit a9459f9

6 files changed

+23
-18
lines changed

exercises/01-whole-game-exercises.qmd

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,9 @@ Now let's try the bootstrap. First, we need to wrap our model in a function so w
272272

273273
```{r}
274274
# fit ipw model for a single bootstrap sample
275-
fit_ipw_not_quite_rightly <- function(split, ...) {
276-
# get bootstrapped data sample with `rsample::analysis()`
277-
.df <- analysis(split)
275+
fit_ipw_not_quite_rightly <- function(.split, ...) {
276+
# get bootstrapped data frame
277+
.df <- as.data.frame(.split)
278278
279279
# fit ipw model
280280
lm(wt82_71 ~ qsmk, data = .df, weights = wts) |>
@@ -285,8 +285,9 @@ fit_ipw_not_quite_rightly <- function(split, ...) {
285285
The problem is that we need to account for the *entire* modeling process, so we need to include the first step of our analysis -- fitting the inverse probability weights.
286286

287287
```{r}
288-
fit_ipw <- function(split, ...) {
289-
.df <- analysis(split)
288+
fit_ipw <- function(.split, ...) {
289+
# get bootstrapped data frame
290+
.df <- as.data.frame(.split)
290291
291292
# fit propensity score model
292293
propensity_model <- glm(

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,9 @@ Remember, you need to bootstrap the entire modeling process, including the regre
171171
set.seed(1234)
172172
library(rsample)
173173
174-
fit_gcomp <- function(split, ...) {
175-
.df <- analysis(split)
174+
fit_gcomp <- function(.split, ...) {
175+
# get bootstrapped data frame
176+
.df <- as.data.frame(.split)
176177
177178
# fit outcome model. remember to model using `.df` instead of `wait_times`
178179

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,9 @@ Finish early? Try bootstrapping the G-computation model with censoring weights
102102
Remember, you need to bootstrap the entire modeling process, including fitting both regression models, cloning the data sets, and calculating the effects.
103103

104104
```{r}
105-
fit_gcomp_cens <- function(split, ...) {
106-
.df <- analysis(split)
105+
fit_gcomp_cens <- function(.split, ...) {
106+
# get bootstrapped data frame
107+
.df <- as.data.frame(.split)
107108
108109
# fit the censoring model. remember to model using `.df` instead of `nhefs_censored`
109110

exercises/14-bonus-continuous-pscores-exercises.qmd

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,9 @@ There's nothing new here. Just remember, you need to bootstrap the entire modeli
183183
set.seed(1234)
184184
library(rsample)
185185
186-
fit_model <- function(split, ...) {
187-
.df <- analysis(split)
186+
fit_model <- function(.split, ...) {
187+
# get bootstrapped data frame
188+
.df <- as.data.frame(.split)
188189
189190
# fill in the rest!
190191
}

slides/raw/01-causal_modeling_whole_game.qmd

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -456,9 +456,9 @@ as_tibble(ipw_estimate_robust)
456456

457457
```{r}
458458
# fit ipw model for a single bootstrap sample
459-
fit_ipw_not_quite_rightly <- function(split, ...) {
460-
# get bootstrapped data sample with `rsample::analysis()`
461-
.df <- analysis(split)
459+
fit_ipw_not_quite_rightly <- function(.split, ...) {
460+
# get bootstrapped data frame
461+
.df <- as.data.frame(.split)
462462
463463
# fit ipw model
464464
lm(wt82_71 ~ qsmk, data = .df, weights = wts) |>
@@ -469,8 +469,9 @@ fit_ipw_not_quite_rightly <- function(split, ...) {
469469
## {.small}
470470

471471
```{r}
472-
fit_ipw <- function(split, ...) {
473-
.df <- analysis(split)
472+
fit_ipw <- function(.split, ...) {
473+
# get bootstrapped data frame
474+
.df <- as.data.frame(.split)
474475
475476
# fit propensity score model
476477
propensity_model <- glm(

slides/raw/09-outcome-model.qmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ lm(outcome ~ exposure, data = df, weights = wts) |>
4848

4949
```{r}
5050
#| code-line-numbers: "|1-2|5-13|16-18|21-22"
51-
fit_ipw <- function(split, ...) {
52-
.df <- analysis(split)
51+
fit_ipw <- function(.split, ...) {
52+
.df <- as.data.frame(.split)
5353
5454
# fit propensity score model
5555
propensity_model <- glm(

0 commit comments

Comments
 (0)