generate: Generate synthetic data from a fitted model

View source: R/synthesizer.R

generateR Documentation

Generate synthetic data from a fitted model

Description

generate() draws synthetic records from a fitted model such as an sp_synthesizer (see fit_synthesizer()) or an sp_ts_synthesizer (see fit_synthesizer.ts()).

Usage

generate(object, ...)

## S3 method for class 'sp_synthesizer'
generate(
  object,
  n = object$n_train,
  seed = NULL,
  dependence = 1,
  closeness = 1,
  perturb = NULL,
  stratum_sizes = c("multinomial", "proportional"),
  ...
)

## S3 method for class 'sp_ts_synthesizer'
generate(object, n = object$n_train, seed = NULL, start = object$start, ...)

Arguments

object

A fitted model.

...

Further arguments passed to methods.

n

Number of records (rows) to generate. Defaults to the number of rows in the training data.

seed

Optional random seed. The global random number generator state is restored afterwards.

dependence

Number in [0, 1] scaling the strength of the dependence between variables: 1 (default) reproduces the fitted copula, 0 generates independent columns. Intermediate values shrink the copula correlation matrix towards the identity; the marginal distributions are unaffected.

closeness

Number in [0, 1] controlling how close the synthetic data are to the real data: 1 (default) reproduces the fitted model as closely as possible; smaller values move records away from the real ones (noise on continuous variables, random re-drawing of categories) and loosen the distributions (flatter category probabilities, weaker dependence). With closeness = 0 the variables are independent and strongly smoothed. See perturbation() for the exact mapping and calibrate_closeness() to choose a value that reaches a target distance.

perturb

Optional perturbation() for fine control: record-level noise and swapping, and distribution-level shifts, spread, category temperature and dependence strength. Combined with closeness and dependence.

stratum_sizes

For stratified models: "multinomial" (default; random stratum sizes) or "proportional" (deterministic sizes proportional to the training data).

start

Start time of the generated series (default: the start of the training series).

Value

Synthetic data of the same type as the training data: a data frame, matrix, vector or ts object.

See Also

fit_synthesizer(), synthesize(), generate_to_file()

Examples

fit <- fit_synthesizer(mtcars)
generate(fit, n = 5, seed = 42)

# weaker dependence
syn <- generate(fit, n = 500, dependence = 0.5, seed = 1)

SynthesizerPlus documentation built on Oct. 16, 2026, 5:10 p.m.