permutation tests of group differences when data contain repeated measures I have data from several mice with id id. Each mouse either belongs to either group C or group T. I also have a repeated measures factor because each mouse wandered around two mazes (A and B). My dependent variable is score.
dat <- data.frame(id=c(1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6), 
         maze=c("A", "B", "A", "B", "A", "B", "A", "B", "A", "B", 
                "A", "B"), 
         group=c("C", "C", "T", "T", "C", "C", "T", "T", "C", "C",
                 "T", "T"), 
         score=c(10, 21, 13, 9, 12, 16, 3, 18, 3, 19, 22, 20))

   id maze group score
1   1    A     C    10
2   1    B     C    21
3   2    A     T    13
4   2    B     T     9
5   3    A     C    12
6   3    B     C    16
7   4    A     T     3
8   4    B     T    18
9   5    A     C     3
10  5    B     C    19
11  6    A     T    22
12  6    B     T    20

I'm familiar with permutation tests when each row is an independent observation, but if I'm interested in the effect of group, how should the shuffling be done? Can I simply shuffle the group labels randomly in every replicate, even though scores are not truly independent?
EDIT:
For example, I wondered if I should only shuffle the group labels, with the constraint that each id should get the same group label:
   id maze group score
1   1    A     T    10
2   1    B     T    21
3   2    A     C    13
4   2    B     C     9
5   3    A     C    12
6   3    B     C    16
7   4    A     C     3
8   4    B     C    18
9   5    A     T     3
10  5    B     T    19
11  6    A     C    22
12  6    B     C    20

randomly shuffling the group labels would break the correlation structure. For example, with the random shuffling of group labels below, id 1 now belongs to both groups, even though it was originally in group T only. Would this be valid?
   id maze group score
1   1    A     T    10
2   1    B     C    21
3   2    A     C    13
4   2    B     C     9
5   3    A     T    12
6   3    B     C    16
7   4    A     T     3
8   4    B     C    18
9   5    A     T     3
10  5    B     T    19
11  6    A     T    22
12  6    B     C    20


Each mouse belongs to one group. Having it run through one or many mazes has no influence on your null ("that there is no difference in scores between mice in group C and group T") so we keep that structure in place and do not permute that.
The procedure is very similar to that in your previous question here: Permutations with repeated measures
Pivot the data to a wide format where each mouse has one row with one column defining the group. Then permute the one row (which group each mouse belongs to). Everything else needs no manipulation.
We know that some mouse got 10 points in maze A and 21 in maze B and we only need to permute, if that mouse was group 'C' or 'T' if that is what we want to investigate.
