- 'splitapply' function: https://www.mathworks.com/help/matlab/ref/splitapply.html
- 'grpstats' function: https://www.mathworks.com/help/stats/grpstats.html
How to extract and plot different trial types in an experiment simulation
14 views (last 30 days)
Show older comments
Hi all, apologies if my question is a little out of scope. I've tried looking up some approaches but I'm still very new to MATLAB, so am learning on the job so to speak! I'm simulating an experiment for the Stroop task, as per my research question. I have 30 'virtual' subjects in each block of trials, 5 Words and thus also 5 colour (red blue green yellow purple) and am creating stimulus blocks for both healthy and neurologically impaired participant groups.
I seem to be running some scripts ok, and I'm satisfied with the ways in which my plots are looking (though the error bars are still a bit high - need to tweak parameters etc.) Anyway once concern I have is identifying which recorded result belongs to my independent variable. What is still needed here in my model is to understand the different trial types across the 70 trials blocks.
This is the current code for plotting my graphs (I haven't included the rest of the script) - it works, but isn't enough to thoroughly analyse the data and look at different trials' reaction times separately.
% plot graph
figure(1);
plot(mean(allsubjects_RTS));
% Error bars are one standard error from the mean:
errorbar(mean(allsubjects_RTS), std(allsubjects_RTS)/sqrt(SUBJECTS));
%Probably good to label the horizontal axis with tiral type
% hold on
%set(gca, 'XTick', [5 10 15 20 25 30 35])
%set(gca, 'XTickLabel', switchingblock_wici(:,4)');
title ('Mean Reaction Times by Trial');
% Figure 2: The mean error rate across trials, with error bars for one
% standard error
figure(2);
plot(mean(error_rate));
% Error bars are one standard error from the mean:
errorbar(mean(error_rate), std(error_rate)/sqrt(SUBJECTS));
%Probably good to label the horizontal axis with tiral type
%hold on
%set(gca, 'XTick', [5 10 15 20 25 30 35])
%set(gca, 'XTickLabel', switchingblock_wici(:,4)');
title('Mean Errors by Trial');
% Switch costs - FIXME! These need to take account of the different trial types
fprintf('sd_RT');
fprintf ('\n switch cost: word->colour: %f cycles', ...
(mean_RT(5) - sum(mean_RT(2:3)) / 2));
fprintf ('\n switch cost: colour->word: %f cycles', ...
(mean_RT(9) - sum(mean_RT(3:4))/2));
fprintf ('\n');
Sorry for it being a bit long, hopefully it looks sensible but I can try explain the calling functions I've put in too.
Thanks for any input you may have - MATLAB is very fun but learning it alongside a deadline can be tough!
0 Comments
Answers (1)
Balavignesh
on 10 Nov 2023
Hi Sophie,
As per my understanding, you would like your model to understand different trail types across the trial blocks, and identify which recorded result belongs to which independent variable.
I would suggest you add a column to your data that specifies the trial type. You could then use this column to group your data and analyze different trial types separately. you could also use built-in functions like 'splitapply' or 'grpstats' to group and analyze your data.
Here is an example code that could help you understand this:
% This is an example data. You could use your own dataset.
allsubjects_data = [randn(150,1)*0.1+0.5, randi([1,5],150,1)];
% create a vector of trial types
trial_types = repmat(1:5, 1, 30);
% add the trial type column to your data
allsubjects_data = [allsubjects_data, trial_types'];
% group the data by trial type and calculate the mean reaction time for each group
mean_RTs = splitapply(@mean, allsubjects_data(:,2), allsubjects_data(:,end));
% plot the mean reaction time for each trial type
figure;
bar(mean_RTs);
xlabel('Trial Type');
ylabel('Mean Reaction Time');
Kindly have a look at the following documentation links to have more information on:
Hope that helps!
Balavignesh.
0 Comments
See Also
Categories
Find more on Bar Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!