Zurück zu Fähigkeiten

generate-statistical-tables

pjt222
Aktualisiert 2 days ago
1 Ansichten
17
2
17
Auf GitHub ansehen
Metaworddesign

Über

Diese Fähigkeit erstellt publikationsreife statistische Tabellen in R unter Verwendung von Paketen wie gt, kableExtra oder flextable. Sie erzeugt deskriptive Statistiken, Regressionsergebnisse, ANOVA-Tabellen, Korrelationsmatrizen und APA-formatierte Ausgaben. Nutzen Sie sie bei der Erstellung von Tabellen für wissenschaftliche Arbeiten, Berichte oder Quarto/R Markdown-Dokumente.

Schnellinstallation

Claude Code

Empfohlen
Primär
npx skills add pjt222/agent-almanac -a claude-code
Plugin-BefehlAlternativ
/plugin add https://github.com/pjt222/agent-almanac
Git CloneAlternativ
git clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/generate-statistical-tables

Kopieren Sie diesen Befehl und fügen Sie ihn in Claude Code ein, um diese Fähigkeit zu installieren

Dokumentation

Generate Statistical Tables

Create publication-ready statistical tables for reports and manuscripts.

When to Use

  • Creating descriptive statistics tables
  • Formatting regression or ANOVA output
  • Building correlation matrices
  • Producing APA-style tables for academic papers
  • Generating tables for Quarto/R Markdown documents

Inputs

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

Procedure

Step 1: Choose Table Package

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

Got: A table package selected based on output format and use case. The chosen package is installed and loadable.

If fail: If the required package is not installed, run install.packages("gt") (or the appropriate package). For gtsummary, both gt and gtsummary must be 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: A gt table object with formatted means, SDs, and counts grouped by category. Column headers use proper statistical notation (italicized M, SD, n).

If fail: If group_by() produces unexpected results, verify the grouping variable exists and has the expected levels. If fmt_number() throws an error, ensure the target columns contain numeric data.

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: A gtsummary regression table with bolded p-values, model fit statistics (R-squared, N) in a source note, and a descriptive caption.

If fail: If tbl_regression() fails, verify the input is a model object (e.g., lm, glm). If add_glance_source_note() errors, check that broom can tidy the model: 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: A lower-triangle correlation matrix rendered as a gt table with blanked upper triangle, two decimal places, and a clear caption.

If fail: If sub_missing() does not blank the upper triangle, verify that NA values were set correctly with cor_matrix[upper.tri(cor_matrix)] <- NA. If variables are non-numeric, cor() will fail; 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: A formatted ANOVA table with Source, df, SS, MS, F, and p columns. Interaction terms are clearly labeled and p-values are formatted to three decimal places.

If fail: If broom::tidy(aov_result) produces unexpected columns, verify the model is an aov object. For Type III sums of squares, use car::Anova(model, type = 3) instead of 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 the specified file format (HTML, Word, PNG, or PDF). The output file opens correctly in the appropriate application.

If fail: If gtsave() fails for Word format, ensure the webshot2 package is installed. For PDF output via kableExtra, ensure a LaTeX distribution (TinyTeX or MiKTeX) is installed.

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: The table renders inline in the Quarto document with a cross-referenceable label (@tbl-*) and a proper caption. The table adapts to the document's output format automatically.

If fail: If the table does not render, verify the chunk label starts with tbl- for Quarto cross-referencing. If formatting is lost in PDF, switch from gt to kableExtra for LaTeX-based output.

Validation

  • Table renders correctly in target format (HTML, PDF, Word)
  • Numbers are formatted consistently (decimal places, alignment)
  • Statistical notation follows the style guide (italicized, proper symbols)
  • Table has a clear caption and numbering
  • Column headers are meaningful
  • Notes/footnotes explain abbreviations or significance markers

Pitfalls

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

Related Skills

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

GitHub Repository

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

Verwandte Skills

content-collections

Meta

Diese Skill bietet eine produktionsgetestete Einrichtung für Content Collections – ein TypeScript-first-Tool, das Markdown/MDX-Dateien in typsichere Datensammlungen mit Zod-Validierung umwandelt. Verwenden Sie ihn beim Erstellen von Blogs, Dokumentationsseiten oder inhaltsstarken Vite + React-Anwendungen, um Typsicherheit und automatische Inhaltsvalidierung zu gewährleisten. Er behandelt alles von der Vite-Plugin-Konfiguration und MDX-Kompilierung bis hin zur Deployment-Optimierung und Schema-Validierung.

Skill ansehen

polymarket

Meta

Diese Fähigkeit ermöglicht es Entwicklern, Anwendungen mit der Polymarket-Prognosemärkte-Plattform zu erstellen, einschließlich API-Integration für Handel und Marktdaten. Sie bietet außerdem Echtzeit-Datenstreaming über WebSocket, um Live-Trades und Marktaktivitäten zu überwachen. Nutzen Sie sie zur Implementierung von Handelsstrategien oder zur Erstellung von Tools, die Live-Marktaktualisierungen verarbeiten.

Skill ansehen

creating-opencode-plugins

Meta

Diese Fähigkeit unterstützt Entwickler dabei, OpenCode-Plugins zu erstellen, die in über 25 Ereignistypen wie Befehle, Dateien und LSP-Operationen eingreifen. Sie bietet die Plugin-Struktur, Event-API-Spezifikationen und Implementierungsmuster für JavaScript/TypeScript-Module. Nutzen Sie sie, wenn Sie den Lebenszyklus des OpenCode KI-Assistenten mit benutzerdefinierter ereignisgesteuerter Logik abfangen, überwachen oder erweitern müssen.

Skill ansehen

sglang

Meta

SGLang ist ein hochperformantes LLM-Serving-Framework, das sich auf schnelle, strukturierte Generierung für JSON, Regex und agentenbasierte Workflows unter Verwendung seines RadixAttention-Prefix-Cachings spezialisiert. Es bietet deutlich schnellere Inferenz, insbesondere für Aufgaben mit wiederholten Präfixen, was es ideal für komplexe, strukturierte Ausgaben und Mehrfachdialoge macht. Wählen Sie SGLang gegenüber Alternativen wie vLLM, wenn Sie constrained decoding benötigen oder Anwendungen mit umfangreicher Präfix-Weitergabe entwickeln.

Skill ansehen