Learn R Programming

tidysynthesis (version 0.1.2)

sample_glm: 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)

Value

A numeric vector of predictions

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

Examples

Run this code

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
)

Run the code above in your browser using DataLab