I was wondering if it's possible to automatically pseudo-randomize stimuli in R? If so, I would be very grateful for any help.

  • $\begingroup$ Pseudo randomness is typically just a random permutation. You can write code to do this in any general language. Not sure what you mean by "automatically". $\endgroup$ Jan 25 at 15:59
  • $\begingroup$ I was actually looking for tips on how to do that, I am sorry for not being clear. $\endgroup$ Jan 26 at 16:08

You can use the "sample" function: https://stat.ethz.ch/R-manual/R-devel/library/base/html/sample.html

Start with a list of the stimuli you want to present. For example, if you have two stimuli that should be repeated 4 times each, your list would be c(1,1,1,1,2,2,2,2)

If you take 8 samples from this distribution without replacement, you have a random permutation of the list. This is the default behavior if you just give the original list, like this:

  • $\begingroup$ Thank you! As I understand this would not necessarily create a pseudo-randomization, but a randomization instead. I was actually wondering how to create pseudo-randomized lists in which for example the same condition cannot come up more than 3 times in a sequence. So if I example conditions a, b, c, d, the script would create patterns such as aabbccddaaabbbcccddd or similar to that. $\endgroup$ Jan 28 at 11:24
  • 2
    $\begingroup$ @rhododendron What I write is also pseudorandom, because it's sampling without replacement. For what you describe you could do a block randomization where you take consecutive draws from a smaller number of stimuli and then stitch them together. $\endgroup$ Jan 28 at 12:25
  • $\begingroup$ @rhododendron could you give us more details on what the constrains are and how long the sequence should be? Maybe we could then give a more fitting reply :) $\endgroup$
    – bucky
    Jan 31 at 9:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.