generate-statistical-tables
关于
This skill generates publication-ready statistical tables in R using packages like gt, kableExtra, or flextable. It creates descriptive statistics, regression results, ANOVA tables, and APA-formatted outputs for academic papers. Use it when formatting analysis results for Quarto, R Markdown, or manuscript reports.
快速安装
Claude Code
推荐npx skills add pjt222/agent-almanac -a claude-code/plugin add https://github.com/pjt222/agent-almanacgit clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/generate-statistical-tables在 Claude Code 中复制并粘贴此命令以安装该技能
技能文档
Generate Statistical Tables
Pub-ready stat tables for reports + manuscripts.
Use When
- Descriptive stats tables
- Regression / ANOVA output format
- Correlation matrices
- APA-style academic
- Quarto / R Markdown tables
In
- Required: stat results (models, summaries)
- Required: out format (HTML, PDF, Word)
- Optional: style guide (APA, journal)
- Optional: numbering scheme
Do
Step 1: Choose pkg
| Package | Best for | Formats |
|---|---|---|
gt | HTML, general-purpose | HTML, PDF, Word |
kableExtra | LaTeX/PDF documents | PDF, HTML |
flextable | Word documents | Word, PDF, HTML |
gtsummary | Clinical/statistical summaries | All via gt/flextable |
→ Pkg selected by format + use case, installed + loadable.
If err: missing → install.packages("gt") (or proper). gtsummary needs gt + gtsummary.
Step 2: Descriptive stats
library(gt)
descriptives <- data |>
group_by(group) |>
summarise(
n = n(),
M = mean(score, na.rm = TRUE),
SD = sd(score, na.rm = TRUE),
Min = min(score, na.rm = TRUE),
Max = max(score, na.rm = TRUE)
)
gt(descriptives) |>
tab_header(
title = "Table 1",
subtitle = "Descriptive Statistics by Group"
) |>
fmt_number(columns = c(M, SD), decimals = 2) |>
fmt_number(columns = c(Min, Max), decimals = 1) |>
cols_label(
group = "Group",
n = md("*n*"),
M = md("*M*"),
SD = md("*SD*")
)
→ gt object w/ M, SD, n grouped, italic headers.
If err: group_by() unexpected → verify var + levels. fmt_number() err → numeric cols.
Step 3: Regression results
model <- lm(outcome ~ predictor1 + predictor2 + predictor3, data = data)
library(gtsummary)
tbl_regression(model) |>
bold_p() |>
add_glance_source_note(
include = c(r.squared, adj.r.squared, nobs)
) |>
modify_header(label = "**Predictor**") |>
modify_caption("Table 2: Regression Results")
→ Regression table w/ bold p, fit stats note, caption.
If err: tbl_regression() fail → verify model obj (lm, glm). add_glance_source_note() err → check broom::glance(model).
Step 4: Correlation matrix
library(gt)
cor_matrix <- cor(data[, c("var1", "var2", "var3", "var4")],
use = "pairwise.complete.obs")
# Format lower triangle
cor_matrix[upper.tri(cor_matrix)] <- NA
as.data.frame(cor_matrix) |>
tibble::rownames_to_column("Variable") |>
gt() |>
fmt_number(decimals = 2) |>
sub_missing(missing_text = "") |>
tab_header(title = "Table 3", subtitle = "Correlation Matrix")
→ Lower-triangle cor matrix w/ blanked upper, 2 dec, caption.
If err: sub_missing() not blanking → check NA set. Non-numeric → cor() fails → filter numeric.
Step 5: ANOVA table
aov_result <- aov(score ~ group * condition, data = data)
library(gtsummary)
tbl_anova <- broom::tidy(aov_result) |>
gt() |>
fmt_number(columns = c(sumsq, meansq, statistic), decimals = 2) |>
fmt_number(columns = p.value, decimals = 3) |>
cols_label(
term = "Source",
df = md("*df*"),
sumsq = md("*SS*"),
meansq = md("*MS*"),
statistic = md("*F*"),
p.value = md("*p*")
) |>
tab_header(title = "Table 4", subtitle = "ANOVA Results")
→ ANOVA w/ Source, df, SS, MS, F, p. Interactions labeled, p to 3 dec.
If err: broom::tidy(aov_result) unexpected cols → verify aov obj. Type III SS → car::Anova(model, type = 3).
Step 6: Save
# Save as HTML
gtsave(my_table, "table1.html")
# Save as Word
gtsave(my_table, "table1.docx")
# Save as PNG image
gtsave(my_table, "table1.png")
# For LaTeX/PDF (kableExtra)
kableExtra::save_kable(kable_table, "table1.pdf")
→ Saved to format. Opens correctly.
If err: gtsave() Word fail → install webshot2. PDF via kableExtra → install TinyTeX/MiKTeX.
Step 7: Embed in Quarto
```{r}
#| label: tbl-descriptives
#| tbl-cap: "Descriptive Statistics by Group"
gt(descriptives) |>
fmt_number(columns = c(M, SD), decimals = 2)
```
See @tbl-descriptives for summary statistics.
→ Renders inline w/ @tbl-* cross-ref + caption. Adapts to format.
If err: no render → chunk label tbl- prefix. PDF formatting lost → switch gt → kableExtra.
Check
- Renders in target format
- Consistent number format
- Stat notation per style (italic, symbols)
- Clear caption + numbering
- Meaningful headers
- Notes/footnotes explain abbrevs + sig markers
Traps
- gt in PDF: limited. Use kableExtra for LaTeX.
- Rounding inconsistency:
fmt_number()(gt) /format()notround(). - Missing values:
sub_missing()(gt) oroptions(knitr.kable.NA = ""). - Wide PDF:
landscape()or font reduction. - APA number: no leading zero when ≤1 (p, corr): ".03" not "0.03".
→
format-apa-report— APA manuscript tablescreate-quarto-report— embed in reportsbuild-parameterized-report— param-adaptive tables
GitHub 仓库
相关推荐技能
content-collections
元Content Collections 是一个 TypeScript 优先的构建工具,可将本地 Markdown/MDX 文件转换为类型安全的数据集合。它专为构建博客、文档站和内容密集型 Vite+React 应用而设计,提供基于 Zod 的自动模式验证。该工具涵盖从 Vite 插件配置、MDX 编译到生产环境部署的完整工作流。
polymarket
元这个Claude Skill为开发者提供完整的Polymarket预测市场开发支持,涵盖API调用、交易执行和市场数据分析。关键特性包括实时WebSocket数据流,可监控实时交易、订单和市场动态。开发者可用它构建预测市场应用、实施交易策略并集成实时市场预测功能。
creating-opencode-plugins
元该Skill帮助开发者创建OpenCode插件,用于接入命令、文件、LSP等25+种事件。它提供了插件结构、事件API规范和JavaScript/TypeScript实现模式,适合需要拦截操作、扩展功能或自定义事件处理的场景。开发者可通过它快速构建响应式模块来增强OpenCode AI助手的能力。
sglang
元SGLang是一个专为LLM设计的高性能推理框架,特别适用于需要结构化输出的场景。它通过RadixAttention前缀缓存技术,在处理JSON、正则表达式、工具调用等具有重复前缀的复杂工作流时,能实现极速生成。如果你正在构建智能体或多轮对话系统,并追求远超vLLM的推理性能,SGLang是理想选择。
