Skip to contents

Convert an nlp_k_selection object into a wide, export-ready table with one row per candidate topic count.

Usage

summarize_k_selection(selection, optop = NULL, include_unsupported = FALSE)

Arguments

selection

An nlp_k_selection object returned by select_k_topics().

optop

Optional output from OpTop::optimal_topic(). The common OpTop result shape with columns topic, OpTop, and pval is supported, as are cleaned tables with k, optop, and p-value aliases such as p_value or p.value.

include_unsupported

Logical. Should unsupported aggregate metrics be retained as NA_real_ columns? Defaults to FALSE.

Value

An object of class c("nlp_k_selection_summary", "data.table", "data.frame") with one row per k. Aggregate metrics are widened into columns. Topic-level rows are preserved in attr(result, "topic_metrics") when present. Unsupported aggregate rows are preserved in attr(result, "unsupported") when include_unsupported = TRUE.

Details

This helper reports already-computed evidence; it does not fit models, call OpTop, compute a composite score, or choose the best value of \(K\). Use it after select_k_topics() and, optionally, after an external OpTop::optimal_topic() call.

Examples

selection <- data.table::data.table(
  k = c(2L, 3L),
  metric = "diversity",
  level = "aggregate",
  topic_id = NA_character_,
  value = c(0.75, 0.82),
  supported = TRUE
)
class(selection) <- c("nlp_k_selection", class(selection))

summarize_k_selection(selection)
#> <nlp_k_selection_summary>
#>   candidate K values: 2, 3
#>   columns: diversity
#>   OpTop: not included