wordorientation

Detect attraction and repulsion between words in text.

What it does

For every pair of words that co-occur often enough to analyze, wordorientation computes the phi coefficient (a correlation measure for binary co-occurrence data), tests it for significance, and classifies the pair as:

Installation

# once on CRAN
install.packages("wordorientation")

# development version
# devtools::install_github("yourusername/wordorientation")

Usage

library(wordorientation)

result <- analyze_word_orientation(
  example_social_posts(),
  text_col = "text", doc_col = "id",
  min_count = 2
)

head(result$scored)
plot_orientation_network(result$scored)

Or step by step:

tokens <- tokenize_posts(my_data, text_col = "text")
cooc   <- cooccurrence_counts(tokens, min_count = 5)
scored <- word_orientation(cooc, alpha = 0.05)

wordorientation combines tokenization, co-occurrence counting, significance-tested classification, and network visualization into a single general-language pipeline.

Multiple comparisons

By default, word_orientation() applies a Benjamini-Hochberg correction across all tested word pairs (p_adjust_method = "BH"). On small corpora with few documents, this can mean no pair survives correction even when raw phi values look large — this is intentional, not a bug: it guards against over-interpreting spurious associations from sparse data.