# [R] Permutation Test

From: Stropharia <stevenworthington_at_hotmail.com>
Date: Wed, 20 Feb 2008 23:05:14 -0800 (PST)

Dear R users,

i am fairly new to R and am having trouble creating code to solve a problem. I've searched the list, combed Crawley's 'R book' and several others, but can't quite find what i want.

I want to generate permutations of various 'blocks' of 14 numbers. Each number within a block is a character state for a particular biological taxon. In the example below, for 'character 1' (i.e., block 1) there are thus 4 'states' (0, 1, 2, and 3), BUT there are differing quantities of each state (e.g., five of state 0, two of state 1, four of state 2, etc.). I'd like to 'shuffle' these states across the 14 taxon labels as many times as there are unique combinations (or, if there are several million or more unique combinations, i'd like to do perhaps 1 million Monte Carlo subsets of the possible combinations). Here is an example:

```Taxon     Character 1     Perm 1   Perm 2   Perm 3  ... Perm N
A               0                0              3              2
B               2                2              0              0
C               3                2              2              0
D               1                0              0              3
E               0                3              0               1
F               2                1              3               2
G               1                3             2               0
H               0                0             2               2
I                0                2             1               1
J                2                1             0               0
K               0                3             3               3
L                3                0             2               3
M               3                2             0               2
N               2                0             1               0

```

I have many characters, some with more states (e.g., character 2, below, has 6 states) and some with less states. So, ideally, the code needs to be able to deal with this.

```Taxon     Character 2
A               5
B               3
C               2
D               4
E               4
F               1
G               3
H               0
I                4
J                1
K               0
L               4
M               4
N               3

```

Am I right in thinking that the correct way of working out how many possible permutations there can be in this instance is: N! / (n1!) (n2!) (n3!)... (ni!). Where N is the number of taxa (14) and (for character 2) n1 could be 'number of state zeros' (i.e., 2), n2 could be 'number of state ones' (i.e., 2), n3 could be 'number of state twos (i.e., 1) etc?

Any help would be greatly appreciated. Thanks a lot.

Steve

Steven Worthington
PhD Candidate
New York Consortium
in Evolutionary Primatology
New York, NY 10003
USA
```--
View this message in context: http://www.nabble.com/Permutation-Test-tp15605886p15605886.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help