スキル一覧に戻る

generate-statistical-tables

pjt222
更新日 2 days ago
3 閲覧
17
2
17
GitHubで表示
メタworddesign

について

このClaudeスキルは、R言語でgt、kableExtra、またはflextableを使用して、出版対応の統計表を生成します。記述統計、回帰分析結果、ANOVA表、相関行列、およびAPA形式の出力を作成します。統計分析を整形して提示する必要がある学術論文やQuarto/R Markdown文書にご利用ください。

クイックインストール

Claude Code

推奨
メイン
npx skills add pjt222/agent-almanac -a claude-code
プラグインコマンド代替
/plugin add https://github.com/pjt222/agent-almanac
Git クローン代替
git clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/generate-statistical-tables

このコマンドをClaude Codeにコピー&ペーストしてスキルをインストールします

ドキュメント

Generate Statistical Tables

Make publication-ready stats tables for reports + manuscripts.

When Use

  • Make descriptive stats tables
  • Format regression or ANOVA output
  • Build correlation matrices
  • Make APA-style tables for academic papers
  • Make tables for Quarto/R Markdown docs

Inputs

  • Required: Stats analysis results (model objects, summary data)
  • Required: Output format (HTML, PDF, Word)
  • Optional: Style guide (APA, journal-specific)
  • Optional: Table numbering scheme

Steps

Step 1: Pick Table Package

PackageBest forFormats
gtHTML, general-purposeHTML, PDF, Word
kableExtraLaTeX/PDF documentsPDF, HTML
flextableWord documentsWord, PDF, HTML
gtsummaryClinical/statistical summariesAll via gt/flextable

Got: Table package picked by output format + use case. Package installed + loadable.

If fail: Package not installed? Run install.packages("gt") (or right one). gtsummary needs both gt + gtsummary installed.

Step 2: Descriptive Statistics Table

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*")
  )

Got: gt table object with formatted means, SDs, counts by category. Column headers use proper stats notation (italic M, SD, n).

If fail: group_by() unexpected? Verify grouping variable exists + has expected levels. fmt_number() errors? Target columns must be numeric.

Step 3: Regression Results Table

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")

Got: gtsummary regression table with bold p-values, model fit stats (R-squared, N) in source note, descriptive caption.

If fail: tbl_regression() fails? Verify input is model object (lm, glm). add_glance_source_note() errors? Check broom can tidy: 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")

Got: Lower-triangle correlation matrix as gt table. Upper triangle blank, two decimal places, clear caption.

If fail: sub_missing() won't blank upper triangle? Verify NA set via cor_matrix[upper.tri(cor_matrix)] <- NA. Non-numeric variables → cor() fails; filter to numeric columns first.

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")

Got: Formatted ANOVA table with Source, df, SS, MS, F, p columns. Interaction terms labeled, p-values to three decimals.

If fail: broom::tidy(aov_result) unexpected columns? Verify model = aov object. Type III sums of squares → use car::Anova(model, type = 3) not base aov().

Step 6: Save Tables

# 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")

Got: Table saved to specified format (HTML, Word, PNG, PDF). Output file opens in right application.

If fail: gtsave() fails for Word? webshot2 package needed. PDF output via kableExtra → needs LaTeX distribution (TinyTeX or MiKTeX).

Step 7: Embed in Quarto Document

```{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.

Got: Table renders inline in Quarto doc, cross-reference label (@tbl-*), proper caption. Table adapts to document output format automatically.

If fail: Table won't render? Chunk label must start with tbl- for Quarto cross-ref. Formatting lost in PDF → switch from gt to kableExtra for LaTeX output.

Checks

  • Table renders correct in target format (HTML, PDF, Word)
  • Numbers formatted consistent (decimals, alignment)
  • Stats notation follows style guide (italicized, proper symbols)
  • Table has clear caption + numbering
  • Column headers meaningful
  • Notes/footnotes explain abbreviations + significance markers

Pitfalls

  • gt in PDF: gt has limited PDF support. Use kableExtra for LaTeX-heavy docs.
  • Rounding inconsistency: Always use fmt_number() (gt) or format() not round() for display
  • Missing values display: Set with sub_missing() in gt or options(knitr.kable.NA = "")
  • Wide tables in PDF: Tables over page width need landscape() or smaller font
  • APA number formatting: No leading zero for values bounded by 1 (p-values, correlations): ".03" not "0.03"

See Also

  • format-apa-report - tables in APA manuscripts
  • create-quarto-report - embed tables in reports
  • build-parameterized-report - tables that adapt to parameters

GitHub リポジトリ

pjt222/agent-almanac
パス: i18n/caveman/skills/generate-statistical-tables
0
agentsagentskillsai-assisted-developmentclaude-codeskillsteams

関連スキル

content-collections

メタ

このスキルは、Content Collections(Markdown/MDXファイルを型安全なデータコレクションに変換するTypeScriptファーストのツール)の本番環境でテストされた設定を提供します。Zodバリデーションによる型安全性を実現し、ブログ、ドキュメントサイト、コンテンツ重視のVite + Reactアプリケーション構築時にご利用ください。Viteプラグインの設定、MDXコンパイルから、デプロイ最適化、スキーマバリデーションまで、すべてを網羅しています。

スキルを見る

polymarket

メタ

このスキルは、開発者がPolymarket予測市場プラットフォームを活用したアプリケーション構築を可能にします。API統合による取引や市場データの取得に加え、WebSocketを介したリアルタイムデータストリーミングにより、ライブ取引や市場活動を監視できます。取引戦略の実装や、ライブ市場更新を処理するツールの作成にご利用ください。

スキルを見る

creating-opencode-plugins

メタ

このスキルは、開発者がコマンド、ファイル、LSP操作など25種類以上のイベントタイプにフックするOpenCodeプラグインを作成することを支援します。JavaScript/TypeScriptモジュール向けに、プラグイン構造、イベントAPI仕様、および実装パターンを提供します。カスタムイベント駆動ロジックでOpenCode AIアシスタントのライフサイクルをインターセプト、監視、または拡張する必要がある場合にご利用ください。

スキルを見る

sglang

メタ

SGLangは、高性能なLLMサービングフレームワークであり、RadixAttentionプレフィックスキャッシュを活用したJSON、正規表現、エージェントワークフロー向けの高速で構造化された生成を特長とします。特にプレフィックスが繰り返されるタスクにおいて、大幅に高速な推論を実現し、複雑な構造化出力やマルチターン対話に最適です。制約付きデコードが必要な場合や、広範なプレフィックス共有を伴うアプリケーションを構築する場合は、vLLMなどの代替案ではなくSGLangを選択してください。

スキルを見る