影響度プロット
スチューデント化残差対てこ比を、クックの距離に応じた大きさのバブルで描きます。

観測値は、説明変数の値が特異であり(てこ比が高い、x軸)、かつ当てはまりが悪い(スチューデント化残差が大きい、y軸)とき、影響力が大きい といえます。バブルの面積は両者を組み合わせたクックの距離とともに大きくなります(極端な値でも読みやすいよう √D に比例)。破線は一般的な目安であるてこ比 2p/n と 3p/n、スチューデント化残差 ±2 を示し、クックの D が 4/n を超える観測値には名前と色を付けています。
設定は Warin & Stojkov (2021, Journal of Risk and Financial Management) による、2008 年の危機後の銀行の対外債権の研究です。データは説明のために シミュレーション したもので、論文のデータや結果ではありません。n = 36 の欧州および OECD 諸国で、各国に対する外国銀行の債権(10 億米ドルの対数)を、GDP の対数、金融深化、貿易開放度、ユーロ圏加盟で説明しています。プロットに見つけるべきものがあるよう、いくつかの金融センターには特異な説明変数や債権の値を与えています。スチューデント化(削除)残差、てこ比、クックの距離は statsmodels の model.get_influence() から求め、サブタイトルでは car::outlierTest() と同様に、最大の残差をボンフェローニの外れ値検定で確認しています。
コードおよび図中のテキストは英語です。
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import statsmodels.formula.api as smf
from scipy import stats
# Simulated data, set in the context of Warin & Stojkov (2021) [warin2021banks]
# Data: 36 countries; foreign bank claims from size, depth, openness and the euro
rng = np.random.default_rng(2021)
names = ["Austria", "Belgium", "Cyprus", "Estonia", "Finland", "France", "Germany", "Greece",
"Ireland", "Italy", "Latvia", "Lithuania", "Luxembourg", "Malta", "Netherlands",
"Portugal", "Slovakia", "Slovenia", "Spain", "Bulgaria", "Croatia", "Czechia",
"Denmark", "Hungary", "Poland", "Romania", "Sweden", "Norway", "Switzerland",
"United Kingdom", "Iceland", "Canada", "United States", "Japan", "Australia", "Turkey"]
n = len(names)
df = pd.DataFrame({"log_gdp": rng.normal(6, 1.2, n), "depth": rng.normal(100, 30, n),
"openness": rng.normal(90, 30, n),
"euro": [1] * 19 + [0] * 17}, index=names)
df.loc["Luxembourg", ["depth", "openness"]] = [300, 260] # tiny economy, huge banks
df.loc["Malta", "openness"] = 230
df["claims"] = (-2 + 0.9 * df.log_gdp + 0.004 * df.depth + 0.003 * df.openness
+ 0.5 * df.euro + rng.normal(0, 0.45, n))
df.loc[["Ireland", "Cyprus", "Luxembourg"], "claims"] += [1.6, 2.2, -1.6]
model = smf.ols("claims ~ log_gdp + depth + openness + euro", data=df).fit()
infl = model.get_influence()
rstud, lev, cook = infl.resid_studentized_external, infl.hat_matrix_diag, infl.cooks_distance[0]
n, p = int(model.nobs), int(model.df_model + 1)
flag = cook > 4 / n
fig, ax = plt.subplots(figsize=(8.5, 5.6))
# Rule-of-thumb thresholds
for h in (2 * p / n, 3 * p / n):
ax.axvline(h, color="#AEAEB2", lw=1, ls="--", zorder=0)
ax.text(h, 1.0, f" {round(h * n / p)}p/n", transform=ax.get_xaxis_transform(),
fontsize=8.5, color="#8E8E93", va="top")
for r in (-2, 0, 2):
ax.axhline(r, color="#AEAEB2" if r else "#C7C7CC", lw=1, ls="--" if r else "-", zorder=0)
# Bubbles: area proportional to √Cook's D (keeps extreme points readable)
area = lambda d: 20 + 700 * np.sqrt(d)
size = area(cook)
ax.scatter(lev[~flag], rstud[~flag], s=size[~flag], color="#007AFF", alpha=0.35,
edgecolor="#007AFF", lw=0.8)
ax.scatter(lev[flag], rstud[flag], s=size[flag], color="#FF3B30", alpha=0.35,
edgecolor="#FF3B30", lw=1.2)
for i in np.flatnonzero(flag):
right = lev[i] > 0.7 * lev.max() # far-right points: label on the left
ax.annotate(f"{df.index[i]}\nD = {cook[i]:.2f}", (lev[i], rstud[i]),
xytext=((-1 if right else 1) * (np.sqrt(size[i]) / 2 + 6), 0),
textcoords="offset points", ha="right" if right else "left", va="center",
fontsize=8.5, color="#3A3A3C", linespacing=1.1)
# Bubble-size key
for d, x in zip((0.1, 0.5, 1, 2), (0.745, 0.79, 0.84, 0.90)):
ax.scatter(x, 0.86, s=area(d), transform=ax.transAxes, color="none",
edgecolor="#8E8E93", lw=0.8)
ax.text(x, 0.77, f"{d:g}", transform=ax.transAxes, ha="center", fontsize=8.5, color="#6E6E73")
ax.text(0.82, 0.97, "Cook's D", transform=ax.transAxes, ha="center", va="top",
fontsize=8.5, color="#6E6E73")
ax.set_ylim(rstud.min() - 0.8, rstud.max() + 1.2)
ax.set_xlim(0, lev.max() * 1.15)
ax.set_xlabel("Leverage (hat value)")
ax.set_ylabel("Studentized residual")
ax.set_title(f"{flag.sum()} countries cross the Cook's D > 4/n line in a simulated model of bank claims", pad=26)
# Bonferroni outlier test on the largest |studentized residual|
k = np.argmax(np.abs(rstud))
p_bonf = min(1, n * 2 * stats.t.sf(abs(rstud[k]), model.df_resid - 1))
ax.text(0, 1.02, f"OLS log claims ~ 4 predictors · n = {n} countries (simulated) · {flag.sum()} with Cook's D > 4/n · "
f"largest |t*| = {abs(rstud[k]):.2f} ({df.index[k]}), Bonferroni p = {p_bonf:.3f}",
transform=ax.transAxes, fontsize=9.5, color="#6E6E73")
plt.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. - Warin & Stojkov (2021), banks' foreign claims after the 2008 crisis. Warin, T., & Stojkov, A. (2021). Banks' foreign claims in the aftermath of the 2008 crisis: Institutional response, financial efficiency, and integration of cross-border banking in the euro area. Journal of Risk and Financial Management, 14(2), 61. https://doi.org/10.3390/jrfm14020061
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). Influence plot. In PyStatlas: A Python Gallery of Statistical Graphics for the Social Sciences (Version 1.1.0) [Computer software]. https://warin.ca/pystatlas/model-diagnostics/influence-plot/
@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}
}モデル診断のその他のグラフ
残差診断
線形モデルのための定番の 2 × 2 パネル。線形性、正規性、分散、てこ比を確認します。
plot(lm) / performance::check_model()ROC 曲線
3つの分類器を ROC 曲線、ブートストラップ 95% 信頼区間付きの AUC、ユーデン点で比較します。
pROC::ggroc() / pROC::ci.auc()キャリブレーションプロット
十分位ごとの予測リスク対観測リスクを、ウィルソン信頼区間、予測値のヒストグラム、ブライアスコアとともに示します。
rms::calibrate() / probably::cal_plot_breaks()