RE: [R] Permutations

From: Robin Hankin <>
Date: Thu 15 Jul 2004 - 18:14:48 EST

hi again

what a stimulating R discussion! This is R-help at its very best!

I think I understand why you don't want pure inter-block permutations.

My solution would be to realize that weeding out "forbidden" permutations is quite difficult and time-consuming (also as several people have pointed out forbidden permutations are very rare, accounting for only a proportion of (3!)^4/12! ...about one in 400000).

The extra expense of this weeding process is likely to outweigh the slight loss of efficiency caused by generating a forbidden permutation. My solution would therefore be:

x <- c(1,2,3,4,5,6,7,8,9,10,11,12) <- sample(x)

(note the not-inconsiderable advantage of code simplicity!)

I think my algorithm generated repeats because in it there are only (4!)^3=13284 distinct
permutations; see help(birthday). The system above has 12! ~= 4x10^8, much higher.

Hope this helps


>7.- Robin Hankin
>for (i in 1:200)
>x <- c(1,2,3,4,5,6,7,8,9,10,11,12)
>dim(x) <- c(3,4)
> jj <- t(apply(x,1,sample))
>##In 200 permutations, there are 5 repetitions.
>Thanks to all and sorryfor the confusion that
>have generated the "intra-block" permutation.
>Jordi Altirriba
>PhD student
>Hospital Clinic - Barcelona - Spain
>P.S. I think that I don't have forgot to anybody...(sorry if I have done it)
>¿Cuánto vale tu auto? Tips para mantener tu
>carro. ¡De todo en MSN Latino Autos!

Robin Hankin
Uncertainty Analyst
Southampton Oceanography Centre
SO14 3ZH
tel +44(0)23-8059-7743 (edit in obvious way; spam precaution)

______________________________________________ mailing list
PLEASE do read the posting guide!
Received on Thu Jul 15 18:21:18 2004

This archive was generated by hypermail 2.1.8 : Wed 03 Nov 2004 - 22:54:59 EST