Contrast and Separation Metrics for Phonological Categories
Overview
Computes and compares multiple measures of separation and overlap between phonological categories (for example vowels or consonants) in arbitrary multi-dimensional acoustic spaces such as formant values, mel-frequency cepstral coefficients (MFCCs), duration, or learned embeddings. The main entry point, phontrast(), reports several contrast metrics in one call -- Jensen-Shannon divergence and distance (Lin, 1991) doi:10.1109/18.61115, the Pillai-Bartlett trace, Bhattacharyya distance and affinity, Mahalanobis distance, and proportional overlap -- globally or by group on a common separation-oriented scale, with bootstrap confidence intervals. rank_contrasts() implements a measurement protocol for ranking speakers' contrasts by Jensen-Shannon distance and checking the ranking against Pillai, with sample-size licensing and a bandwidth-sensitivity check. Also provides utilities for preparing estimates for downstream modelling such as generalized additive models and mixed-effects models. Formerly released as 'phonJSD'.
The ranking protocol in one call
This release implements the measurement protocol recommended by the simulation
study "Estimand or estimator? Comparing vowel overlap measures against a known
ground truth" (Berry, under review, Sec. VII.A), so that its three steps and
their conditions can be run and reported without hand-assembling them.
rank_contrasts(data, features, category_col, group_col)computes, per speaker, Jensen-Shannon distance (sqrt_jsd) and shared probability mass from one shared kernel density estimate and the Pillai trace on the same tokens (step 1); ranks the speakers on the percentile-rank scale(average rank - 1/2) / k, ties averaged, after setting measurements at thesqrt(JSD)ceiling (default 0.99) apart (step 2); and flags speakers whose Pillai andsqrt(JSD)percentile ranks differ bymargin(default 0.25 of the ordering) or more (step 3).
Show all changes in 2.5.0Hide the rest of the changes in 2.5.0
- The study's conditions are applied and reported rather than left to the user: sample-size floors per speaker from the smaller category's count (
rank_licensed,flag_licensed,rank_basis; ranking licensed from 50 tokens per category at d = 2, 200 at d = 3-4, 500 at d = 5-8; the flag readable from 100 at d = 2 and 200 at d = 3-4, undefined whend >= 2n, withheld from d = 5), a warning below eight speakers, and the bandwidth check (sqrt(JSD)recomputed at half and twice the diagonal Scott bandwidth;bw_shift,sign_change,set_aside). - The result is a
phontrast_rankingtibble with aprint()method that summarizes the protocol, the estimator, the floors, the flagged and set-aside speakers, and the ceiling. The cleaned tokens travel with it inattr(x, "protocol"). plot_rank_agreement()(alsoplot()/ggplot2::autoplot()on the ranking) draws Pillai percentile rank againstsqrt(JSD)percentile rank with the identity line and the+/- margininspection band; flagged speakers are coloured and labelled, set-aside speakers crossed, unreadable flags hollow, and ceiling speakers listed in the caption.inspect_contrast(ranking, group)redraws one speaker withplot_contrast()'s distribution-aware layers at half, the selected, and twice the diagonal Scott bandwidth, annotating each panel withsqrt(JSD)and shared mass at that bandwidth plus the speaker's Pillai, and restating the reported ranks and the bandwidth-check outcome in the subtitle.- Helpers:
percentile_rank()(the protocol's rank scale, with anexcludemask),protocol_floors(d)(the licensing floors by dimensionality), andrecommended_estimator(d)(the kernel estimator settings the study used at each dimensionality: plug-in /ksat d <= 4, diagonal Scott /fast_diagwith 200 evaluation tokens from d = 5, no leave-one-out from d = 14). - A bundled, simulated twelve-speaker cohort,
vowel_cohort, with a planted Pillai /sqrt(JSD)disagreement, a ceiling speaker, and two under-sampled speakers; and a vignette, "Ranking speakers by Jensen-Shannon distance and checking Pillai agreement", that walks through the protocol on it.
Bandwidth multiplier
- New
bw_scaleargument on the kernel path (jsd_kde_nd(),percent_overlap_kde(),estimate_jsd(),estimate_overlap(),phontrast(),plot_contrast()): a positive multiplier on the selected bandwidth on the standard-deviation scale (h * bw_scale; bandwidth matricesH * bw_scale^2).0.5and2give the halved and doubled bandwidths of the smoothing-sensitivity check.plot_contrast()draws its regions, overlap shading, and annotations at the scaled bandwidth and records it in the caption. Ignored underdensity = "mvnorm".
The kernel family on one shared density
phontrast()now reads Jensen-Shannon divergence and distance, proportional overlap, total variation, and the matched-kernel Bhattacharyya affinity / distance and Hellinger distance off a single density estimate per comparison, instead of separate kernel passes for JSD and overlap. Values of the existing columns are unchanged; bootstraps do half the kernel work.- New opt-in metrics for
phontrast(metrics = ...):"tv"(total variation,total_variation = 1 - percent_overlap);"bhattacharyya_kde"(bhatt_kde_dist,bhatt_kde_affinity,hellinger), the same quantity as the closed-form Gaussian"bhattacharyya"columns under a matched kernel estimator, with the same partial leave-one-out self-density as JSD, so measure and estimator can be told apart; and"euclidean"(euclidean_dist), the distance between the category means after dividing each feature by the pooled two-category standard deviation (bounded by2 * sqrt(d)for equal category sizes). The default metric set and the column order of earlier releases are unchanged; long output and bootstraps cover the new columns.
Citation
citation("phontrast")now lists the study behind the protocol as a second entry (manuscript under review, with the OSF replication package), after the software citation.
From NEWS.md in the release
Install
Health
- OK13 OKNow
- OK7 OK2026-08-10
Documentation
- Help pages
- 39 (2 internal)includes a package overview page
- Examples that run
- 100%21 run in a plain check (3 of them under a condition)
- Exported functions with examples
- 54%
- Documented parameters
- 91%
- Return-value docs
- 100%
- Help pages citing references
- 3%
Downloads
Repository
- PRs merged (all time)
- 100%
- Median days to close, 50 most recently updated closed issues
- 0
- Median days to close, 50 most recently updated closed PRs
- 0
Releases over time
Commits over time
6 development-tooling and community-health practices detected across 4 families in the upstream repository
Checks run against github.com/berrygrant/phontrast on 2026-10-22.
The R CMD check workflow runs on Linux
This repository shows signs of AI coding tools.
- Claude Codefirst seen 2026-07-18Pull request it wrote: opened by a project memberCommits: 1 by its own account · at least 6 crediting it in the message
- Claude Opus 4.83 commits · Jul 2026
- Claude Opus 5.53 commits · Oct 2026
Dependencies
Code & Tests
Datasets
People & History
Package metadata
- First published
- 2026-08-09
- Total releases
- 4 / 1 yrs
- License
- MIT + file LICENSE OSI
- Minimum R
- ≥ 4.1.0
- Bundled data
- 9.3 KB / 1 file
- Download size
- 464 KB
Cite
Cite this package
Run in R for the authors' preferred citation:
citation("phontrast")The package provides a citation file that builds its entry when R runs it. Run citation() to see it.
The repository also keeps a CITATION.cff.
Cite the R Observatory
For a number measured here: a download total, a coverage figure, an archival date.
From data release v2026-10-24, which the citation names so these numbers can be found later. More on citing and the projects behind them.