[R] generate combination multiset (set with repetition)
Reuben Cummings
reubano at gmail.com
Fri Dec 12 07:33:50 CET 2008
Thanks!!! works perfectly. I'll use t(rmultinom(x, m, rep(1,n))/m) for
now and look up in my stats book the formula for determining the
number of sample sizes to achieve a given p level. The second question
was more pertaining to how many combinations are too many to attempt
to calculate every possibility.
I ran a few tests and it took about 1 min or so for R to run z <-
subsets(15, 10, allow.repeat=T) which is ~ 2 million combinations.
Based on that, I figure I'll sample when the number of combinations
starts to approach 1 million. Thanks again.
Reuben
On Thu, Dec 11, 2008 at 11:02 PM, G. Jay Kerns <gkerns at ysu.edu> wrote:
> Reuben,
>
> On Thu, Dec 11, 2008 at 9:28 PM, Reuben Cummings <reubano at gmail.com> wrote:
>> 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:
>>
>> M1 M2
>> [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
>> choices.
>>
>> 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?
>
> how about this:
>
> rmultinom(10, 2, rep(1,3))/2
>
> Please note that the above assumes a model in which it is equally
> likely to choose asset 1, 2, or 3. You should think about the model
> carefully and adjust the "prob" argument accordingly.
>
>> And what # of
>> combinations should I use as the cutoff for doing a sampling instead
>> of testing every possible combination?
>
> There isn't a definitive answer to that question. Assuming that it is
> desired to find an 'average risk' of some sort, it would be good to
> increase the number of samples until the risk estimate stabilizes to a
> value with which you are comfortable.
>
> Best,
> Jay
>
>
>
>
>
>
> ***************************************************
> 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
> http://www.cc.ysu.edu/~gjkerns/
>
More information about the R-help
mailing list