微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Matlab:如何在不连续呈现相同试验的情况下随机化试验

如何解决Matlab:如何在不连续呈现相同试验的情况下随机化试验

我是 Matlab 的初学者,在 Matlab 的 PsychtoolBox 任务中,我正在努力进行随机试验。我的试验包括 5 次重复 12 次的语言刺激(总共 60 次试验)。我有 2 次练习试验,然后是 60 次测试试验。我想要做的就是按照固定的顺序呈现练习试验,以随机的顺序呈现测试试验,而不是连续重复相同的语言刺激。

我的刺激文件 (stim.txt) 有一列“项目”,其中的刺激看起来像:

练习1

练习 2

word1

word2

word3

word4

word5

word1

word2

word3

word4

word5

.... x 其他 11 次(仅重复测试刺激)....

这是我的代码感兴趣的部分:

%here I define the trial info
trial = 1;
maxTrial = length(stim.items); %this is the excel file from which I take the stimuli 

% I define the number of practice trials 
NumOfPracticeTrials=2;

%I randomize only the testing trials 
TrialIndex(NumOfPracticeTrials+1:maxTrial)=NumOfPracticeTrials+randperm((maxTrial-NumOfPracticeTrials); 

代码有效,因此我以固定顺序呈现练习试验,而测试试验是随机的。然而,当我进行实验时,一些测试性的语言刺激会连续重复两次甚至更多次。

我想在不连续重复相同的语言刺激的情况下随机化测试试验。

我可以请你帮忙吗?非常非常感谢你!! :)

解决方法

如您所述,生成伪随机序列的一种方法是在每次试验中随机选择一个不等于前一次试验的词。下面是一个示例(称为“方法 1”)。为清楚起见,随机值是数字 1-5,对应 5 个单词,而不是上述 TrialIndex 中的位置。

这种伪随机化的一个潜在问题是,与随机排序不同,您不能保证在整个实验中呈现的 5 个单词的比例相等,因为单词是在每次试验中随机选择的。

受 Python 中的这个答案 https://stackoverflow.com/a/52556609/2205580 启发的另一种方法是对子序列进行混洗和附加。这种方法生成相同数量的每个混洗值,但具有随机性降低的缺点。具体来说,由于值以块为单位进行混洗,因此单词的下一次出现将在某种程度上是可预测的,这对于在呈现单词后多长时间再次呈现存在限制。这在下面显示为“方法 2”

% generating sequence
num_words = 5;
word_options = 1:num_words;
num_repeats = 13;
num_trials = num_words * num_repeats;


% Method 1

word_order = nan(1,num_trials);

% randomly choose a word (1-5) for the initial trial
word_order(1) = randi(5);

% for each subsequent trial,randomly choose a word that isn't a repeat
for k = 2:num_trials
    word_order(k) = RandSel(setdiff(word_options,word_order(k-1)),1);
end

% diagnostics on sequence
disp('Word Order:')
disp(word_order);
% verify there are no repeated elements in the sequenceas
has_repeats = any(diff(word_order) == 0);
if (has_repeats)
    disp('sequence has sequential repeats!')
else
    disp('sequence has no sequential repeats!')
end

for k = 1:num_words
   fprintf('Word %i is present at a rate of %2.2f \n',k,mean(word_order == k)); 
end


% Method 2

word_order = nan(1,num_trials);

for k = 1:num_words:num_trials
    subsequence = Shuffle(word_options);
    word_order(k:k+(num_words-1)) = subsequence;
    % swap the first value of this subsequence if it repeats the previous
    if k > 1 && (word_order(k) == word_order(k-1))
        word_order([k,k+1]) = word_order([k+1,k]);
    end
end

% diagnostics on sequence
disp('Word Order:')
disp(word_order);
% verify there are no repeated elements in the sequenceas
has_repeats = any(diff(word_order) == 0);
if (has_repeats)
    disp('sequence has sequential repeats!')
else
    disp('sequence has no sequential repeats!')
end

for k = 1:num_words
   fprintf('Word %i is present at a rate of %2.2f \n',mean(word_order == k)); 
end

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。