sample_ranger: Sample the conditional distribution created by a ranger rf...

View source: R/sample_ranger.R

sample_rangerR Documentation

Sample the conditional distribution created by a ranger rf model

Description

Sample the conditional distribution created by a ranger rf model

Usage

sample_ranger(model, new_data, conf_data)

Arguments

model

A "model_fit" object created by parsnip::ranger()

new_data

A data frame with predictors

conf_data

A data frame with original confidential predictors

Value

A numeric vector of predictions

Examples


rf_mod_regression <- parsnip::rand_forest(trees = 500, min_n = 1) |>
  parsnip::set_engine(engine = "ranger") |>
  parsnip::set_mode(mode = "regression") |>
  parsnip::set_args(quantreg = TRUE)

regression_rec <- recipes::recipe(age ~ ., data = acs_conf)

model_reg <- workflows::workflow() |>
  workflows::add_model(spec = rf_mod_regression) |>
  workflows::add_recipe(recipe = regression_rec) |>
  parsnip::fit(data = acs_conf)

set.seed(1)
sample1 <- sample_ranger(
  model = model_reg, 
  new_data = acs_conf[1:3, ], 
  conf_data = acs_conf
)


tidysynthesis documentation built on March 17, 2026, 1:06 a.m.