发布于 2016-01-02 09:28:43 | 1608 次阅读 | 评论: 0 | 来源: 网络整理

二项式分布模型涉及寻找具有在一系列实验中只有两种可能的结果的事件的成功的概率。对于一个硬币的例子折腾总是给出一个正面或反面。发现正是3个正面,在反复掷硬币10次的概率是二项分布估计的期间。

R语言有四个内置函数生成二项分布。它们被描述如下。

dbinom(x, size, prob)
pbinom(x, size, prob)
qbinom(p, size, prob)
rbinom(n, size, prob)

以下是所使用的参数的说明:

  • x 是数字向量。
  • p 是概率的向量。
  • n 是观测次数。
  • size 是试验次数。
  • prob 是每次试验的成功概率。

dbinom()

此函数可以让每个点显示的概率密度分布。

# Create a sample of 50 numbers which are incremented by 1.
x <- seq(0,50,by=1)

# Create the binomial distribution.
y <- dbinom(x,50,0.5)

# Give the chart file a name.
png(file = "dbinom.png")

# Plot the graph for this sample.
plot(x,y)

# Save the file.
dev.off()

当我们上面的代码执行时,它产生以下结果:

pbinom()

此函数给出了一个事件的累积概率。它是表示单个值的概率

# Probability of getting 26 or less heads from a 51 tosses of a coin.
x <- pbinom(26,51,0.5)

print(x)

当我们上面的代码执行时,它产生以下结果:

[1] 0.610116

qbinom()

这个函数的概率值,并给出了一个数字,其累加值相匹配概率值。

# How many heads will have a probability of 0.25 will come out when a coin is tossed 51 times.
x <- qbinom(0.25,51,1/2)

print(x)

当我们上面的代码执行时,它产生以下结果:

[1] 23

rbinom()

这个函数从给定的样本生成概率随机值所需的数目。

# Find 8 random values from a sample of 150 with probability of 0.4.
x <- rbinom(8,150,.4)

print(x)

当我们上面的代码执行时,它产生以下结果:

[1] 58 61 59 66 55 60 61 67


最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务