randscr function define probabilities
Mostrar comentarios más antiguos
Hi, I am trying to conduct an experiment with two conditions, which should be displayed with a certain probability.
In this case "Trial_p" should be presented in 2/3 of the cases and "Trial_c" in 1/3.
I do get a quite random sequence, but the probabilities are not as I defined it!
Can anyone help?
Trial_p = [0 4 1 2]; % trial with percept
td1 = [0 1 0.5 2];
Trial_c = [0 4 3]; % control trial
td2 = [0 1 2];
total_ntrials = 9; % 120 trials
prob1 = 1/3*2; %0.66
prob2 = 1/3*1; %0.33
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
my_sequence = [];
my_duration = [];
randomized_seq = randsrc(1,total_ntrials,[1,2; prob1,prob2]); % randomize trialtypes
%x = rand(1)*(10-5) + 5;
for i = 1:length(randomized_seq)
if randomized_seq(i) == 1
td1(1) = floor(rand(1)*(5-1)+1); %(30-20) + 20);
my_sequence = cat(2, my_sequence, Trial_p);
my_duration = cat(2, my_duration, td1);
elseif randomized_seq(i) == 2
td2(1) = floor(rand(1)*(10-5) + 5);
my_sequence = cat(2, my_sequence, Trial_c);
my_duration = cat(2, my_duration, td2);
end
end
% floor (x) rounds the random numbers.
% randomize baseline (ITI) between 5 and 10 seconds
disp(my_duration');
disp(my_sequence');
2 comentarios
Jeff Miller
el 31 de Jul. de 2020
Do you want exactly 1/3 and 2/3 in the two conditions for every generated sequence, or do you want the actual proportions to vary a bit due to randomness? For example, suppose you will run sequences of 99 trials: do you want those divided 66/33 in every sequence, or do you want some sequences with 67/32, 65/34, etc due to randomness?
Walter Roberson
el 1 de Ag. de 2020
If the trials are independent of each other, then most of the time you will not get exactly the proportions you ask for.
Suppose for example that you run two flips of a fair-weight coin, probability of a H being 50% . Then after the first flip, the outcome is either 1 H or 1 T, discrete outcomes: you do not get 50% of a H and 50% of a T. When you continue on to the second flip, if you require exactly 50% then the second flip must be exactly the opposite of the first flip -- if you got a H the first time then the second would have to be a T, and if you got a T the first time the second outcome would have to be a H. So if you require exact proportions, then after the first flip, there is no randomness in what the second flip could be. That would contradict the assumption that the trials are independent of each other.
Respuestas (0)
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!