Learn R Programming

rsdv (version 0.2.0)

sample_conditions: Sample synthetic rows that match fixed column values (conditional sampling)

Description

Generates rows in which one or more categorical or boolean columns are held to specified values, via rejection sampling against the fitted copula. This preserves the modeled dependence between the conditioned columns and the rest of the table (unlike overwriting values after the fact).

Usage

sample_conditions(x, conditions, max_tries = 100L)

Value

A data frame of synthetic rows satisfying the conditions.

Arguments

x

A fitted gaussian_copula_synthesizer.

conditions

A data frame whose columns are the variables to fix. Each row is one condition; an optional integer column .n gives how many rows to generate for that condition (default 1 per row).

max_tries

Maximum rejection-sampling rounds per condition.

Examples

Run this code
# \donttest{
meta <- metadata(adult_income)
syn  <- gaussian_copula_synthesizer(meta) |> fit(adult_income)
sample_conditions(syn, data.frame(income = ">50K", .n = 20))
# }

Run the code above in your browser using DataLab