Skip to contents

For each theme, compares a numeric metric between units where the theme is present and units where it is absent, using Welch's two-sample t-test. P-values are adjusted for multiple comparisons across themes.

Usage

cross_tab_themes(
  coded_data,
  metric_col,
  themes = NULL,
  metrics = NULL,
  id_col = NULL,
  p_adjust = "BH",
  alpha = 0.05
)

Arguments

coded_data

A data frame returned by llm_auto_code().

metric_col

The numeric metric column (unquoted or a string). It is looked up in metrics if supplied, otherwise in coded_data.

themes

Character vector of theme columns. Defaults to the codebook stored by llm_auto_code().

metrics

Optional participant-level data frame holding the metric.

id_col

Name of the ID column (a string) used to aggregate and join when metrics is supplied. Defaults to the ID column used in llm_auto_code().

p_adjust

Multiple-comparison correction passed to stats::p.adjust(). Defaults to "BH" (false discovery rate).

alpha

Significance threshold applied to the adjusted p-value.

Value

A tibble with one row per theme: group sizes and means, the mean difference (present minus absent) with its 95% confidence interval, Cohen's d, raw and adjusted p-values, and a significant flag. Themes with fewer than two units in either group get NA statistics.

Details

When the text was coded at segment level (several rows per participant) and the metrics live in a separate participant-level table, pass that table as metrics: codes are first aggregated per participant (a theme counts as present if it appears in any of their segments) and then joined to the metrics by id_col.

Examples

df <- mock_mixed_data(80, seed = 42)
coded <- llm_auto_code(df, user_id, transcript_feedback,
                       codebook = c("UI_Confusion", "Positive_Experience",
                                    "Feature_Request"),
                       coder = mock_coder())
cross_tab_themes(coded, session_duration_sec)
#> # A tibble: 3 × 12
#>   theme          n_absent n_present mean_absent mean_present difference conf_low
#>   <chr>             <int>     <int>       <dbl>        <dbl>      <dbl>    <dbl>
#> 1 UI_Confusion         50        30        181.         439.     258.      227. 
#> 2 Positive_Expe…       47        33        372.         142.    -230.     -263. 
#> 3 Feature_Reque…       49        31        275.         282.       6.81    -56.7
#> # ℹ 5 more variables: conf_high <dbl>, cohens_d <dbl>, p_value <dbl>,
#> #   p_adjusted <dbl>, significant <lgl>