[R] generate combination multiset (set with repetition)
reubano at gmail.com
Fri Dec 12 03:28:44 CET 2008
Good point, I actually thought about doing some kind of sampling
before, but now I think I don't have a choice. Essentially, what I am
doing is calculating possible asset allocation possibilities, e.g.
N is the number of available assets and M is the available buckets of
money to spend on the assets. With N = 3 and M = 2, I am saying I have
a choice to buy any of 3 three assets and I can afford to make 2 such
purchases. These combinations are represented below:
[1,] 1 1
[2,] 1 2
[3,] 1 3
[4,] 2 2
[5,] 2 3
[6,] 3 3
[1,] is saying I spend all of my money buying asset 1.
this produces the following asset allocations
A1 A2 A3
[1,] 1 0 0
[2,] .5 .5 0
[3,] .5 0 .5
[4,] 0 1 0
[5,] 0 .5 .5
[6,] 0 0 1
[1,] again, is saying that my allocation is 100% asset 1.
from here, I plan to run some risk/performance metrics on the
allocations and then come up with a list of the best allocation
The sampling will come in handy to give me random asset allocations.
I've taken a statistical design of experiments class, so I am familiar
with generating factorial experiment designs.
So, how would I go about producing the random samples? And what # of
combinations should I use as the cutoff for doing a sampling instead
of testing every possible combination?
On Thu, Dec 11, 2008 at 6:48 PM, G. Jay Kerns <gkerns at ysu.edu> wrote:
> Dear Reuben,
>> my questions now are... how would I generalize functions 3 and 4 for m
>> And, which of the 4 functions would be best for varying ranges of
>> n and m? I am expecting values for n to range between 1 and 1e3, while
>> m will range between 1 and 1e6.
> Regarding your 2nd question, for the values of n and m that you
> request, the answer is "none". The number of combinations is
> astronomically large. To get an idea, try
> nsamp( n, m, ordered = FALSE, replace = TRUE )
> for assorted values of n and m.
> Bearing the above in mind, it may be useful to think carefully about
> _why_ it is desired to have all possible combinations. In some
> circumstances, it is good enough to randomly generate combinations and
> draw inferences from a sampling distribution of some sort associated
> with the problem.
> Good luck.
> G. Jay Kerns, Ph.D.
> Associate Professor
> Department of Mathematics & Statistics
> Youngstown State University
> Youngstown, OH 44555-0002 USA
> Office: 1035 Cushwa Hall
> Phone: (330) 941-3310 Office (voice mail)
> -3302 Department
> -3170 FAX
> E-mail: gkerns at ysu.edu
More information about the R-help