記述統計の表

実証論文の「表 1」。変数ごとの N、平均、標準偏差、最小値、中央値、最大値をパネルに分けて示し、群ごとの平均とその差の検定を添えます。

記述統計の表

モデルの前に、論文はまずデータを記述します。この表は各変数について、欠測のない観測数、平均、標準偏差、最小値、中央値、最大値を示し、パネル(被説明変数、個人の属性、ネットワーク)にまとめています。右側のブロックは論文の関心である 2 つの群、ここでは残るつもりの回答者と移住するつもりの回答者を比べ、バランス表のように平均の差と Welch の t 検定による星を示します。

書式はすべて Python の文字列ではなく Great Tables 自身で整えています。fmt_integer() と fmt_number()(0/1 変数が 0 と 1 と表示されるよう drop_trailing_zeros を指定)、差に星を付ける cols_merge()、セルを空欄にする sub_missing()、グループ列から作る tab_stub() のパネルと tab_stub_indent()、そして PNG 書き出しの現行の方法である gtsave()(Selenium を使う save() に代わるもの)です。体裁はこのファミリーの回帰表と同じで、セリフ体、スモールキャピタルの表題、横罫線のみです。

設定は Blakely & Warin (2012, Global Economy Journal) による、欧州における移住の決定は選択か模倣かという研究です。データは説明のためのシミュレーションであり、論文のデータや結果ではありません。調査回答者 2,500 人で、約 6% は世帯所得が欠測しているため、N は行によって異なります。

コードおよび図中のテキストは英語です。

summary-statistics.py · 94 行
ダウンロード GitHub
import numpy as np
import pandas as pd
from scipy import stats
from great_tables import GT, loc, style
# Simulated data, set in the context of Blakely & Warin (2012) [blakely2012]

# Data: 2,500 respondents; younger, unemployed and better-connected people plan to move
rng = np.random.default_rng(2012)
n = 2500
age = rng.uniform(18, 70, n).round()
tertiary = rng.binomial(1, 0.3, n)
unemployed = rng.binomial(1, 0.1, n)
network = rng.binomial(1, 0.35, n)
contacts = rng.poisson(0.6 + 2.2 * network)
satisfaction = rng.integers(1, 11, n)
income = np.exp(rng.normal(3.3 + 0.35 * tertiary - 0.4 * unemployed, 0.45, n)).round(1)
income[rng.random(n) < 0.06] = np.nan                     # item non-response
eta = -0.2 - 0.045 * age + 0.35 * tertiary + 0.7 * unemployed + 0.95 * network - 0.12 * satisfaction
move = rng.binomial(1, 1 / (1 + np.exp(-eta)))
df = pd.DataFrame({"move": move, "age": age, "female": rng.binomial(1, 0.52, n),
                   "tertiary": tertiary, "unemployed": unemployed, "income": income,
                   "satisfaction": satisfaction, "network": network, "contacts": contacts})

panels = {
    "Panel A. Outcome": {"move": "Intends to move abroad (0/1)"},
    "Panel B. Individual characteristics": {
        "age": "Age (years)", "female": "Female (0/1)", "tertiary": "Tertiary education (0/1)",
        "unemployed": "Unemployed (0/1)", "income": "Household income (€ thousand per year)",
        "satisfaction": "Life satisfaction (1–10)"},
    "Panel C. Networks": {
        "network": "Family or friends abroad (0/1)", "contacts": "Contacts abroad (number)"},
}

# One row per variable: full-sample statistics, then group means and Welch t-test
rows = []
for panel, variables in panels.items():
    for var, label in variables.items():
        x = df[var].dropna()
        row = {"panel": panel, "variable": label, "N": len(x), "mean": x.mean(), "sd": x.std(),
               "min": x.min(), "median": x.median(), "max": x.max()}
        if var != "move":                                   # the outcome defines the groups
            stay, go = x[df.move == 0], x[df.move == 1]
            t = stats.ttest_ind(go, stay, equal_var=False)
            row |= {"stay": stay.mean(), "go": go.mean(), "diff": go.mean() - stay.mean(),
                    "stars": "***" if t.pvalue < .01 else "**" if t.pvalue < .05 else "*" if t.pvalue < .1 else ""}
        rows.append(row)
tab = pd.DataFrame(rows)
n_stay, n_go = (df.move == 0).sum(), (df.move == 1).sum()

full = ["N", "mean", "sd", "min", "median", "max"]
groups = ["stay", "go", "diff"]
table = (
    GT(tab)
    .tab_stub(rowname_col="variable", groupname_col="panel")
    .tab_stub_indent(rows=list(range(len(tab))), indent=2)
    .tab_header(title="TABLE II", subtitle="Descriptive statistics")
    .tab_spanner(label="Full sample", columns=full, id="full")
    .tab_spanner(label="Mean by intention", columns=groups, id="groups")
    .cols_label(N="N", mean="Mean", sd="SD", min="Min", median="Median", max="Max",
                stay=f"Stay ({n_stay:,})", go=f"Move ({n_go:,})", diff="Difference")
    .fmt_integer(columns="N")
    .fmt_number(columns=["mean", "sd", "stay", "go", "diff"], decimals=2)
    .fmt_number(columns=["min", "median", "max"], decimals=1, drop_trailing_zeros=True)
    .cols_merge(columns=["diff", "stars"], pattern="<<{0}{1}>>")   # stars glued to the difference
    .sub_missing(columns=groups, missing_text="")
    .cols_align("center", columns=full + groups)
    .tab_source_note(f"Notes: n = {n:,} respondents (simulated). N counts non-missing observations; "
                     f"household income is missing for {df.income.isna().sum()} respondents.")
    .tab_source_note("Difference = Move − Stay, with stars from Welch t-tests of equal means: "
                     "*p < 0.1; **p < 0.05; ***p < 0.01.")
    # Same journal look as Table I: serif type, small-caps title, horizontal rules only
    .opt_table_font(font=["Latin Modern Roman", "Times New Roman", "Georgia", "serif"])
    .tab_options(
        table_width="900px", table_font_size="15px", table_font_color="#000",
        heading_title_font_size="15px", heading_subtitle_font_size="15px", heading_padding="1px",
        table_border_top_style="hidden", table_border_bottom_style="hidden",
        heading_border_bottom_style="none",
        column_labels_border_top_style="solid", column_labels_border_top_width="1.5px",   # top rule
        column_labels_border_top_color="#000",
        column_labels_border_bottom_style="solid", column_labels_border_bottom_width="1px",
        column_labels_border_bottom_color="#000",
        table_body_border_top_style="solid", table_body_border_top_width="1px",
        table_body_border_top_color="#000",
        row_group_border_top_style="none", row_group_border_bottom_style="none",
        row_group_padding="6px",
        table_body_hlines_style="none", stub_border_style="none",
        table_body_border_bottom_style="solid", table_body_border_bottom_width="1.5px",
        table_body_border_bottom_color="#000",
        data_row_padding="3px", source_notes_font_size="13px", source_notes_padding="1px",
    )
    .tab_style(style.css("font-variant: small-caps; padding-bottom: 8px;"), loc.subtitle())
    .tab_style(style.text(style="italic"), [loc.row_groups(), loc.spanner_labels(ids=["full", "groups"])])
)
table.show()

図にはオプションの PyStatlas スタイル を使用しています。同じ見た目にするには plt.style.use("pystatlas.mplstyle") を追加してください。

データの出典

  • Simulated data. Simulated data with a fixed random seed, created for this example.
    No real respondents, documents or measurements: the numbers only illustrate how the chart and its statistics work.
  • Blakely & Warin (2012), the decision to migrate in Europe. Blakely, A., & Warin, T. (2012). Choice or mimetism in the decision to migrate? A European illustration. Global Economy Journal, 12(2). https://doi.org/10.1515/1524-5861.1818
    The example is set in the context of this paper; unless its description says otherwise, the numbers are simulated and are not the paper's data or results.

これらの例は統計手法を説明するためのものです。項目に別の記載がない限り数値はシミュレーションであり、図のタイトルはこのシミュレーションデータで図が示す内容を述べたものです。引用した論文の知見でも、実質的な問いに対する著者の立場でもありません。結果、背景、データについては、ここに挙げた論文を参照してください。

引用方法

PyStatlas は Thierry Warin が作成・運営しています。研究や業務に役立った場合は、ぜひ引用してください。

Warin, T. (2026). Summary statistics table. In PyStatlas: A Python Gallery of Statistical Graphics for the Social Sciences (Version 1.1.0) [Computer software]. https://warin.ca/pystatlas/academic-tables/summary-statistics/

@misc{warin2026statlas,
  author       = {Warin, Thierry},
  title        = {PyStatlas: A Python Gallery of Statistical Graphics for the Social Sciences},
  year         = {2026},
  version      = {1.1.0},
  howpublished = {\url{https://warin.ca/pystatlas/}},
  note         = {Source code: https://github.com/warint/pystatlas}
}

学術論文の表のその他のグラフ