PyStatlas について
実際の社会科学データにもとづき、答える問いごとに整理した Python の統計グラフ集です。モデルの予測精度とその理由を示す機械学習、地図と空間的自己相関を扱う空間データを、分布、グループ比較、回帰、生存分析と並べて収録し、すべての図に推定値、信頼区間、検定、効果量といった根拠となる統計量を示します。
PyStatlas は、コードからではなく、研究者が立てる問いから出発します。もともとは、自分の分野をよく知り、データで問いに答える必要がある社会科学の学生のために作られました。これらのグループに差はあるか、2 つの変数は連動しているか、モデルは何を予測し、それはなぜか。各グラフは必要な統計量を図の上に示し、Python の科学計算エコシステムで書かれた短く自己完結したスクリプトを添えています。R の ggstats や ggstatsplot と同じ考え方です。
基本方針
- 単体で動作。すべてのスクリプトはそのまま実行できます。データは statsmodels と lifelines に同梱された実際の社会科学データ(選挙、学校、犯罪、出生率、政治体制、再犯など)、手入力した公表済みの小さな表、またはまれに明示したシード固定のシミュレーションです。空間データの例は、ゲリーのフランス地図を libpysal で一度だけ取得し、その後は保存されたコピーを使います。
- 統計が第一。各グラフには、推定値、区間、検定統計量、効果量といった重要な数値が示されています。
- フォルダ=ページ。リポジトリの構成はサイトの構成と一致しています。各例は
gallery/<family>/<chart>/plot.pyに置かれ、描画済みのplot.pngと README が付属します。
カテゴリ
| カテゴリ | グラフ数 | 内容 |
|---|---|---|
| 機械学習 | 9 | モデルは新しいデータをどれだけうまく予測できるのか、そしてなぜか。交差検証による評価、学習曲線、モデルに依存しない説明を、それぞれの不確実性とともに示します。 |
| 空間データ | 4 | 近隣の値が高いところでは、その値も高いのか。空間重み、大域的・局所的な空間自己相関、そしてクラスターの広がりを、1830 年代のゲリーのフランスで示します。 |
| 分布 | 5 | ヒストグラム、密度曲線、リッジラインプロット、ECDF、Q–Q プロットでデータの形をとらえます。 |
| 群間比較 | 5 | 検定、効果量、p値をグラフ上に示して群を比較します。ggstatsplot のスタイルです。 |
| 割合と調査データ | 5 | 割合、クロス集計、リッカート尺度を、ggstats::gglikert や stat_prop の流儀で描きます。 |
| 相関と関連 | 4 | 相関行列、統計量付き散布図、変数ペア間の関係を描きます。 |
| 回帰モデル | 6 | 係数プロット、オッズ比、モデル比較、限界効果。Python 版の ggcoef_model です。 |
| モデル診断 | 5 | 残差、てこ比、キャリブレーション、ROC 曲線。モデルを信頼する前に確認しましょう。 |
| 生存時間分析 | 4 | リスク集合表付きのカプラン・マイヤー曲線、累積ハザード、Cox モデルのハザード比。 |
| 時系列 | 4 | 分解、自己相関、予測区間付きの予測、時間的変化を描きます。 |
| 多変量解析とクラスタリング | 4 | 高次元データのための PCA バイプロット、スクリープロット、クラスタリング、ヒートマップ。 |
| 推測と不確実性 | 6 | ブートストラップ、信頼区間、検出力、一致度、メタアナリシスのフォレストプロット。 |
著者
PyStatlas は Thierry Warin が作成・運営しています。データサイエンス、統計学、AI に関するその他の活動は www.warin.ca をご覧ください。
引用方法
PyStatlas は Thierry Warin が作成・運営しています。研究や業務に役立った場合は、ぜひ引用してください。
Warin, T. (2026). PyStatlas: A Python Gallery of Statistical Graphics for the Social Sciences. https://warint.github.io/pystatlas/
@misc{warin2026statlas,
author = {Warin, Thierry},
title = {PyStatlas: A Python Gallery of Statistical Graphics for the Social Sciences},
year = {2026},
howpublished = {\url{https://warint.github.io/pystatlas/}},
note = {Source code: https://github.com/warint/pystatlas}
}貢献する
plot.py を含むフォルダを追加し、python build.py を実行して、プルリクエストを送ってください。詳しくは CONTRIBUTING.md をご覧ください。
謝辞
PyStatlas は、オープンソースソフトウェア、オープンデータ、そして R コミュニティの成果の上に成り立っています。すべての例は、以下の成果を用いて、あるいはそれに着想を得て作られています。
例で使用している Python パッケージ
NumPy · pandas · Matplotlib · seaborn · SciPy · statsmodels · scikit-learn · lifelines · SHAP · GeoPandas · libpysal · esda
データセット
着想を得たプロジェクト
- The R Graph Gallery (Yan Holtz)
- ggstatsplot (Indrajeet Patil) —
ggbetweenstats(),ggwithinstats(),ggbarstats(),ggcorrmat(),ggscatterstats() - ggstats (Joseph Larmarange) —
gglikert(),stat_prop(),ggtable(),ggcoef_model(),ggcoef_compare() - ggdist (Matthew Kay) and ggrain (Nicholas Judd, Jordy van Langen) —
stat_halfeye(),geom_rain() - ggridges (Claus O. Wilke) —
geom_density_ridges() - survminer and factoextra (Alboukadel Kassambara) —
ggsurvplot(),ggforest(),ggadjustedcurves(),fviz_pca_biplot(),fviz_eig(),fviz_silhouette() - dabestr (Joses W. Ho and colleagues) —
dabest() - performance, easystats (Daniel Lüdecke and colleagues) —
check_model() - metafor (Wolfgang Viechtbauer) —
forest(),funnel(),regtest() - GGally (Barret Schloerke, Di Cook) —
ggpairs() - corrplot (Taiyun Wei, Viliam Simko) —
corrplot() - SHAP (Scott Lundberg and Su-In Lee, 2017) and shapviz (Michael Mayer) —
sv_importance(),sv_dependence(),sv_waterfall() - spdep (Roger Bivand) and GeoDa / rgeoda (Luc Anselin, Xun Li) —
poly2nb(),moran.plot(),moran.mc(),localmoran_perm(),sp.correlogram(),local_moran() - vip and pdp (Brandon Greenwell, Bradley Boehmke) and tidymodels' yardstick —
vip(),partial(),conf_mat(),pr_curve()
例が再現している R パッケージ
BlandAltmanLeh · blandr · boot · car · caret · ComplexHeatmap · corrplot · dabestr · factoextra · feasts · forecast · GGally · ggdist · ggeffects · ggplot2 · ggpubr · ggrain · ggridges · ggstats · ggstatsplot · iml · interactions · marginaleffects · meta · metafor · pdp · performance · pheatmap · probably · pROC · pwr · qqplotr · quantreg · rgeoda · rms · shapviz · spdep · survminer · TeachingDemos · tune · vcd · vip · yardstick
サイトの構築
PyYAML · Pygments · Pillow · GitHub Pages
データの出典
ほぼすべての例は公表済みのデータを使い、statsmodels、lifelines、R の metafor が配布する形のまま再現しています。シミュレーションによる 2 つの例はその旨を明示しています。各項目には、元の文献、ギャラリーにデータが入る経路、そのデータを使うグラフを示します。
- American National Election Study, 1996. Rosenstone, S. J., Kinder, D. R., Miller, W. E., & the National Election Studies. (2016). ANES 1996 Time Series Study (ICPSR 6896; Version 6) [Data set]. Inter-university Consortium for Political and Social Research. https://doi.org/10.3886/ICPSR06896.v6
Subset of 944 respondents distributed with statsmodels (sm.datasets.anes96); public domain.
使用しているグラフ: 指標付き混同行列, 交互作用プロット, テューキーの HSD 区間, 群別の積み上げ割合, 95% 信頼区間の意味 - California STAR test results, 1998 (303 school districts). Gill, J. (2001). Generalized Linear Models: A Unified Approach (Quantitative Applications in the Social Sciences, No. 134). Sage. https://www.statsmodels.org/stable/datasets/generated/star98.html
Original data from the California Department of Education's Standardized Testing and Reporting (STAR) program, 1998. Subset distributed with statsmodels (sm.datasets.star98) with the author's permission.
使用しているグラフ: 交差検証によるモデル比較, 置換重要度, ICE 曲線付き部分依存プロット, SHAP サマリー(ビースウォーム), SHAP 依存プロット, 1 件の予測に対する SHAP ウォーターフォール, 群間比較, 統計量付き散布図, 相関係数付きペアプロット, クラスタリング付きコレログラム, 入れ子モデルの比較, 交互作用効果, スクリープロット - US state crime and social indicators, 2009. U.S. Census Bureau. Statistical Abstract of the United States, state tables for 2009 (crime rates from the FBI Uniform Crime Reporting program). https://www.statsmodels.org/stable/datasets/generated/statecrime.html
Compiled for statsmodels (sm.datasets.statecrime); public domain. See the statsmodels page for each variable's table and footnotes.
使用しているグラフ: 推定プロット, 相関行列, 係数プロット, 残差診断, 影響度プロット, 追加変数プロット, PCA バイプロット, k-means のシルエットプロット, クラスター化ヒートマップ, ブートストラップ分布 - Redbook survey of married women, 1974 (Fair's affairs data). Fair, R. C. (1978). A theory of extramarital affairs. Journal of Political Economy, 86(1), 45–61. https://doi.org/10.1086/260646
Data from the 1974 Redbook magazine survey; distributed with statsmodels (sm.datasets.fair) with the author's permission.
使用しているグラフ: 適合率–再現率曲線, 学習曲線, ピアソン残差付きモザイクプロット, 信頼区間付きの割合, 標準化残差付きクロス集計表, オッズ比のフォレストプロット, ROC 曲線, キャリブレーションプロット - World Bank fertility rates by country, 1960–2013. World Bank. Fertility rate, total (births per woman), indicator SP.DYN.TFRT.IN. World Development Indicators. https://data.worldbank.org/indicator/SP.DYN.TFRT.IN
Primary sources: UN Population Division, UN Statistical Division, national statistical offices, Eurostat and others. Distributed with statsmodels (sm.datasets.fertility) under the World Bank terms of use.
使用しているグラフ: 密度曲線付きヒストグラム, リッジラインプロット, 被験者内比較 - Engel's Belgian household budgets (235 families). Koenker, R., & Bassett, G. (1982). Robust tests for heteroscedasticity based on regression quantiles. Econometrica, 50(1), 43–61. https://doi.org/10.2307/1912528
Engel's (1857) household budget data as used by Koenker and Bassett and distributed with R's quantreg; in statsmodels as sm.datasets.engel; public domain.
使用しているグラフ: 信頼帯付き Q–Q プロット, 分位点回帰プロセス - Spector and Mazzeo's teaching-method experiment (32 students). Spector, L. C., & Mazzeo, M. (1980). Probit analysis and economic education. Journal of Economic Education, 11(2), 37–44. https://www.statsmodels.org/stable/datasets/generated/spector.html
Obtained from W. Greene's Econometric Analysis web site with the original author's permission; distributed with statsmodels (sm.datasets.spector).
使用しているグラフ: 予測確率 - US quarterly macroeconomic series, 1959–2009. Federal Reserve Bank of St. Louis. FRED, Federal Reserve Economic Data; U.S. Bureau of Labor Statistics (unemployment rate). Accessed December 15, 2009. https://fred.stlouisfed.org/
Compiled by Skipper Seabold for statsmodels (sm.datasets.macrodata); public domain.
使用しているグラフ: ACF と PACF - Euro-area electrical-equipment turnover, monthly, 1995–2016. Eurostat. Euro area (18, fixed composition) total turnover index, manufacture of electrical equipment (NACE Rev. 2), working-day adjusted, not seasonally adjusted. https://ec.europa.eu/eurostat
Distributed with statsmodels (statsmodels.datasets.elec_equip); public domain.
使用しているグラフ: STL 分解, SARIMA 予測, 季節サブシリーズプロット - Democracy and Dictatorship: leader spells, 1946–2008. Cheibub, J. A., Gandhi, J., & Vreeland, J. R. (2010). Democracy and dictatorship revisited. Public Choice, 143(1–2), 67–101. https://doi.org/10.1007/s11127-009-9491-2
202 countries; distributed with lifelines (lifelines.datasets.load_dd).
使用しているグラフ: レインクラウドプロット, カプラン・マイヤー曲線, 累積ハザード - Rossi recidivism experiment (432 released prisoners). Rossi, P. H., Berk, R. A., & Lenihan, K. J. (1980). Money, Work, and Crime: Some Experimental Results. Academic Press. https://lifelines.readthedocs.io/en/latest/lifelines.datasets.html
Men released from Maryland state prisons in the 1970s, half randomly assigned to financial aid. Distributed with lifelines (lifelines.datasets.load_rossi).
使用しているグラフ: ECDF の比較, Cox モデルのハザード比, 調整済み生存曲線 - Teacher-expectancy experiments (Raudenbush, 1984). Raudenbush, S. W. (1984). Magnitude of teacher expectancy effects on pupil IQ as a function of the credibility of expectancy induction: A synthesis of findings from 18 experiments. Journal of Educational Psychology, 76(1), 85–97. https://doi.org/10.1037/0022-0663.76.1.85
Effect sizes and variances typed in from dat.raudenbush1985 in R's metadat/metafor (Viechtbauer, 2010, Journal of Statistical Software, 36(3), https://doi.org/10.18637/jss.v036.i03); one of the 18 experiments contributes two rows.
使用しているグラフ: メタアナリシスのフォレストプロット, ファンネルプロット - 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.
使用しているグラフ: 発散型リッカートチャート, ブランド・アルトマンプロット - Guerry's moral statistics of France, c. 1830 (85 départements). Guerry, A.-M. (1833). Essai sur la statistique morale de la France. Crochard. Data as compiled in Friendly, M. (2007). A.-M. Guerry's moral statistics of France: Challenges for multivariable spatial analysis. Statistical Science, 22(3), 368–399. https://doi.org/10.1214/07-STS241
Prepared by the Center for Spatial Data Science (University of Chicago) from the R package Guerry (Friendly and Dray), provided “as is”. Fetched once and cached by libpysal (examples.load_example("Guerry")). Variables come from Guerry's tables as translated by Whitt and Reinking (2002).
使用しているグラフ: 空間重み付きコロプレス図, モラン散布図(大域的自己相関), LISA クラスター地図(局所的自己相関), 空間コレログラム
これらの例は統計手法を説明するためのものです。図のタイトルは、この特定のデータ(多くは小規模で、古く、部分的な標本)で図が示す内容を述べたものであり、実質的な問いに対する著者の立場ではありません。解釈、背景、データの質については、ここに挙げた元の出典を参照してください。