Learn R Programming

tidysynthesis (version 0.1.2)

sample_lm: Sample the conditional distribution created by a linear model

Description

Sample the conditional distribution created by a linear model

Usage

sample_lm(model, new_data, conf_data)

Value

A numeric vector of predictions

Arguments

model

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

new_data

A data frame with predictors

conf_data

A data frame with original confidential predictors

Examples

Run this code

lm_mod <- parsnip::linear_reg() |>
  parsnip::set_engine("lm") |>
  parsnip::set_mode(mode = "regression")

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

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

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

Run the code above in your browser using DataLab