admin管理员组文章数量:1122846
In R
, how to use rpois
generate, for instance, 5 random numbers from a Poisson distribution with mean 2, and then 3 random numbers from a Poisson distribution with mean 3, and put them in one vector of length 8?
I have tried
rpois(c(5,3),c(2,3))
but this generates a vector with length 2.
In R
, how to use rpois
generate, for instance, 5 random numbers from a Poisson distribution with mean 2, and then 3 random numbers from a Poisson distribution with mean 3, and put them in one vector of length 8?
I have tried
rpois(c(5,3),c(2,3))
but this generates a vector with length 2.
Share Improve this question asked Nov 21, 2024 at 23:49 AsiganAsigan 1054 bronze badges 3 |1 Answer
Reset to default 3There are lots of ways to do this. The most transparent one might be
rpt_vec <- c(5,3)
lambda_vec <- c(2,3)
rpois(sum(rpt_vec), lambda = rep(lambda_vec, rpt_vec))
sum(rpt_vec)
is the total number of deviates you want; rep(...)
generates the right number of copies of each lambda_vec
value.
版权声明:本文标题:Use R to generate a sequence random numbers of Poisson distribution with different mean - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736306474a1932970.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
rpois(8, c(2,2,2,2,2, 3,3,3))
would do it. There are many other ways to generate the vector of means, but for this length you may as well just write it out. – user2554330 Commented Nov 22, 2024 at 0:28R
? I did not see that way of usingrpois
on the document of the function stat.ethz.ch/R-manual/R-devel/library/stats/html/Poisson.html . – Asigan Commented Nov 22, 2024 at 1:51?rpois
sayslambda
(the mean) is a "vector of (non-negative) means". – user2554330 Commented Nov 22, 2024 at 10:32