sample_glm: Sample the conditional distribution created by a generalized...

View source: R/sample_glm.R

sample_glmR Documentation

Sample the conditional distribution created by a generalized linear model

Description

Currently, logistic and poisson regression are supported using parsnip and the standard glm engine. Note that poisson regression requires the suggested poissonreg library.

Usage

sample_glm(model, new_data, conf_data)

Arguments

model

A "model_fit" object created by parsnip

new_data

A data frame with predictors

conf_data

A data frame with original confidential predictors

Value

A numeric vector of predictions

Examples


acs_conf <- acs_conf |>
  tidyr::drop_na()

logistic_mod <- parsnip::logistic_reg() |>
  parsnip::set_engine("glm") |>
  parsnip::set_mode(mode = "classification")

classification_rec <- recipes::recipe(hcovany ~ ., data = acs_conf)

model_class <- workflows::workflow() |>
  workflows::add_model(spec = logistic_mod) |>
  workflows::add_recipe(recipe = classification_rec) |>
  parsnip::fit(data = acs_conf)

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


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