Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

確率分布の性質

再生性

確率変数の和が同じ確率分布になることを再生性という。

例えば、N(μ1,σ12)N(\mu_1, \sigma_1^2)の正規分布に従う確率変数とN(μ2,σ22)N(\mu_2, \sigma_2^2)の正規分布に従う確率変数の和は、N(μ1+μ2,σ12+σ22)N(\mu_1 + \mu_2, \sigma_1^2 + \sigma_2^2)の正規分布に従う。

Source
import matplotlib.pyplot as plt
import japanize_matplotlib
from scipy.stats import norm

x = norm.rvs(loc=10, scale=2, size=100, random_state=0)
y = norm.rvs(loc=25, scale=5, size=100, random_state=0)

def info(x):
    return f"mean={x.mean():.1f}, std={x.std():.1f}, n={len(x)}"
    

fig, axes = plt.subplots(nrows=3)
fig.subplots_adjust(hspace=0.6)
axes[0].hist(x, label=f"x: {info(x)}", alpha=.5)
axes[0].hist(y, label=f"y: {info(y)}", alpha=.5)
axes[0].set(title=r"Raw data: $x \sim N(\mu=10, \sigma=2), y \sim N(\mu=25, \sigma=5)$")
axes[0].legend()


# もしレコードを結合するなら、2峰の分布になる
import numpy as np
a = np.append(x, y)
axes[1].hist(a, label=f"a: {info(a)}", alpha=.5)
axes[1].legend()
axes[1].set(title=f"Distribution of $a = [x, y]$ (concatenated samples)")


# レコードを結合するのではなく、サンプルごとに和をとっている点に注意
z = x + y
axes[2].hist(z, label=f"z: {info(z)}", alpha=.5)
axes[2].legend()
axes[2].set(title=f"Distribution of $z = x + y$")

fig.show()

<Figure size 640x480 with 3 Axes>