R에서 제공하는 분포 관련 함수

density function of dist.

- d### (x,  ...<parameters>...)

 

distribution function of dist. 

- p###(q, ...<parameters>...)   # = P(X <= q)

- q###(p, ...<parameters>...)   # p = P(X <= x) >>> {P(X <= x)}^(-1)

 

 

 

이산확률분포 

 

이항분포

## 이항분포 - pmf 활용 ----
n = 15
p = 0.2
x = 0:10

y1 = dbinom(x, n, p) ; y1
plot(x, y1, type = "h", lwd = 3, col = "blue4")

## 이항분포 - cdf 활용 ----
y2 = pbinom(x, n, p) ; y2
plot(x, y2, type = "h", lwd = 3, col = "tomato")
plot(x, y2, type = "s", lwd = 3, col = "tomato")

## 이항분포 - check qbinom value ----
x; y2
qbinom(y2[2], n, p) == x[2]

 

 

포아송분포

## 포아송 분포 - pmf 활용 ----
lam = 2.5
x = 0:10
y1 = dpois(x, lam)

plot(x, y1, type = "h", lwd = 3, col = "blue4")


## 포아송 분포 - cdf 활용 ----
y2 = ppois(x, lam)
plot(x, y2, type = "h", lwd = 3, col = "tomato")
plot(x, y2, type = "s", lwd = 3, col = "tomato")

## 포아송 분포 - 값 찾기 ----
qpois(0.3456, lam)

 

 

 

연속확률분포

 

정규분포

## 정규분포 - pdf 활용 ----
mu = 0
sig = 1
x = seq(-5, 5, length = 20)

y2 = dnorm(x, mu, sig)
plot(x, y2, type = "h", lwd = 3, col = "blue4")

## 정규분포 - cdf 활용 ----
y3 = pnorm(x, mu, sig)
plot(x, y3, type = "s", lwd = 3, col = "tomato")

## 정규분포 - 값 찾기 ----
qnorm(y3, mu, sig) < qnorm(0.7, mu, sig)

 

 

t-분포

## t-분포 - pdf 활용 ----
df1 = 5
x = seq(-5, 5, length = 20)

y1 = dt(x, df1)
plot(x, y1, type = "h", lwd = 3, col = "blue4")

## t-분포 - cdf 활용 ----
y2 = pt(x, df1)
plot(x, y3, type = 's', lwd = 3, col = "tomato")

## t=분포 - 값 찾기 ----
qt(0.2, df1)

 

 

카이제곱분포

## 카이제곱분포 - pdf 활용 ----
df2 = 7
x = seq(0,30, length = 20)

y1 = dchisq(x, df2)
plot(x, y1, type = "h", lwd = 3, col = "blue4")

## 카이제곱분포 - cdf 활용 ----
y2 = pchisq(x, df2)
plot(x, y2, type = "s", lwd = 3, col = "tomato")


## 카이제곱분포 - 값 찾기 ----
qchisq(0.65, df1) + qchisq(0.65, df2)

+ Recent posts