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
For the resampled fit, we definitely need a helper that bridges the two calls to fit_resamples() by mutating propensity weights onto the assessment set underlying the rsplit. In this example, I call it weight_propensity():
The helper (sans error checking) could look something like:
EDIT: Out of date, see linked PR
# a function that takes in a resample fit object and outputs a modified# version of that object where the training data underlying each rsplit# is augmented with propensity weights for each element of the analysis set. # this serves as the "bridge" between two calls to# `fit_resamples()` (or `tune_*()`) in a causal workflow, the# first being for the propensity model and the second for the outcome model.# `tune_results` must have been executed with option `extract = identity`.weight_propensity<-function(tune_results, wt_fn) {
for (resamplein seq_along(tune_results$splits)) {
tune_results$splits[[resample]] <-
augment_split(
tune_results$splits[[resample]],
tune_results$.extracts[[resample]]$.extracts[[1]],
wt_fn=wt_fn,
outcome_name= outcome_names(tune_results)
)
}
tibble::new_tibble(
tune_results[, c("splits", "id")],
!!!attr(tune_results, "rset_info")$att,
class= c(attr(tune_results, "rset_info")$att$class, "rset")
)
}
augment_split<-function(split, workflow, wt_fn, outcome_name) {
d<- analysis(split)
d<-vctrs::vec_cbind(d, predict(workflow, d, type="prob"))
d<-vctrs::vec_slice(d, !duplicated(d$id))
model_fit<- extract_fit_parsnip(workflow)
lvls<-model_fit$lvlevent_lvl<-lvls[1]
preds<-d[[paste0(".pred_", event_lvl)]]
split[["data"]][d$id, "wts"] <-
importance_weights(wt_fn(preds, d[[outcome_name]], .treated=event_lvl))
split
}
Questions:
What’s a good name for weight_propensity()? Is there something more compatible with the analogous(?) procedure in survival analysis?
Do we want that function to be able to be used in both the single-fit and resampled-fit setting to aid with that parallelism? We could make a method that takes in data, a weighting function, and a model fit to make the single-fit setting feel more like the resampled-fit setting, a la:
fit()
ting a single model vs resampling a model fit viafit_resamples()
has a nice parallelism to it with the usual single-model approach:Ideally, the two-stage approach in causal inference could have the same ring to it.
Defining workflows:
Note that there’s an
add_case_weights()
step foroutcome_wf()
that can’t happen untilpropensity_wf()
can generate predictions.With no changes made to tidymodels, the code for a fit to one dataset looks like something like:
For the resampled fit, we definitely need a helper that bridges the two calls to
fit_resamples()
by mutating propensity weights onto the assessment set underlying the rsplit. In this example, I call itweight_propensity()
:The helper (sans error checking) could look something like:
EDIT: Out of date, see linked PR
Questions:
What’s a good name for
weight_propensity()
? Is there something more compatible with the analogous(?) procedure in survival analysis?Do we want that function to be able to be used in both the single-fit and resampled-fit setting to aid with that parallelism? We could make a method that takes in data, a weighting function, and a model fit to make the single-fit setting feel more like the resampled-fit setting, a la:
I'd propose we do include that parsnip/workflows counterpart. That helper (and probably the generic?) ought to live in parsnip/workflows, if so.
The text was updated successfully, but these errors were encountered: