Re: [R] Constrained vector permutation

2010-02-01 Thread Andrew Rominger
Chuck, Thanks for the reference. MCMC with "swapping" was my original goal and I think I'll go with that in the long run--although using sample() has worked out for now. I was initially concerned that checking all choose(n,2) possible swaps would slow down the process, but in my case for choose(

Re: [R] Constrained vector permutation

2010-01-29 Thread Charles C. Berry
On Fri, 29 Jan 2010, Andrew Rominger wrote: Being reasonably sure that all valid permutations are equally probable is important to me. I've played around with search algorithms in permuting contingency tables and find that possible solutions decrease rapidly once one starts assigning values, pa

Re: [R] Constrained vector permutation

2010-01-29 Thread Andrew Rominger
Being reasonably sure that all valid permutations are equally probable is important to me. I've played around with search algorithms in permuting contingency tables and find that possible solutions decrease rapidly once one starts assigning values, particularly if small values are assigned first,

Re: [R] Constrained vector permutation

2010-01-28 Thread Thomas Lumley
On Thu, 28 Jan 2010, Jason Smith wrote: It wouldn't be guaranteed to produce any usable permutation, but it seems like it would be much faster and so could be repeated until an acceptable vector is found.  What do you think? Thanks-- Andy I think I am not understanding what your ultimate goa

Re: [R] Constrained vector permutation

2010-01-28 Thread Jason Smith
> It wouldn't be guaranteed to produce any usable permutation, but it seems > like it would be much faster and so could be repeated until an acceptable > vector is found.  What do you think? > > Thanks-- > Andy > I think I am not understanding what your ultimate goal is so I'm not sure I can give

Re: [R] Constrained vector permutation

2010-01-28 Thread Andrew Rominger
Hi Jason, Thanks for you suggestions, I think that's pretty close to what I'd need. The only glitch is that I'd be working with a vector of ~30 elements, so permutations(...) would take quite a long time. I only need one permutation per vector (the whole routine will be within a loop that generat

Re: [R] Constrained vector permutation

2010-01-28 Thread Jason Smith
I just realized I read through your email too quickly and my script does not actually address the constraint on each permutation, sorry about that. You should be able to use the permutations function to generate the vector permutations however. Jason

Re: [R] Constrained vector permutation

2010-01-28 Thread Jason Smith
Andrew Rominger gmail.com> writes: > I'm trying to permute a vector of positive integers > 0 with the constraint Hi Andy I'm not sure if you are explicitly wanting to use a sampling approach, but the gtools library has a permutations function (found by ??permutation then ? gtools::combinations

[R] Constrained vector permutation

2010-01-27 Thread Andrew Rominger
Hello, I'm trying to permute a vector of positive integers > 0 with the constraint that each element must be <= twice the element before it (i.e. for some vector x, x[i] <= 2*x[i-1]), assuming the "0th" element is 1. Hence the first element of the vector must always be 1 or 2 (by assuming the "0t