计算 R 编程中均匀分布的 CDF 值 – punif()函数
在 R 编程中, punif()
函数用于计算累积分布函数(CDF) 的值。
Syntax:
punif(q, min = 0, max = 1, lower.tail = TRUE, log.p = FALSE)
Parameters:
q: represents vector of quantiles
min, max: represents lower and upper limits of the distribution
lower.tail: represents logical value. If TRUE, probabilities are P[X<=x]
log.p: represents logical value. If TRUE, probabilities are given as log(p)
示例 1:
# Create vector of random deviation
u <- runif(20)
punif(u) == u
print(punif(u))
输出:
[1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
[16] TRUE TRUE TRUE TRUE TRUE
[1] 0.21571509 0.97224483 0.74654757 0.93053902 0.90868119 0.93048128
[7] 0.41566382 0.52074950 0.41353715 0.48460207 0.63706965 0.16338451
[13] 0.22761876 0.54239105 0.07045675 0.04363406 0.68484316 0.86928257
[19] 0.06046589 0.29565811
示例 2:
# Output to be present as PNG file
png(file = "punifGFG.png")
# Plot function
curve(punif(x, min = 2, max = 6), 0, 8, ylim = c(0, 0.5),
ylab = "f(x)")
# Saving the file
dev.off()
输出: