0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Rを学びたい Step21 幾何分布

Posted at

はじめに

Rを学びたのStep21です。今回は幾何分布に関して学んでいきます。

幾何分布って何??

幾何分布とは、ベルヌーイ試行(成功または失敗しかない独立した試行)が繰り返される中で、初めて成功するまでの試行回数を記述します。

例えば:
  ・コインを投げて表が出るまでの回数
 ・ダイスを振って「1」が出るまでの回数

\begin{align*}
P(X = k) &= (1-p)^{k-1} p \quad \text{(幾何分布の確率質量関数)} \\

k & : \text{成功する試行の回数} \quad (k = 1, 2, 3, \dots) \\
p & : \text{各試行における成功確率} \\
1-p & : \text{失敗の確率} \\
\\
(1-p)^{k-1} & : \text{最初の } k-1 \text{ 回は失敗する確率} \\
p & : k \text{-回目で初めて成功する確率。}
\end{align*}

Rで学ぶ。

あるコインを投げたとき、表が出る確率は p = 0.3 です。このコインを何回か投げて、初めて表が出るまでの試行回数を考えます。この試行回数は幾何分布に従うとする。この時の幾何分布と累積分布関数(CDF)をplotしなさい。

# Parameter settings
p <- 0.3   # Success probability
k <- 1:20  # Number of trials (k)

# Probability Mass Function (PMF)
pmf <- dgeom(k - 1, prob = p)  # R's dgeom requires k-1

# Cumulative Distribution Function (CDF)
cdf <- pgeom(k - 1, prob = p)

# PMF Plot
plot(k, pmf, type = "h", lwd = 2, col = "blue",
     main = "Probability Mass Function (PMF) of Geometric Distribution",
     xlab = "Number of Trials (k)", ylab = "Probability",
     ylim = c(0, max(pmf) * 1.2))
points(k, pmf, pch = 16, col = "blue")
grid()

# CDF Plot
plot(k, cdf, type = "o", lwd = 2, col = "red",
     main = "Cumulative Distribution Function (CDF) of Geometric Distribution",
     xlab = "Number of Trials (k)", ylab = "Cumulative Probability",
     ylim = c(0, 1))
points(k, cdf, pch = 16, col = "red")
grid()

image.png

image.png

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?