0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

二項分布と負の二項分布の違いを一枚の図で表してみる

Last updated at Posted at 2025-11-18

fig1.png

上の図は二項分布 (binomial distribution) と負の二項分布 (negative binomial distribution) の違いを表したものです。名前だけ見ると真逆っぽいですが、実は よく似た形 をしています。平均 $\mu$ を揃えた場合、二項分布は分散 $\sigma^2$ が小さく、負の二項分布は分散 $\sigma^2$ が大きい という違いがあります。両者の中間に位置するのがポアソン分布 (Poisson distribution) で、平均 $\mu$ と分散 $\sigma^2$ が一致しています。

なお、分散が予想より大きいことを過分散 (overdispersion) と呼びます。負の二項分布は、ポアソン分布を仮定した場合よりも分散が大きいため、過分散と呼ばれることがあります。

分散の違いは、以下の表を見ると分かりやすいです。

名前 パラメータ $p(x)$ $\mu$ $\sigma^2$ $\displaystyle \frac{\sigma^2}{\mu}$
二項分布 $n,\ p$ $\dbinom{n}{x}p^x(1-p)^{n-x}$ $np$ $np(1-p)$ $1-p<1$
負の二項分布 $r,\ p$ $\dbinom{r+x-1}{x}(1-p)^xp^r$ $\displaystyle \frac{r(1-p)}{p}$ $\displaystyle \frac{r(1-p)}{p^2}$ $\displaystyle \frac{1}{p}>1$

それぞれ2つパラメータを持つので、平均 $\mu$ を固定したとき、分散 $\sigma^2$ をある程度自由に動かせます。ただし、一番右の列の $\sigma^2/\mu$ を見ると分かるように、二項分布では必ず分散 $\sigma^2$ が平均 $\mu$ より小さくなり、負の二項分布では必ず分散 $\sigma^2$ が平均 $\mu$ より大きくなります。

平均を固定した場合、二項分布の $p\to 0$ の極限と、負の二項分布の $p\to 1$ の極限が一致し、ポアソン分布になります。その意味で、二項分布と負の二項分布は、連続的に繋がっている仲間同士の分布といえます。

以上は二項分布と負の二項分布の形の違いでした。各パラメータの違いについても以下の表にまとめておきます。コインを複数回投げる場合を例に説明します。

分布 表が出る確率 合計回数 表の回数 裏の回数
二項分布 固定 ($p$) 固定 ($n$) 可変 ($x$) 可変 ($n-x$)
負の二項分布 固定 ($p$) 可変 ($r+x$) 固定 ($r$) 可変 ($x$)

コインを合計 $n$ 回投げたときの表の回数 $x$ の従う分布が二項分布です。一方、表がちょうど $r$ 回出るまでコインを投げ続けたときの裏の回数 $x$ の従う分布が負の二項分布です。つまり、固定する変数が違います。

直感的にも、負の二項分布では、運が悪ければ無限にコインを投げ続けなければならないので、分散が大きくなる点に納得がいくかと思います。

最後に、図を作成したpythonのコードを以下に載せておきます。パラメータは割といい加減です。

import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from scipy import stats
sns.set_context('notebook', font_scale=1.2)

def test_binom():
  mu = 10
  x_arr = np.arange(41)
  fig, ax = plt.subplots(figsize=(6,4))

  # binomial
  for i, n in enumerate([15, 20, 30, 50]):
    p = mu / n
    alpha = 1 - i/4
    ax.plot(stats.binom(n,p).pmf(x_arr), '.-', c='C0', alpha=alpha)

  # poisson
  ax.plot(stats.poisson(mu).pmf(x_arr), 'o-', c='0.2', lw=3)

  # negative binomial
  for i, r in enumerate([3, 5, 10, 20]):
    p =  r / (mu + r)
    alpha = 1 - i/4
    ax.plot(stats.nbinom(r,p).pmf(x_arr), '.-', c='C3', alpha=alpha)

  kws = dict(transform=ax.transAxes)
  ax.text(0.4, 0.8, 'Binomial: $\mu>\sigma^2$', c='C0', **kws)
  ax.text(0.4, 0.7, 'Poisson: $\mu=\sigma^2$', c='0.2', **kws)
  ax.text(0.4, 0.6, 'Negative binomial: $\mu<\sigma^2$', c='C3', **kws)
  ax.set_xlabel('$x$')
  ax.set_ylabel('$p(x)$')
  fig.tight_layout()
  fig.show()
  fig.savefig('tmp.png')
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?