| jsd_kde_nd | R Documentation |
Computes Jensen-Shannon divergence between two categories in an arbitrary n-dimensional acoustic space using multivariate KDE. The default engine uses the ks package; a faster diagonal-Gaussian engine is available for diagonal bandwidths.
jsd_kde_nd(
data,
features,
group = "category",
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,
loo = TRUE,
bw_scale = 1
)
data |
A data frame containing observations from exactly two categories. |
features |
Character vector of column names giving the acoustic dimensions (e.g., MFCC1..MFCC13, F1/F2/duration). |
group |
String: name of the column giving the category labels
(e.g., "vowel", "segment"). Must have exactly two unique values in |
bw |
Bandwidth selection method. One of |
eval_on |
Where to evaluate the KDEs ( |
eval_n |
Optional positive integer giving the maximum number of
evaluation points to use. If supplied, evaluation points are sampled from
the set chosen by |
eval_seed |
Optional integer seed used only when |
engine |
KDE evaluation engine. |
chunk_size |
Positive integer controlling the number of evaluation
points processed per chunk by |
method |
Estimator: |
density |
Density model behind the estimate: |
mc_n |
Positive integer; number of Monte-Carlo samples drawn from each
fitted Gaussian when |
loo |
Logical; if |
bw_scale |
Positive number multiplying the selected kernel bandwidth on
the standard-deviation scale: univariate bandwidths are multiplied by
|
By default (method = "mc") JSD is estimated with a Monte-Carlo plug-in:
each category's KDE is evaluated at that category's own observations and the
log density ratio against the mixture is averaged. This is a consistent
estimator of the continuous JSD in any dimension. method = "legacy"
reproduces the pre-1.2.0 self-normalized sample-point estimate (a bounded
relative separation index rather than the continuous JSD); use it only to
reproduce results from phonJSD 1.0.0.
A single numeric JSD value in bits, bounded in [0, 1].
set.seed(2026)
vowels <- data.frame(
vowel = rep(c("ih", "eh"), each = 40),
f1 = c(rnorm(40, 500, 55), rnorm(40, 565, 60)),
f2 = c(rnorm(40, 1980, 150), rnorm(40, 1870, 155))
)
# One-dimensional JSD, for example a single formant or duration.
jsd_kde_nd(vowels, features = "f1", group = "vowel")
# Two-dimensional JSD in F1/F2 space.
jsd_kde_nd(vowels, features = c("f1", "f2"), group = "vowel")
# Faster high-dimensional path: diagonal Scott bandwidth and sampled
# pooled evaluation points.
jsd_kde_nd(
vowels,
features = c("f1", "f2"),
group = "vowel",
bw = "scott.diag",
eval_n = 40,
eval_seed = 2026,
engine = "fast_diag"
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.