How to pseude-randomize dataset with constraints
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
John D'Errico
2021-1-19
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!