forked from tiesmaaj/trial_and_error
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_script.m
More file actions
51 lines (40 loc) · 1.67 KB
/
example_script.m
File metadata and controls
51 lines (40 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
%% Sample Script
close all; clear; clc;
load('data/Motion1/Motion1_VisOnly.mat')
rawData = data_output;
processedData = preprocessData(rawData);
processedData = processedData(processedData.Stimulus ~= 0, :);
processedData = processedData(~isnan(processedData.RT), :);
% Make descriptive plots
visualizeDescriptiveAnalysis(processedData,2);
% Make DDM plots
DDM_SNR(processedData);
% Initialize the drift variable
numTrials = height(processedData);
drift = zeros(1, numTrials); % Initialize drift state
initial_state = 0; % Start drift at zero
drift(1) = initial_state;
% Normalize Response for drift calculations
normalizedResponse = processedData.Response; % Copy original response
normalizedResponse(normalizedResponse == 2) = -1; % Right -> -1 (toward bottom boundary)
normalizedResponse(normalizedResponse == 1) = 1; % Left -> +1 (toward top boundary)
% Loop through trials and calculate drift
for t = 2:numTrials
if ~isnan(normalizedResponse(t)) && ~isnan(processedData.PrevOutcome(t))
if processedData.PrevOutcome(t) == 1 % Correct
drift(t) = drift(t-1) + normalizedResponse(t); % Positive drift
elseif processedData.PrevOutcome(t) == 0 % Incorrect
drift(t) = drift(t-1) - normalizedResponse(t); % Negative drift
end
else
drift(t) = drift(t-1); % No change if PrevOutcome or Response is NaN
end
end
verifyRTDriftCorrelation(processedData, drift);
%averageDriftState = mean(drift);
%disp(['Average Drift State: ', num2str(averageDriftState)]);
% Example Data
%data.SNR = rand(100, 1); % Random SNR values
%data.Response = rand(100, 1) < 0.5 + 0.3 * data.SNR; % Synthetic responses
% Test Function
%fitBayesianModel(data);