compare_tables: Compare original and synthetic tables column by column

View source: R/compare.r

compare_tablesR Documentation

Compare original and synthetic tables column by column

Description

For every modelled column: missing fraction in both; for numeric and date columns the mean, SD and median and the Kolmogorov-Smirnov distance; for categorical columns the total variation distance between label distributions. self_match is the share of subject cells equal to the same row's original cell; for categorical columns chance_match gives what a random redraw from the marginal would produce, so a large excess points at a column that copies its own row.

Usage

compare_tables(orig, syn, spec, rows = seq_len(nrow(orig)))

Arguments

orig, syn

Raw character data.frames in the same layout.

spec

The shared spec.

rows

Rows to compare (default: all).

Value

A data.frame, one row per modelled column.

Examples

df <- data.frame(id = sprintf("AB%03d", 1:60), value = 1:60,
                 code = rep(c(0, 1, NA), 20), group = rep(c("A", "B"), 30))
path <- file.path(tempdir(), "compare_tables.csv")
utils::write.csv(df, path, row.names = FALSE, na = "")
src <- read_source(path)
spec <- infer_spec(src)
syn <- src$raw
syn$value <- rev(syn$value)
compare_tables(src$raw, syn, spec)

cellsynth documentation built on Oct. 31, 2026, 1:07 a.m.