I want to calculate all permutations of a blocked design suitable for a Friedman test. Consider the following example:
thedata <- data.frame(
score = c(replicate(4,sample(1:3))),
judge = rep(1:4,each=3),
wine = rep.int(1:3,4)
)
Four judges ranked 3 wines and now I want to calculate every possible permutation within the data for every judge. I expect to see 1,296 permutations, as also given by:
require(permute)
CTRL <- how(within=Within("free"),
plots=Plots(strata=factor(thedata$judge)),
complete=TRUE,maxperm=1e9)
numPerms(12,CTRL)
However, allPerms(12,control=CTRL)
produces the following error:
Error in (function (..., deparse.level = 1) :
number of rows of matrices must match (see arg 2)
I tried using the block
argument, but it simply returns a matrix that repeats 4 times a matrix with the 6 possible permutations of 3 values:
CTRL <- how(within=Within("free"),
blocks=factor(thedata$judge),
complete=TRUE,maxperm=1e9)
allPerms(12,control=CTRL)
IMPORTANT NOTE:
I do have a custom function to obtain the result, using an adaptation of expand.grid()
with permn()
from the combinat
package. I'm interested in where I misunderstand the permute
package, not how I can calculate all these permutations myself.