# R語言中之分佈函數

R語言中提供了四類有關統計分佈的函數，以下爲函數和相應前綴

d --概率密度函數

p --累計分佈函數

q --分位函數

r –隨機數函數(仿真)

 分佈 R中名字 附加參數 beta beta shape1 shape2 ncp binomial binom size prob Cauchy cauchy location scale chi-squared chisq df ncp exponential exp rate F f df1 df2 ncp gamma gamma shape scale geometric geom prob hypergeometric hyper m n k log-normal lnorm meanlog sdlog logistic logis location scale negative binomial nbinom size prob normal norm mean sd Poisson pois lambda Student’s t df ncp uniform unif min max Weibull weibull shape scale Wilcoxon wilcox m n

## R分佈函數例子

``````dnorm(x, mean = 0, sd= 1, log = FALSE)
pnorm(q, mean = 0, sd= 1, lower.tail = TRUE, log.p = FALSE)
qnorm(p, mean = 0, sd= 1, lower.tail = TRUE, log.p = FALSE)
rnorm(n, mean = 0, sd= 1)``````

1

``````dnorm(0)#獲得正態分佈的密度函數在x = 0處的值
#[1] 0.3989423
pnorm(0)#正態分佈的累計密度函數在q = 0處的值
#[1] 0.5
qnorm(0.975)#標準正態分佈在p = 0.975處的分位數
#[1] 1.959964
rnorm(3,5, 2) #按均值爲5，標準差爲2的正態分佈隨機產生3個數
#[1] 3.726756 2.8733234.092495
``````

``````dpois(x, lambda, log =FALSE)
ppois(q, lambda,lower.tail = TRUE, log.p = FALSE)
qpois(p, lambda,lower.tail = TRUE, log.p = FALSE)
rpois(n, lambda)``````

``dbinom(x, size, prob, log = FALSE) ``
``````pbinom(q, size, prob, lower.tail = TRUE, log.p = FALSE)
qbinom(p, size, prob, lower.tail = TRUE, log.p = FALSE)
rbinom(n, size, prob)
``````

1 已知某批雞蛋的孵出率prob = 0.9，抽取size = 5個雞蛋檢查其孵化情況，發現最終x=3個雞蛋孵化，求二項分佈的概率。

``````dbinom(3, 5, 0.9)
#[1] 0.0729``````

2：進行投籃實驗，試驗次數size = 5，每次投中率prob =0.6，生成n = 10個滿足該分佈B(5, 0.6)的隨機數.

``````rbinom(10, 5, 0.6)
# [1] 4 2 4 4 2 2 3 34 2``````

## 參考文獻：

《統計建模與R軟件》-薛毅

R語言中的四類統計分佈函數

http://www.cnblogs.com/end/p/3718822.html