Re: [R] Sum(Random Numbers)=100

From: Richard Pearson <richard.pearson_at_postgrad.manchester.ac.uk>
Date: Tue, 08 Jul 2008 08:25:09 +0100

Shubha

Does table(ceiling(runif(100,0,50))) give you something like you want?

Richard.

Shubha Vishwanath Karanth wrote:
> ...actually I need to allocate certain amount of money (here I mentioned
> it as 100) to a randomly selected stocks(50 stocks)... i.e., 100 being
> divided among 50 stocks and preferably all are integer allocations(i.e.,
> 5 8 56 12 etc without any decimals)...
>
> Thank you,
> Shubha
> -----Original Message-----
> From: Moshe Olshansky [mailto:m_olshansky_at_yahoo.com]
> Sent: Tuesday, July 08, 2008 12:09 PM
> To: r-help_at_stat.math.ethz.ch; Shubha Vishwanath Karanth
> Subject: Re: [R] Sum(Random Numbers)=100
>
> If they are really random you can not expect their sum to be 100.
> However, it is not difficult to get that given that the sum of n
> independent Poisson random variables equals N, any individual one has
> the conditional binomial distribution with size = N and p = 1/n, i.e.
> P(Xi=k/Sn=N) = (N over k)*(1/n)^k*((n-1)/n)^(N-k).
> So you can generate X1 binomial with size = 100 and p = 1/50; if X1 = k1
> then the sum of the rest 49 must equal 100 - k1, so now you generate X2
> binomial with size = 100-k1 and p = 1/49; if X2 = k2 then generate X3
> binomial with size = 100 -(k1+k2) and p = 1/48, etc.
>
> Why do you need this?
>
>
> --- On Tue, 8/7/08, Shubha Vishwanath Karanth <shubhak_at_ambaresearch.com>
> wrote:
>

>> From: Shubha Vishwanath Karanth <shubhak_at_ambaresearch.com>
>> Subject: [R] Sum(Random Numbers)=100
>> To: r-help_at_stat.math.ethz.ch
>> Received: Tuesday, 8 July, 2008, 3:58 PM
>> Hi R,
>>
>>  
>>
>> I need to generate 50 random numbers (preferably poisson),
>> such that
>> their sum is equal to 100. How do I do this?
>>
>>  
>>
>>  
>>
>> Thank you,
>>
>> Shubha
>>
>>  
>>
>> This e-mail may contain confidential and/or privileged
>> i...{{dropped:13}}
>>
>> ______________________________________________
>> R-help_at_r-project.org mailing list
>> 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.

> This e-mail may contain confidential and/or privileged i...{{dropped:10}}
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> 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.
>
-- 
Richard D. Pearson             richard.pearson_at_postgrad.manchester.ac.uk
School of Computer Science,    http://www.cs.man.ac.uk/~pearsonr
University of Manchester,      Tel: +44 161 275 6178
Oxford Road,                   Mob: +44 7971 221181
Manchester M13 9PL, UK.        Fax: +44 161 275 6204

______________________________________________
R-help_at_r-project.org mailing list
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.
Received on Tue 08 Jul 2008 - 07:39:53 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 08 Jul 2008 - 08:31:46 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive