首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Matlab:如何在不连续呈现相同试验的情况下对试验进行随机化

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

Stack Overflow用户
提问于 2021-02-12 18:21:18
回答 1查看 121关注 0票数 0

我是Matlab的初学者,我正在为随机试验而苦苦挣扎在我的心理工具箱的任务中,在Matlab中。我的试验包括5个言语刺激,重复12次(总共60次试验)。我有两个练习赛,然后是60个测试赛。我想做的是以固定的顺序呈现练习试验,以随机顺序呈现测试试验,而不是连续重复相同的语言刺激。

我的刺激文件(stim.txt)有一列"items“,其中的刺激如下:

practice1

练习2

word1

word2

word3

word4

word5

word1

word2

word3

word4

word5

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

下面是我的代码中有趣的部分:

代码语言:javascript
复制
%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); 

这段代码可以工作,所以我以固定的顺序呈现实践试验,而测试试验是随机的。然而,当我运行实验时,一些测试语言刺激连续重复两次甚至更多次。

我想将测试试验随机化,而不是连续重复相同的语言刺激。

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

EN

回答 1

Stack Overflow用户

发布于 2021-02-14 05:18:10

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

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

另一种不同的方法,灵感来自Python语言中的这个答案,https://stackoverflow.com/a/52556609/2205580,是混洗和附加子序列。这种方法生成相同数量的每个混洗值,但具有减少随机性的缺点。具体地说,由于值是以块为单位进行混洗的,因此下一个单词的出现在某种程度上是可以预测的,这就限制了在一个单词出现后多久它将再次出现。这在下面显示为“方法2”。

代码语言:javascript
复制
% 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', k, mean(word_order == k)); 
end
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66170036

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档