MATLAB Answers

How to pseude-randomize dataset with constraints

35 views (last 30 days)
Sybren Van Hoornweder
Sybren Van Hoornweder on 19 Jan 2021
Hi
I would like to pseudo-randomize the order of trials in an experiment. I'll start of by shortly explaining the experiment.
There are 80 trials in total, and 8 different condition (so 10 trials of each condition) (see attachment). Out of the 8 conditions, two conditions are considered to be easy, two conditions are considered to be mildly difficult, two conditions are considered to be moderately difficult and two conditions are considered to be hard.
I would like to pseudo-randomize the data in such a way that all trials within a condition are preceded by trials of all difficulty levels. Hence I would like to avoid that, for example, the easy tasks are always preceded by difficult tasks, which might induce unwanted confounders into the data. Ideally, the data would be randomized in such a way that two or three easy tasks are preceded by mildly difficult tasks, two or three easy tasks are preceded by moderately difficult tasks, and so on.
Does anyone know how to achieve this in Matlab?
Thanks in advance
Sincerely

  0 Comments

Sign in to comment.

Answers (1)

John D'Errico
John D'Errico on 19 Jan 2021
So, you want it random, but you don't really want it random, in a sort of vague, unspecified way.
Can you do this in MATLAB? NO! The vagueness makes that impossible. What might you do? God only nows, because you have been too vague to know for sure what would be acceptable.
Can you rank the various conditions into 8 distinct ranks of difficulty? (If not, this is still not a problem. 4 levels of difficulty are still ok.) For now, I'll assume there are 8 ranks.
T = -7:2:7;
So a trial with difficulty of -7 is REALLY easy. A +7 is the most difficult.
trials = repmat(T,1,10);
Now, consider a simple random permutation of the trials. Think of this as a zero sum random walk. At the very end, you know it you will return to zero, since sum(trials)==0.
plot([0,cumsum(trials(randperm(80)))])
yline(0);
What you don't want (I THINK) is a sequence of trials that spends the entire sequence a long way above or below zero. In fact, the one I plotted above is actually pretty good, compared to several that I tried. On the other hand, I only had to take a few random permutations until I found something that seemed pretty good.
The point being, you can do the same. You could even create some measure of the random walk that I show above so that random walks that wander too far away from zero are bad. Then just set up a while loop that will iterate until you find a random permutation that satisfies your goal of acceptability.
If you can only form 4 ranks of difficulty, then set the trials as having difficulty as
T = [-3 -3 -1 -1 1 1 3 3];
trials = repmat(T,1,10);
Now take random permuations of that set until you are happy with the cumulative random walk induced by the permutation.
If you want something better than this, then you probably need to be VERY, VERY less vague.

  1 Comment

Sybren Van Hoornweder
Sybren Van Hoornweder on 19 Jan 2021
Hi John.
The option you have presented, seems to be something I can definitely work with, so thanks! Nevertheless, I'll try to clarify what I mean. First of all, I intend to analyse brain activity.
I have a reaction time task consisting of 8 different conditions (8 different buttons subjects have to press). Each condition will be repeated 10 times, totaling 80 conditions. Conditions can be divided into groups of 2 (so four distinct ranks of difficulty, as aforementioned) regarding difficulty level (going from easy to hard, so condition 1 and 2 are of similar difficulty etc.).
My goal is to PSEUDO-randomize (so I indeed don't want it completely random) the dataset, to ensure a specific condition is not always preceded by another trial of a specific difficulty level. I'll elaborate with an example:
Let's say i randomise the trial-order, but condition 1 (easy) is (near-)always preceded by condition 7 or 8 (hard). This would influence brain activity, as residual activity from the difficult condition might influence the brain activity measured during condition 1. To overcome this, I would thus need some sort of Mathlab script, that pseudo-randomizes my dataset in such a way, that all trials of each condition, are preceded by trials from all sorts of difficulty levels. For condition 1, I would thus need a way that condition 1 is preceded by for example an easy condition the first time, a mildly difficult condition the second time, a hard condition the third time, a moderately difficult condition the fourth time, and so on. This would balance out any brain activity present induced by a specific level of difficulty.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by