% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/compare_betas.R
\name{compare_betas}
\alias{compare_betas}
\title{Compare topic-word distributions using Hellinger distance}
\usage{
compare_betas(beta1, beta2 = NULL, vocab)
}
\arguments{
\item{beta1}{Tidy beta dataframe with columns \code{token}, \code{topic}, and \code{beta},
as returned by \code{tidy(model, matrix = 'beta')}.}

\item{beta2}{Optional second tidy beta dataframe in the same format. If
\code{NULL} (default), pairwise distances among the topics in \code{beta1} are
returned.}

\item{vocab}{Character vector of vocabulary tokens used to align the column
space of both matrices. Tokens in \code{beta1} or \code{beta2} that are not in
\code{vocab} are dropped; tokens in \code{vocab} absent from a beta are filled with
probability 0.}
}
\value{
Numeric matrix of Hellinger distances. Dimensions are k1 × k1 when
\code{beta2 = NULL}, or k1 × k2 when two beta dataframes are supplied, where
k1 and k2 are the number of topics in each model.
}
\description{
Computes pairwise Hellinger distances between topics from one or two fitted
models. Tokens missing from a beta dataframe are filled with probability 0
before comparison, so both models need not share the same vocabulary.
}
\examples{
set.seed(42)
vocab = letters[1:5]
make_beta = function(k) {
  rdirichlet(k, rep(1, length(vocab))) |>
    tibble::as_tibble(.name_repair = ~vocab) |>
    dplyr::mutate(topic = paste0('t', dplyr::row_number())) |>
    tidyr::pivot_longer(-topic, names_to = 'token', values_to = 'beta')
}
beta1 = make_beta(3)
beta2 = make_beta(4)
compare_betas(beta1, vocab = vocab)
compare_betas(beta1, beta2, vocab = vocab)
}
