% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils.R
\name{calculate_word_frequency}
\alias{calculate_word_frequency}
\title{Analyze and Visualize Word Frequencies Across a Continuous Variable}
\usage{
calculate_word_frequency(
  dfm_object,
  continuous_variable,
  selected_terms,
  height = 500,
  width = 900
)
}
\arguments{
\item{dfm_object}{A quanteda document-feature matrix (dfm).}

\item{continuous_variable}{A continuous variable in the metadata.}

\item{selected_terms}{A vector of terms to analyze trends for.}

\item{height}{The height of the resulting Plotly plot, in pixels (default: 500).}

\item{width}{The width of the resulting Plotly plot, in pixels (default: 900).}
}
\value{
A list containing Plotly objects and tables with the results.
}
\description{
This function analyzes and visualizes word frequencies across a continuous variable.
}
\details{
This function requires a fitted STM model object and a quanteda dfm object.
The continuous variable should be a column in the metadata of the dfm object.
The selected terms should be a vector of terms to analyze trends for.
The required packages are 'htmltools', 'splines', and 'broom' (plus
additional ones loaded internally).
}
\examples{
\donttest{
  mydata <- TextAnalysisR::SpecialEduTech

  united_tbl <- TextAnalysisR::unite_cols(
    mydata,
    listed_vars = c("title", "keyword", "abstract")
  )

  tokens <- TextAnalysisR::prep_texts(united_tbl, text_field = "united_texts")

  dfm_object <- quanteda::dfm(tokens)

  word_freq_results <- TextAnalysisR::calculate_word_frequency(
    dfm_object,
    continuous_variable = "year",
    selected_terms = c("calculator", "computer"),
    height = 500,
    width = 900
  )
  print(word_freq_results$plot)
  print(word_freq_results$table)
}
}
\seealso{
\code{\link[=extract_keywords_tfidf]{extract_keywords_tfidf()}} and \code{\link[=extract_keywords_keyness]{extract_keywords_keyness()}} for ranking terms by importance; \code{\link[=plot_word_frequency]{plot_word_frequency()}} for the standard frequency-by-doc plot
}
