jsd_summary: JSD summary: point estimate and optional bootstrap per group

View source: R/jsd_summary.R

jsd_summaryR Documentation

JSD summary: point estimate and optional bootstrap per group

Description

Convenience wrapper that returns both the point-estimate JSD and, optionally, bootstrap-based uncertainty (mean, SD, and CI) for each group.

Usage

jsd_summary(
  data,
  group_col,
  category_col,
  features,
  do_boot = TRUE,
  n_boot = 1000,
  min_tokens = 20,
  conf_level = 0.95,
  bw = c("Hpi", "Hscv", "Hpi.diag", "scott.diag"),
  eval_on = c("pooled", "group1", "group2", "pooled_sample"),
  eval_n = NULL,
  eval_seed = NULL,
  engine = c("ks", "fast_diag", "fast_diagonal"),
  chunk_size = 1000L,
  method = c("mc", "legacy"),
  density = c("kde", "mvnorm"),
  mc_n = 10000L,
  ...
)

Arguments

data

Data frame containing acoustic measurements.

group_col

Character vector giving one or more grouping columns (e.g., "speaker" or c("Sex", "Style")).

category_col

String: name of column giving the category to compare (e.g., "vowel"). Each group must have exactly two categories.

features

Character vector of column names giving the acoustic space.

do_boot

Logical; if TRUE (default), perform bootstrap via boot_jsd().

n_boot

Integer; number of bootstrap resamples per group if do_boot = TRUE.

min_tokens

Minimum number of tokens per group required to compute JSD. Groups with fewer tokens are dropped.

conf_level

Confidence level for bootstrap intervals.

bw

Bandwidth selection method passed to jsd_kde_nd().

eval_on

KDE evaluation points passed to jsd_kde_nd().

eval_n

Optional maximum number of KDE evaluation points.

eval_seed

Optional integer seed for KDE evaluation-point subsampling.

engine

KDE evaluation engine passed to jsd_kde_nd(). "fast_diagonal" is accepted as an alias for "fast_diag".

chunk_size

Chunk size for engine = "fast_diag".

method

Estimator passed to jsd_kde_nd(): "mc" (default) or "legacy" (pre-1.2.0 self-normalized estimate). Ignored when density = "mvnorm".

density

Density model passed to jsd_kde_nd(): "kde" (default) or "mvnorm" (fit one multivariate normal per category and estimate JSD between the two Gaussians by Monte-Carlo).

mc_n

Positive integer; number of Monte-Carlo samples drawn from each fitted Gaussian when density = "mvnorm" (default 10000). Ignored when density = "kde".

...

Additional arguments passed to jsd_kde_nd().

Value

A tibble with one row per group and columns:

  • group - group ID (e.g., speaker)

  • n_tokens - number of tokens for that group

  • jsd_point - single JSD point estimate

  • n_boot, conf_level, jsd_mean, jsd_sd, ci_lower, ci_upper, jsd_low, jsd_high - bootstrap summary columns. These are NA (or 0 for n_boot) if do_boot = FALSE.


phontrast documentation built on Oct. 7, 2026, 5:06 p.m.