【发布时间】:2014-04-18 14:44:20
【问题描述】:
在论坛搜索后,我没有找到类似的问题。如果我错过了,请告诉我。我真的很感激。
我需要使用给定的形状和比例参数以及 R 中的下限/上限从伽马分布中生成 N 个(可以是 10000 个或更多)样本点。
我知道如何通过“for循环”来做到这一点,但是效率不高。
library(distr)
get_sample_gamma(shape, scale, lb, ub)
{
v <- rgamma(n = 10000, shape, scale)
# check the elements of v to be located [lb, ub]
# if not in the range, count the number of points in the range as M
# generate the remaining N - M points until all N points are got.
}
这不是有效的。
任何更有效的解决方案都会受到赞赏。
【问题讨论】:
-
在
truncdist包中使用rtrunc(...)。见this answer。
标签: r distribution gamma-distribution