#05 ふれてみよう高校数学 確率・統計

条件付き確率とベイズの定理

条件付き確率とは

「今日は曇り空だ。この場合、午後に雨が降る確率は?」——「曇り空という情報を持っている」ときの雨の確率は、何も情報がないときとは違います。このように「ある情報(条件)を得た後の確率」が条件付き確率です。

「Aが起こった」という情報を得た後に、「Bが起こる確率」はどうなるでしょうか?

P(BA)=P(AB)P(A)(P(A)>0)P(B \mid A) = \frac{P(A \cap B)}{P(A)} \quad (P(A) > 0)

これを条件付き確率(conditional probability)といいます。

直感的な理解: AとBのベン図で、「Aの円の中だけ」を新しい標本空間と考えたとき、そこにBがどれだけ含まれるか——がP(B|A)です。「Aが確定した世界の中で、Bの割合がどのくらいか」という見方です。


具体例

袋に赤玉4個・白玉6個が入っています。2回連続で取り出す(戻さない)。

1回目が赤だったとき、2回目も赤の確率は?

「1回目に赤を取り出した後、袋には赤3個・白6個が残っている」——状況が変わるので改めて計算します:

P(2回目赤1回目赤)=39=13P(\text{2回目赤} \mid \text{1回目赤}) = \frac{3}{9} = \frac{1}{3}


ベイズの定理

「検査で陽性だった。本当に病気である確率は?」——「結果を見てから原因の確率を求める」これがベイズの定理の使い場所です。

ベイズの定理は「結果を見てから原因の確率を求める」ときに使います。

P(AB)=P(BA)P(A)P(B)P(A \mid B) = \frac{P(B \mid A)\,P(A)}{P(B)}

分母 P(B)P(B) は全確率の法則で展開できます:

P(B)=P(BA)P(A)+P(BAˉ)P(Aˉ)P(B) = P(B \mid A)\,P(A) + P(B \mid \bar{A})\,P(\bar{A})

「原因がA(病気)の場合と、原因がAではない(健康)の場合の両方から、Bという結果(陽性)が出る可能性を合計する」——全部の経路を足し合わせます。


医療検査の例

設定:

  • 病気の有病率(base rate):P(D)=0.01P(D) = 0.01(1%)
  • 検査の感度(sensitivity):P(+D)=0.95P(+\mid D) = 0.95(病気なのに陽性が出る確率)
  • 検査の特異度(specificity):P(Dˉ)=0.90P(-\mid \bar{D}) = 0.90(健康なのに陰性が出る確率)

問い: 陽性反応が出たとき、本当に病気である確率 P(D+)P(D \mid +) は?

P(+)=0.95×0.01+0.10×0.99=0.0095+0.099=0.1085P(+) = 0.95 \times 0.01 + 0.10 \times 0.99 = 0.0095 + 0.099 = 0.1085

P(D+)=0.00950.10850.08768.8%P(D \mid +) = \frac{0.0095}{0.1085} \approx 0.0876 \approx 8.8\%

有病率が1%しかない場合、陽性でも本当に病気の確率は9%未満——これは多くの人が直感に反すると感じる結果です。「陽性反応が出たのに、病気じゃない可能性が91%もある?」——健康な人が多すぎるので、「偽陽性(健康なのに陽性)」の数が多くなってしまうのです。


確率樹形図デモ

ベイズ定理の確率樹形図:マウスを左右に動かして有病率を変え、陽性的中率の変化を確認
function loop() {
ctx.clearRect(0, 0, W, H);

var prevalence = 0.001 + (mx / W) * 0.199;
var sensitivity = 0.95;
var fpr = 0.10;

var pD = prevalence;
var pNd = 1 - pD;
var pPosGivenD = sensitivity;
var pPosGivenNd = fpr;

var pDandPos = pD * pPosGivenD;
var pDandNeg = pD * (1 - pPosGivenD);
var pNdandPos = pNd * pPosGivenNd;
var pNdandNeg = pNd * (1 - pPosGivenNd);

var pPos = pDandPos + pNdandPos;
var ppv = pPos > 0 ? pDandPos / pPos : 0;

var rootX = 60, rootY = H / 2;
var mid1X = 220, endX = 430;

function drawLine(x1, y1, x2, y2, color, width) {
  ctx.strokeStyle = color;
  ctx.lineWidth = width || 1.5;
  ctx.beginPath();
  ctx.moveTo(x1, y1);
  ctx.lineTo(x2, y2);
  ctx.stroke();
}

function drawNode(x, y, color, label, sublabel) {
  ctx.fillStyle = color;
  ctx.beginPath();
  ctx.arc(x, y, 8, 0, Math.PI * 2);
  ctx.fill();
  ctx.fillStyle = '#e2e8f0';
  ctx.font = '12px sans-serif';
  ctx.textAlign = 'left';
  if (label) ctx.fillText(label, x + 12, y + 4);
  ctx.fillStyle = '#94a3b8';
  ctx.font = '11px monospace';
  if (sublabel) ctx.fillText(sublabel, x + 12, y + 18);
}

ctx.fillStyle = '#fbbf24';
ctx.beginPath();
ctx.arc(rootX, rootY, 10, 0, Math.PI * 2);
ctx.fill();
ctx.fillStyle = '#e2e8f0';
ctx.font = 'bold 12px sans-serif';
ctx.textAlign = 'center';
ctx.fillText('集団', rootX, rootY + 26);

var y_D = rootY - 85, y_Nd = rootY + 85;

drawLine(rootX, rootY, mid1X, y_D, '#f472b6', 2);
drawLine(rootX, rootY, mid1X, y_Nd, '#60a5fa', 2);

ctx.fillStyle = '#94a3b8';
ctx.font = '11px monospace';
ctx.textAlign = 'center';
ctx.fillText('P(D)=' + pD.toFixed(3), (rootX + mid1X) / 2 - 10, y_D - 10);
ctx.fillText('P(D̄)=' + pNd.toFixed(3), (rootX + mid1X) / 2 - 10, y_Nd + 16);

drawNode(mid1X, y_D, '#f472b6', '病気', 'P=' + pD.toFixed(3));
drawNode(mid1X, y_Nd, '#60a5fa', '健康', 'P=' + pNd.toFixed(3));

var y_DP = y_D - 40, y_DN = y_D + 40;
var y_NdP = y_Nd - 40, y_NdN = y_Nd + 40;

drawLine(mid1X, y_D, endX, y_DP, '#f472b6', 1.5);
drawLine(mid1X, y_D, endX, y_DN, '#475569', 1);
drawLine(mid1X, y_Nd, endX, y_NdP, '#ef4444', 1.5);
drawLine(mid1X, y_Nd, endX, y_NdN, '#475569', 1);

ctx.font = '10px monospace';
ctx.fillStyle = '#94a3b8';
ctx.textAlign = 'center';
ctx.fillText('感度 ' + sensitivity.toFixed(2), (mid1X + endX) / 2 - 5, y_DP - 8);
ctx.fillText((1 - sensitivity).toFixed(2), (mid1X + endX) / 2 - 5, y_DN + 14);
ctx.fillText('偽陽性 ' + fpr.toFixed(2), (mid1X + endX) / 2 - 5, y_NdP - 8);
ctx.fillText((1 - fpr).toFixed(2), (mid1X + endX) / 2 - 5, y_NdN + 14);

drawNode(endX, y_DP, '#f472b6', '+', pDandPos.toFixed(4));
drawNode(endX, y_DN, '#475569', '-', pDandNeg.toFixed(4));
drawNode(endX, y_NdP, '#ef4444', '+', pNdandPos.toFixed(4));
drawNode(endX, y_NdN, '#475569', '-', pNdandNeg.toFixed(4));

var infoX = 490;
ctx.fillStyle = '#e2e8f0';
ctx.font = 'bold 13px sans-serif';
ctx.textAlign = 'left';
ctx.fillText('有病率', infoX, 50);
ctx.fillStyle = '#fbbf24';
ctx.font = 'bold 18px monospace';
ctx.fillText((pD * 100).toFixed(1) + '%', infoX, 72);

ctx.fillStyle = '#e2e8f0';
ctx.font = 'bold 13px sans-serif';
ctx.fillText('陽性的中率', infoX, 110);
ctx.fillText('P(D|+)', infoX, 128);
ctx.fillStyle = ppv > 0.5 ? '#22c55e' : ppv > 0.2 ? '#f59e0b' : '#ef4444';
ctx.font = 'bold 22px monospace';
ctx.fillText((ppv * 100).toFixed(1) + '%', infoX, 155);

ctx.fillStyle = '#64748b';
ctx.font = '11px sans-serif';
ctx.fillText('← マウスで有病率変化', infoX, 190);

requestAnimationFrame(loop);
}
loop();

ベイズ更新の直感

マウスを動かして有病率を変えると、陽性的中率が大きく変化することが分かります。

  • 有病率が低い(1%以下):陽性でも実際に病気の確率は10%未満——「病気の人が少ないので、陽性の大半は健康な人の偽陽性」
  • 有病率が10%:陽性的中率は50%程度に上昇——「病気の人が増えると、陽性の信頼性も上がる」
  • 有病率が高い(50%):陽性なら90%以上が本当の病気——「もともと病気の人が多いので陽性はほぼ確実」

これが「ベースレートの無視」という認知バイアスで、多くの人が直感的に過大評価してしまう部分です——「精度95%の検査で陽性 = ほぼ確実に病気」と思いがちですが、有病率が低ければそうではありません。


ベイズの定理の重要性

日常生活でもベイズの定理は活躍しています——「新しい情報が入ったとき、確率をどう更新するか」という思考法です。

分野応用例
医学検査結果の解釈、診断支援
スパムフィルタメールがスパムかどうかの判定
機械学習ナイーブベイズ分類器
法廷DNA証拠の解釈

まとめ

  • 条件付き確率P(BA)=P(AB)P(A)P(B \mid A) = \frac{P(A \cap B)}{P(A)}——「Aの世界の中でBの割合」
  • ベイズの定理P(AB)=P(BA)P(A)P(B)P(A \mid B) = \frac{P(B \mid A)\,P(A)}{P(B)}——「結果から原因の確率を逆算」
  • 医療検査では有病率(ベースレート)が陽性的中率に大きく影響する——「検査精度だけで判断してはいけない」
  • 「陽性 = 病気」という直感は有病率が低い場合には正しくない——「ベースレートを常に考慮する」

次回は独立な試行——コインを何度も投げるような、各回が独立した実験の確率を学びます。