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

## -----------------------------------------------------------------------------
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

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

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

## ----eval = requireNamespace("ggplot2", quietly = TRUE)-----------------------
plot_category_pca(
  data = tokens,
  features = features,
  category_col = "category",
  group_col = "speaker"
)

## ----eval = requireNamespace("ggplot2", quietly = TRUE)-----------------------
plot_category_space(
  data = tokens,
  features = c("feature_1", "feature_2"),
  category_col = "category",
  group_col = "speaker"
)

## ----eval = FALSE-------------------------------------------------------------
# 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"
# )

