[R] Generate N random numbers with a given probability and condition
Göran Broström
gor@n@bro@trom @end|ng |rom umu@@e
Thu Jul 12 09:44:06 CEST 2018
On 2018-07-05 00:21, Nelly Reduan wrote:
> Dear all,
>
> I would like to generate N random numbers with a given probability and condition but I'm not sure how to do this.
> For example, I have N = 20 and the vector from which to choose is seq(0, 10, 1). I have tested:
>
> x <- sample(seq(0, 10, 1), 20, replace=TRUE, prob=rep(0.28, times=length(seq(0, 10, 1))))
>
> But I don�t know how to put the condition sum(x) <= max(seq(0, 10, 1)).
> Many thanks for your time
> Nell
Maybe the paper "Acceptance–Rejection Sampling from the Conditional
Distribution of Independent Discrete Random Variables, given their Sum",
Statistics 34, pages 247-257, by Leif Nilsson and myself (2000) is relevant?
Göran
>
>
> [[alternative HTML version deleted]]
>
>
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list