Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

propensity score calculation in in bootstrap workflow #295

Closed
rpruim opened this issue Nov 22, 2024 · 1 comment · Fixed by #301
Closed

propensity score calculation in in bootstrap workflow #295

rpruim opened this issue Nov 22, 2024 · 1 comment · Fixed by #301

Comments

@rpruim
Copy link

rpruim commented Nov 22, 2024

In https://causal-inference-in-r.netlify.app/chapters/11-outcome-model#the-bootstrap, there is the following example:

fit_ipw <- function(.split, ...) {
  # get bootstrapped data frame
  .df <- as.data.frame(.split)

  # fit propensity score model
  propensity_model <- glm(
    park_extra_magic_morning ~ park_ticket_season + park_close + park_temperature_high,
    data = seven_dwarfs_9,           ### should this be .df?
    family = binomial()
  )

  # calculate inverse probability weights
  .df <- propensity_model |>
    augment(type.predict = "response", data = .df) |>        ### newdata = .df (or omit if using .df above)
    mutate(wts = wt_att(
      .fitted,
      park_extra_magic_morning,
      exposure_type = "binary"
    ))

  # fit correctly bootstrapped ipw model
  lm(
    wait_minutes_posted_avg ~ park_extra_magic_morning,
    data = .df,
    weights = wts
  ) |>
    tidy()
}

Should the propensity scores be recalculated from each bootstrap sample (currently: data = seven_dwarfs_9)? [If it were done as here, it would be better to compute it once rather than once per resample.]

@rpruim
Copy link
Author

rpruim commented Nov 22, 2024

Also

augment(type.predict = "response", data = .df)

Should be newdata = .df.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants