Render srv_cont_stats() output to a workbook
Source: R/srv_cont_stats_render.R
srv_cont_stats_render.RdFormats output from srv_cont_stats() with variables in rows and cohorts in
columns. By default, each cohort contains n, mean, median, q05, and
q95 columns.
diff shows the cohort mean minus the reference mean, in the original units.
pval is the two-sided weighted Welch p-value comparing those means against
the full reference cohort. Both statistics require a cohort-set summary.
Only mean cells use significance coloring: green for higher means and orange
for lower means, with stronger colors at smaller p-values. Reference cells
use a light-blue fill. Reference rows have diff = 0 and no p-value.
Usage
srv_cont_stats_render(
summary,
hierarchy_cols = NULL,
stats = c("n", "mean", "median", "q05", "q95"),
wb = NULL,
sheet_name = "Cont Stats"
)Arguments
- summary
Output of
srv_cont_stats().- hierarchy_cols
Optional tidy-select expression choosing the cohort columns used for the column hierarchy. By default, the function uses
c(label, level)when present.- stats
Character vector with statistics to include. Available values are
n,N,mean,median,q05,q95,sd,min,max,diff, andpval.- wb
Optional
openxlsxworkbook to append to.- sheet_name
Character. Sheet name to write into.
Examples
data <- example_srv_main |>
dplyr::mutate(news_interest_score = 5 - as.numeric(m1_news_interest))
gender_cohorts <- data |>
g6tr.cohorts::create_cohort_set(
id_col = response_id,
grp_cols = d_gender,
weight_col = weight
)
summary <- srv_cont_stats(
data,
sbj_cols = news_interest_score,
cohorts = gender_cohorts,
id_col = response_id
)
wb <- srv_cont_stats_render(
summary,
stats = c("n", "mean", "diff", "pval")
)