# RE: [R] Permutations

From: Robin Hankin <rksh_at_soc.soton.ac.uk>
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)
x.new <- 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

Robin

>
>}
>7.- Robin Hankin
>a<-matrix(1,200,12)
>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))
>a[i,]<-as.vector(jj)
>}
>##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!
>http://latino.msn.com/autos/

```--
Robin Hankin
Uncertainty Analyst
Southampton Oceanography Centre
SO14 3ZH
tel +44(0)23-8059-7743
initialDOTsurname@soc.soton.ac.uk (edit in obvious way; spam precaution)

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help