Multidimensional workflows

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

phontrast can estimate category separation in feature spaces with more than two dimensions, such as MFCC vectors, formants plus duration, or other acoustic embeddings. The key distinction is that metrics and plots answer different questions:

library(phontrast)

set.seed(2026)
features <- paste0("feature_", 1:6)
tokens <- data.frame(
  speaker = rep(c("s01", "s02"), each = 80),
  category = rep(rep(c("A", "B"), each = 40), 2),
  matrix(rnorm(160 * length(features)), ncol = length(features))
)
names(tokens)[-(1:2)] <- features
tokens[tokens$category == "B", features[1:3]] <-
  tokens[tokens$category == "B", features[1:3]] + 0.65

Compute metrics in all dimensions.

metrics <- phontrast(
  data = tokens,
  features = features,
  category_col = "category",
  group_col = "speaker",
  output = "long"
)

metrics[, c("group", "metric", "estimate", "orientation", "separation_value")]

Visualize a projection without changing the metric estimand.

plot_category_pca(
  data = tokens,
  features = features,
  category_col = "category",
  group_col = "speaker"
)

For a specific pair of interpretable dimensions, use plot_category_space().

plot_category_space(
  data = tokens,
  features = c("feature_1", "feature_2"),
  category_col = "category",
  group_col = "speaker"
)

PCA plots are useful for sanity checks and presentations, but they can hide separation that lives outside the first two principal components. Use them as a visual diagnostic; report metric estimates from the intended full feature set.

PB52 note

The Peterson and Barney 1952 data in phonTools::pb52 are useful for global vowel contrasts. For example, a global I/i comparison in F1/F2 has many tokens. Per-speaker I/i F1/F2 comparisons are not estimable with KDE-based metrics because each speaker has only two repetitions per vowel.

data(pb52, package = "phonTools")
pb_i <- subset(pb52, as.character(vowel) %in% c("I", "i"))

phontrast(
  data = pb_i,
  features = c("f1", "f2"),
  category_col = "vowel"
)


Try the phontrast package in your browser

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

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