Convert an nlp_k_selection object into a wide, export-ready table with one
row per candidate topic count.
Arguments
- selection
An
nlp_k_selectionobject returned byselect_k_topics().- optop
Optional output from
OpTop::optimal_topic(). The common OpTop result shape with columnstopic,OpTop, andpvalis supported, as are cleaned tables withk,optop, and p-value aliases such asp_valueorp.value.- include_unsupported
Logical. Should unsupported aggregate metrics be retained as
NA_real_columns? Defaults toFALSE.
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
