% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lexical_analysis.R
\name{calculate_log_odds_ratio}
\alias{calculate_log_odds_ratio}
\title{Calculate Log Odds Ratio Between Categories}
\usage{
calculate_log_odds_ratio(
  dfm_object,
  group_var,
  comparison_mode = c("binary", "one_vs_rest", "pairwise"),
  reference_level = NULL,
  top_n = 10,
  min_count = 5
)
}
\arguments{
\item{dfm_object}{A quanteda dfm object}

\item{group_var}{Character, name of the grouping variable in docvars}

\item{comparison_mode}{Character, one of "binary", "one_vs_rest", or "pairwise"
\itemize{
\item binary: Compare two categories directly
\item one_vs_rest: Compare each category against all others combined
\item pairwise: Compare all pairs of categories
}}

\item{reference_level}{Character, reference category for binary comparison (default: first level)}

\item{top_n}{Number of top terms per comparison (default: 10)}

\item{min_count}{Minimum word count to include (default: 5)}
}
\value{
Data frame with columns:
\itemize{
\item term: The word/feature
\item category1: First category in comparison
\item category2: Second category in comparison
\item count1: Count in category 1
\item count2: Count in category 2
\item odds1: Smoothed odds in category 1, (count + 1) / (total + V - count - 1)
\item odds2: Smoothed odds in category 2
\item odds_ratio: Ratio of odds
\item log_odds_ratio: Log of odds ratio (positive = more in compared category)
\item variance: Approximate variance of the log odds ratio
\item z_score: Log odds ratio divided by its standard error
\item significant: TRUE when |z| >= 1.96
}
Terms are ranked by absolute z-score.
}
\description{
Compares word usage between categories using the log-odds ratio with a
uniform Dirichlet prior, ranked by z-score. Identifies words distinctively
used in one category. For the informative-prior weighted log-odds, see
\code{\link[=calculate_weighted_log_odds]{calculate_weighted_log_odds()}}.
}
\examples{
\donttest{
articles <- TextAnalysisR::SpecialEduTech[1:20, ]
corpus <- quanteda::corpus(
  articles$abstract,
  docvars = data.frame(reference_type = articles$reference_type)
)
dfm_object <- quanteda::dfm(quanteda::tokens(corpus))
log_odds <- calculate_log_odds_ratio(dfm_object, "reference_type")
}
}
\concept{lexical}
