# 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()
當(dāng)我們執(zhí)行上面的代碼,它產(chǎn)生以下結(jié)果 -
pbinom()
此函數(shù)給出事件的累積概率。 它是表示概率的單個值。
# Probability of getting 26 or less heads from a 51 tosses of a coin.
x <- pbinom(26,51,0.5)
print(x)
當(dāng)我們執(zhí)行上面的代碼,它產(chǎn)生以下結(jié)果 -
[1] 0.610116
qbinom()
該函數(shù)采用概率值,并給出累積值與概率值匹配的數(shù)字。
# 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)
當(dāng)我們執(zhí)行上面的代碼,它產(chǎn)生以下結(jié)果 -
[1] 23
rbinom()
該函數(shù)從給定樣本產(chǎn)生給定概率的所需數(shù)量的隨機值。
# Find 8 random values from a sample of 150 with probability of 0.4.
x <- rbinom(8,150,.4)
print(x)
更多建議: