Commit 8dabfd89 authored by Hannah Slack's avatar Hannah Slack

Delete OnlineTappingTaskAnalysisScript.m

parent e7f9a3bd
% Created by Hannah Slack, 05/08/2020.
% Script to analyse data from the Online Tapping Task run on Pavlovia.
%% First creates a blank table to save the data into.
headers = {'participant' ,'mu1','sig1', 'mu2', 'sig2'};
data = cell(0,5);
T = cell2table(data);
T.Properties.VariableNames = headers;
% reads in all the csv files in the specified folder.
files = dir(fullfile('/Users/hannahslack/Desktop/test', '*csv'));
% This loop runs the analysis for each file in the folder. Files MUST have filenames
% like 'OTT_PARTICIPANT1.csv'.
for i = 1:length(files)
%% Grab the data from the raw csv file.
%filename = ['OTT_PARTICIPANT' num2str(i) '.csv'];
filename = ['OTT_PARTICIPANT1.csv'];
%participantNum = participantNum +1;
% grabs the needed data from the relevant columns of the original csv file.
trialNum = readtable(filename,'Range','W5:W16'); trialNum = table2cell(trialNum);
condition = readtable(filename,'Range','I5:I16');condition = table2array(condition);
respTimes = readtable(filename,'Range','T5:T16'); respTimes = table2array(respTimes);
trial1=[]; %trial1=mat2cell(trial1,1);
trial2=0; %trial2=mat2cell(trial2,1);
trial3=0; %trial3=mat2cell(trial3,1);
trial4=0; %trial4=mat2cell(trial4,1);
trial5=0; %trial5=mat2cell(trial5,1);
trial6=0; %trial6=mat2cell(trial6,1);
trial7=0; %trial7=mat2cell(trial7,1);
trial8=0; %trial8=mat2cell(trial8,1);
trial9=0; %trial9=mat2cell(trial9,1);
trial10=0; %trial10=mat2cell(trial10,1);
trial11=0; %trial11=mat2cell(trial11,1);
trial12=0; %trial12=mat2cell(trial12,1);
trials = [trial1, trial2, trial3, trial4, trial5, trial6, trial7, trial8, trial9, trial10, trial11, trial12];
trials = mat2cell(trials,11)
for k=1:length(respTimes)
trial = respTimes(k);
trial = cell2mat(trial);
trial(1)=[] ;
trial = strsplit(trial,',');
neededLength = length(trial);
trials(k) = trial;
% puts all columns together into one cell array.
%Results=[trialNum condition tapTimes];
%% Run the analysis
RTdata =Results(:,5) -Results(:,3); % RT from the amber onset
% if cells are empty, it adds 4 NaN values to the table and skips
% the current excel file.
NoData = NaN(1,4);
OutResults = [participantNum, NoData];
OutResults = array2table(OutResults,'VariableNames',{'participant' ,'mu1','sig1', 'mu2', 'sig2'});
T = [T;OutResults];
%RTdata =Results(:,5) -Results(:,3); % RT from the amber onset
RTdata(find(RTdata<0)) = NaN; % remove the trials in which the response was made even before the amber onset.
t0 = 0.750; % average amber duration - HannahNote: may need to edit this depending on the variability of the amber duration for each participant.
t_gap = 0.050;
t1 = t_gap/2:t_gap:2;
t2 = t1 - t0; t2 = t2(num_zeros+1:end);
% convert RT into cumulative probability
RT_CP = [];
RT_PD = [];
for i = 1:length(t1)
RT_CP = [RT_CP length(find(RTdata < t1(i)+t_gap/2))./length(RTdata)];
RT_PD = [RT_PD length(find(RTdata>= t1(i)-t_gap/2 & RTdata < t1(i)+t_gap/2))./length(RTdata)];
% Figure
figure(1); hold on
set(gcf, 'position', [100 100 1300 500])
subplot(1,3,1); hold on
title(['Results']); hold on
plot(t1,RT_CP, 'ko-')
subplot(1,3,2); hold on
% Two horse race model
% Pr(T<t) = 1-normcdf(1./t1, mu1,sigma1) + 1-normcdf(1./t2, mu2,sigma2) - (1-normcdf(1./t1, mu1,sigma1)) .* 1-normcdf(1./t2, mu2,sigma2);
CP1_fun = @(mu1, sigma1) 1-normcdf(1./t1, mu1,sigma1);%cumulative probability
CP2_fun = @(mu2, sigma2) 1-normcdf(1./t2, mu2,sigma2); %cumulative probability
CP3_fun = @(param) (CP1_fun(param(1),param(2)) + [zeros(1,num_zeros) CP2_fun(param(3),param(4))] - CP1_fun(param(1),param(2)) .* [zeros(1,num_zeros) CP2_fun(param(3),param(4))]);
CP4_fun = @(param) sum((RT_CP - CP3_fun(param)).^2);
%param0 = [0.725, 0.618, 4.52, 1.27]; % Start from the values taken from Heyes et al. (2012)
param0 = [0.5, 0.5, 2.0, 2.0];
[param,fval,exitflag,output] = fminsearch(CP4_fun, param0);
% Figure
fig = figure(1);
subplot(1,3,1); hold on
plot(t1, CP3_fun(param0), 'bo-')
plot(t1, CP3_fun(param), 'ro-')
text(1.4, 0.36, ['mu1=' num2str(param(1),3)], 'color', 'k')
text(1.4, 0.32, ['sigma1=' num2str(param(2),3)], 'color', 'k')
text(1.4, 0.24, ['mu2=' num2str(param(3),3)], 'color', 'k')
text(1.4, 0.20, ['sigma2=' num2str(param(4),3)], 'color', 'k')
subplot(1,3,2); hold on
CP3 = CP3_fun(param);
CP3_pd = CP3(1:end) - [0 CP3(1:end-1)];
plot(t1, CP3_pd, 'r', 'linewidth', 4)
subplot(1,3,3); hold on
CP1 = CP1_fun(param(1), param(2));
CP1_pd = CP1(1:end) - [0 CP1(1:end-1)];
plot(t1, CP1_pd, 'color', [255 102 0]/255, 'linewidth', 3)
CP2 = CP2_fun(param(3), param(4));
CP2_pd = CP2(1:end) - [0 CP2(1:end-1)];
plot(t2+t0, CP2_pd, 'color', [51 204 51]/255, 'linewidth', 3)
Two_horse = [param];
%% save the 2HorseRaceModelFigure and the 2HorseRaceModelParameters
% saves figure as a png file with participant's number.
saveas(fig,['DRT_PARTICIPANT' num2str(participantNum) '.png']);
clf % clear figure ready for next iteration.
OutResults = [participantNum, Two_horse]; %creates new array with Pnumber and 2HorseRace parameters for this participant.
% Turns that array into a table with the relevant headers.
OutResults = array2table(OutResults,'VariableNames',{'participant' ,'mu1','sig1', 'mu2', 'sig2'});
% Joins the current table with this new table (adds this
% participant to the overall table containing the data from
% all the participants/raw excel files.
T = [T;OutResults];
%% save ALL the 2HorseModelParameters from ALL participants into one big xlsx file.
filename = ['DRT_RESULTS.xlsx'];
\ No newline at end of file
  • An irrelevant file thats contents were unrelated to the tapping task. To analyse the tapping task, use the python script instead.

Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment