inst/doc/evaluating-synthetic-data.R

## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>", fig.width = 7,
                      fig.height = 4.2, dpi = 72, out.width = "100%")

## -----------------------------------------------------------------------------
library(SynthesizerPlus)
real <- airquality
syn <- synthesize(real, by = "Month", seed = 1)

## -----------------------------------------------------------------------------
cmp <- compare_synthetic(real, syn, seed = 1)
cmp
summary(cmp)

## -----------------------------------------------------------------------------
marginal_metrics(real, syn)[, c("variable", "distance", "wasserstein",
                                "mean_real", "mean_synthetic",
                                "missing_real", "missing_synthetic")]

## ----fig.height = 5-----------------------------------------------------------
plot_marginals(real, syn)
plot_qq(real, syn)

## -----------------------------------------------------------------------------
syn_iris <- synthesize(iris, by = "Species", seed = 1)
plot_categorical(iris, syn_iris)

## ----fig.height = 4-----------------------------------------------------------
plot_association(real, syn, vars = c("Ozone", "Solar.R", "Wind", "Temp"))

## -----------------------------------------------------------------------------
pmse(real, syn, seed = 1)
discriminator_auc(real, syn, seed = 1)

## -----------------------------------------------------------------------------
ci_overlap(real, syn, Ozone ~ Temp + Wind + Solar.R)[, c("term", "estimate_real",
                                                        "estimate_synthetic",
                                                        "std_diff", "overlap")]

## -----------------------------------------------------------------------------
risk <- dcr(real, syn, seed = 1)
risk$quantiles
risk$exact_match_rate
plot_dcr(risk)

## ----eval = FALSE-------------------------------------------------------------
# plot(cmp, type = "marginals")
# plot(cmp, type = "association")
# plot(cmp, type = "pairs")
# plot(cmp, type = "qq")
# plot(cmp, type = "dcr")
# ggplot2::autoplot(cmp, type = "association") + ggplot2::ggtitle("airquality")

Try the SynthesizerPlus package in your browser

Any scripts or data that you put into this service are public.

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