Interaction of shuffle() and Latin Square function

Skip to first unread message

Ken Nakatani

May 4, 2021, 2:38:42 AMMay 4
to ibexexperiments

Not that I’m in trouble, but I’m just being curious about the logic behind how Ibex’s latin square function interacts with its shuffle() function.  

Suppose that an experiment consists of 4 sets of 4 conditions, which are given different Type names (a, b, c, d), as well as 4 fillers.  

[["a", 1], …]
[["b", 1], …]
[["c", 1], …]
[["d", 1], …]

[["a", 4], …]
[["b", 4], …]
[["c", 4], …]
[["d", 4], …]

["filler", …]
["filler", …]
["filler", …]
["filler", …]

I understand that in such a case, using anyOf("a", "b", "c", "d") along with shuffle() would yield a desirable order of presentation in which one of the 4 conditions and one of the 4 fillers alternates.  

What I don’t understand is, without anyOf(), the first 3 fillers are always presented first. 

var shuffleSequence = seq(shuffle("a", "b", "c", "d", "filler"));

Some sample outcomes:
f1 f2 f3 4d 2b 1a f4 3c 
f1 f2 f3 2d f4 1c 4b 3a 
f1 f2 f3 2b 3c f4 4d 1a 
f1 f2 f3 1c 4b 3a f4 2d 
f1 f2 f3 1a 3c 2b f4 4d
f1 f2 f3 4b 2d 1c 3a f4

(Note: randomize() is not used.)

Why do the first 3 fillers come first, and why 3, not 1, 2, or 4?  
Also, the order of appearance of the target items seems randomized.  Why?  Just being curious.

Without shuffle(), the order of presentation would be very predictable and straightforward.  

var shuffleSequence = seq("a", "b", "c", "d", "filler");
1a 2b 3c 4d f1 f2 f3 f4 
4a 1b 2c 3d f1 f2 f3 f4
3a 4b 1c 2d  f1 f2 f3 f4
2a 3b 4c 1d  f1 f2 f3 f4

The documentation states: 

“A statement of the form shuffle(pred1, pred2, pred3, ...) specifies that items matching the given predicates should be shuffled together in such a way that items matching each predicate are evenly spaced. The original relative ordering between items of the same type is preserved.”

But in the above instance of shuffle(), the predicates do not seem to be evenly spaced.  I bet that the Group specification is doing some trick but I’m wondering what trick it’s doing.

I sometimes give an introductory tutorial on Ibex to friends and students, but I always find myself unable to provide an explanation for this.  

If anybody has an idea, I would appreciate it.  Thank you!

-Ken Nakatani

Alexandre Cremers

May 4, 2021, 2:51:53 AMMay 4

shuffle works best with predicates of roughly equal sizes, or sizes which are multiples of each other. In your case, "a" to "d" each have only one element (for a given participant), so there isn't much sense talking about how the "a" items are evenly spaced since there's only one of them (and same for "b" to "d"). If you use shuffle(anyOf("a", "b", "c", "d"), "filler"), then you feed only two predicates to shuffle, and they each contain 4 elements, so this will give you the correct shuffling. In practice, you'll probably want to use rshuffle(), so that the order between "a"..."d" varies across participants, but the logic is the same.

I hope this helps,

You received this message because you are subscribed to the Google Groups "ibexexperiments" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit

Ken Nakatani

May 4, 2021, 10:10:40 PMMay 4
Hi Alexandre,

So the reason why 3 of the 4 fillers appear first is that the program tries to make the number of the elements of “filler” comparable to those of the other predicates (i.e., 1) by discharging 3.  That makes sense, thank you!  


2021年5月4日(火) 15:51 Alexandre Cremers <>:
Reply all
Reply to author
0 new messages