Skip to contents

Formats output of srv_prop_stats() into a wide spreadsheet layout with one row per subject-variable level and hierarchical cohort columns.

By default, the column hierarchy is taken from cohort metadata columns label and level when they are present. You can override that with hierarchy_cols.

By default, each cohort contains n and percentage columns. Use stats to add or remove statistics. Percentage, index, and p-value cells use the same significance coloring.

When the input contains .is_reference, reference percentage, index, and p-value cells use a light-blue background.

Usage

srv_prop_stats_render(
  summary,
  hierarchy_cols = NULL,
  stats = c("n", "percentage"),
  wb = NULL,
  sheet_name = "Prop Stats"
)

Arguments

summary

Output of srv_prop_stats().

hierarchy_cols

Optional tidy-select expression choosing the summary columns to use as the column hierarchy. By default, uses c(label, level) when present.

stats

Character vector with statistics to include. Available values are n, percentage, index, and pval.

wb

Optional openxlsx workbook to append to.

sheet_name

Character. Sheet name to write into.

Value

An openxlsx workbook.

Examples

gender_cohorts <- example_srv_main |>
  g6tr.cohorts::create_cohort_set(
    id_col = response_id,
    grp_cols = d_gender,
    weight_col = weight
  )

summary <- srv_prop_stats(
  example_srv_main,
  sbj_cols = c(m1_news_interest, m1_news_trust),
  cohorts = gender_cohorts,
  id_col = response_id
)

wb <- srv_prop_stats_render(summary)