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?

統計学における期待値

Posted at

以下の統計検定2級対策動画で用いられているスライドの一部です。

具体例から始めよう:パン屋の販売個数

あるパン屋の特別なクリームパンについて、1日の販売個数 $X$ は以下の確率分布に従います。

このパンは、1日あたり平均で何個売れると期待できるでしょうか?

販売個数 (x) 10 20 30 40
確率 P(X=x) 0.1 0.4 0.3 0.2

「期待値」とは?

確率変数がとりうる値について、 確率の重みを考慮した平均値 のこと。

  • 多くの試行を繰り返したときに得られるであろう、 結果の平均 を示します。
  • パン屋の例で言えば、「毎日パンを売り続けた場合、1日あたり平均で何個売れるか」という値です。

このパンの販売個数のように、値が飛び飛びになる確率変数を 離散型確率変数 と呼びます。


期待値の計算方法(離散型)

期待値は、 「確率変数のとりうる値」「その値をとる確率」 の積を、すべての値について合計して求めます。

計算手順 1/2: 各値と確率を掛け合わせる

  • 10個売れる場合: $10 \times 0.1 = 1.0$
  • 20個売れる場合: $20 \times 0.4 = 8.0$
  • 30個売れる場合: $30 \times 0.3 = 9.0$
  • 40個売れる場合: $40 \times 0.2 = 8.0$

期待値の計算方法(離散型)

計算手順 2/2: すべての値を合計する

$$
E(X) = (10 \times 0.1) + (20 \times 0.4) + (30 \times 0.3) + (40 \times 0.2)
$$

$$
E(X) = 1.0 + 8.0 + 9.0 + 8.0 = 26.0
$$

結論

このクリームパンの1日あたりの販売個数の期待値は 26個 です。


確率分布の可視化

image.png


import matplotlib.pyplot as plt
# import japanize_matplotlib  <- この行を削除またはコメントアウト

# Data for the bar chart
sales_counts = [10, 20, 30, 40]
probabilities = [0.1, 0.4, 0.3, 0.2]

# Create bar chart
plt.figure(figsize=(8, 6))
plt.bar(sales_counts, probabilities, width=5, color='skyblue', edgecolor='black')

# Add titles and labels in English
plt.title('Probability Distribution of Bread Sales')
plt.xlabel('Number of Sales (x)')
plt.ylabel('Probability P(X=x)')
plt.xticks(sales_counts)
plt.grid(axis='y', linestyle='--', alpha=0.7)

# Display the plot
plt.show()

次の例:機械部品の寿命

次に、別の種類の問題を考えてみましょう。

ある機械部品の寿命を $X$ (単位: 年)とします。この部品の寿命は、以下の 確率密度関数 $f(x)$ に従うことが分かっています。

この部品の寿命の期待値は、何年でしょうか?

$$
f(x) =
\begin{cases}
\frac{1}{18}x & (0 \le x \le 6) \
0 & (\text{otherwise})
\end{cases}
$$


連続型確率変数

  • 時間や長さのように、ある範囲内の任意の実数値をとることができる確率変数を 連続型確率変数 と呼びます。
  • パンの個数と違い、値が連続的です。
  • 連続型の場合、「寿命がちょうど3.11111...年」という特定の値をとる確率は0になるため、 確率密度関数 $f(x)$ を使って考えます。

期待値の計算方法(連続型)

離散型では「値 × 確率」の 総和( $\sum$ ) で計算しました。

連続型では、これを 積分( $\int$ ) に置き換えて計算します。

「確率変数の値 $x$ 」と「確率密度関数 $f(x)$ 」の積を、定義されている全範囲で積分します。


期待値の計算手順(連続型)

手順 1/3: 期待値の式に代入する

確率密度関数が値を持つのは $0 \le x \le 6$ の範囲なので、積分範囲もそれに合わせます。

$$
E(X) = \int_{0}^{6} x \cdot f(x) dx = \int_{0}^{6} x \cdot \left(\frac{1}{18}x\right) dx
$$


期待値の計算手順(連続型)

手順 2/3: 式を整理して積分する

$$
E(X) = \int_{0}^{6} \frac{1}{18}x^2 dx
$$

定数 $\frac{1}{18}$ を積分の外に出します。

$$
E(X) = \frac{1}{18} \int_{0}^{6} x^2 dx
$$

$x^2$ を積分すると $\frac{1}{3}x^3$ なので、

$$
E(X) = \frac{1}{18} \left[ \frac{1}{3}x^3 \right]_{0}^{6}
$$


期待値の計算手順(連続型)

手順 3/3: 定積分を計算する

$$
E(X) = \frac{1}{18} \left( \frac{1}{3} \cdot 6^3 - \frac{1}{3} \cdot 0^3 \right)
$$

$$
E(X) = \frac{1}{18} \left( \frac{216}{3} \right) = \frac{1}{18} \cdot 72 = 4
$$

結論

この機械部品の寿命の期待値は 4年 です。


確率密度関数の可視化

image.png


import matplotlib.pyplot as plt
import numpy as np
# import japanize_matplotlib  <- この行を削除またはコメントアウト

# Define the range for x
x = np.linspace(0, 6, 400)
# Define the probability density function
y = (1/18) * x

# Create the plot
plt.figure(figsize=(8, 6))
plt.plot(x, y, label='f(x) = (1/18)x')
plt.fill_between(x, y, color='skyblue', alpha=0.4)

# Add titles and labels in English
plt.title('Probability Density Function of Component Lifespan')
plt.xlabel('Lifespan in Years (x)')
plt.ylabel('Density f(x)')
plt.grid(True)
plt.legend()
plt.ylim(bottom=0)

# Display the plot
plt.show()

まとめ:期待値の特徴

ここまでの具体例を踏まえ、期待値の特徴を一般化します。

期待値 $E(X)$ とは、確率変数がとる値の、 確率の重みを考慮した平均値 です。

確率変数が 「離散型」「連続型」 かによって計算方法が異なります。


離散型 確率変数の期待値

  • 特徴: 値が飛び飛びになる確率変数(例:サイコロの目、販売個数)。
  • 公式:
    • 確率変数がとりうる値を $x_i$
    • それぞれの確率を $P(X=x_i)$ とすると、期待値は以下の 総和 で計算されます。

$$
E(X) = \sum_{i=1}^{n} x_i P(X=x_i)
$$


連続型 確率変数の期待値

  • 特徴: ある範囲内の任意の実数値をとる確率変数(例:時間、長さ、重さ)。
  • 公式:
    • 確率密度関数を $f(x)$ とすると、期待値は以下の 積分 で計算されます。

$$
E(X) = \int_{-\infty}^{\infty} x f(x) dx
$$


なぜ期待値が重要なのか?

  • 要約: 期待値は、複雑な確率分布の特性を 「平均的にどのくらいの値か」 という一つの数値で要約してくれます。
  • 基礎: 統計学で学ぶ「分散」や、より高度な統計解析の基礎となる、非常に重要な概念です。

まずはこの計算方法をしっかりと身につけましょう。

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?