-
Notifications
You must be signed in to change notification settings - Fork 0
/
statistics.m
130 lines (82 loc) · 7.42 KB
/
statistics.m
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
% this script if for deciding the groups you want to conduct chi square
% and using the function ,chiSquareFunction, to conduct chi square of
% independence & fisher's extract test
% in this experiment we will compare 2 probes (orientation & duration) and performance in surprise %
% first control
clear
clc
addpath('./')
configIrrelevant;
cd(processedDataOnline)
addpath(genpath(processedDataOnline));
% load files
load('criticalTable.mat');
load('postTable.mat');
%% Groups to compare
%post - get first control data
participantID = criticalTable.ParticipantID; % iterate over all subjects and get the first control performance
for i= 1: numel(participantID)
currentParticipant = participantID(i);
participantData = postTable(postTable.ParticipantID == currentParticipant,:);
firstControlData{i} = participantData(1,:); %post orientation scores
end
%convert it to table
firstControlData = vertcat(firstControlData{:});
%% prepare matched pairs
faceOrientationCritical = [num2cell(criticalTable.orientationPerformance(strcmp(criticalTable.groupName, 'face'))), repmat({'face'}, sum(strcmp(criticalTable.groupName, 'face')), 1)];
faceDurationCritical = [num2cell(criticalTable.durationPerformance(strcmp(criticalTable.groupName, 'face'))), repmat({'face'}, sum(strcmp(criticalTable.groupName, 'face')), 1)];
objectOrientationCritical = [num2cell(criticalTable.orientationPerformance(strcmp(criticalTable.groupName, 'object'))), repmat({'object'}, sum(strcmp(criticalTable.groupName, 'object')), 1)];
objectDurationCritical = [num2cell(criticalTable.durationPerformance(strcmp(criticalTable.groupName, 'object'))), repmat({'object'}, sum(strcmp(criticalTable.groupName, 'object')), 1)];
faceOrientationPost = [num2cell(firstControlData.orientationAccuracy(strcmp(firstControlData.groupName, 'face'))), repmat({'face'}, sum(strcmp( firstControlData.groupName, 'face')), 1)];
faceDurationPost = [num2cell( firstControlData.durationAccuracy(strcmp(firstControlData.groupName, 'face'))), repmat({'face'}, sum(strcmp( firstControlData.groupName, 'face')), 1)];
objectOrientationPost = [num2cell(firstControlData.orientationAccuracy(strcmp(firstControlData.groupName, 'object'))), repmat({'object'}, sum(strcmp(firstControlData.groupName, 'object')), 1)];
objectDurationPost = [num2cell(firstControlData.durationAccuracy(strcmp(firstControlData.groupName, 'object'))), repmat({'object'}, sum(strcmp(firstControlData.groupName, 'object')), 1)];
orientationPerformance = [[faceOrientationCritical(:,1);objectOrientationCritical(:,1)],[faceOrientationCritical(:,2);objectOrientationCritical(:,2)],[repmat({'critical'},height(criticalTable),1)]];
durationPerformance = [[faceDurationCritical(:,1);objectDurationCritical(:,1)],[faceDurationCritical(:,2);objectDurationCritical(:,2)],[repmat({'critical'},height(criticalTable),1)]];
postOrientationPerformance = [[faceOrientationPost(:,1);objectOrientationPost(:,1)],[faceOrientationPost(:,2);objectOrientationPost(:,2)],[repmat({'control'},height(firstControlData),1)]];
postDurationPerformance = [[faceDurationPost(:,1);objectDurationPost(:,1)],[faceDurationPost(:,2);objectDurationPost(:,2)],[repmat({'control'},height(firstControlData),1)]];
orientationCombined = cell2table([orientationPerformance;postOrientationPerformance],'VariableNames',{'accuracy','group','test'});
durationCombined = cell2table([durationPerformance;postDurationPerformance],'VariableNames',{'accuracy','group','test'});
%decide the index
faceIndexOrientation = strcmp(orientationCombined.group,'face');
objectIndexOrientation = strcmp(orientationCombined.group,'object');
faceIndexDuration = strcmp(durationCombined.group,'face');
objectIndexDuration= strcmp(durationCombined.group,'object');
%% stats for comparing probes in critical trial + in different stimulus categories (within subject) - linear mixed models
%% stats for comparing critical & post-surprise (within subject) - McNemar's test
[contFaceOrientation ,~ ,~ ,McNemfaceOrientation] = statsFunction(orientationCombined.test(faceIndexOrientation),orientationCombined.accuracy(faceIndexOrientation),'critical','control',2,1); % give the data ensuring b < c (if not b = c) and check whether b+c>10 for power
[contFaceDuration,~,~,McNemfaceDuration] = statsFunction(durationCombined.test(faceIndexDuration),durationCombined.accuracy(faceIndexDuration),'critical','control',2,1);
[contObjectOrientation,~,~,McNemobjectOrientation]= statsFunction(orientationCombined.test(objectIndexOrientation),orientationCombined.accuracy(objectIndexOrientation),'control','critical',2,1);
[contObjectDuration,~,~,McNemobjectDuration] = statsFunction(durationCombined.test(objectIndexDuration),durationCombined.accuracy(objectIndexDuration),'critical','control',2,1);
faceOrientationStats = {array2table(contFaceOrientation),array2table(McNemfaceOrientation)};
faceDurationStats = {array2table(contFaceDuration),array2table(McNemfaceDuration)};
objectOrientationStats = {array2table(contObjectOrientation),array2table(McNemobjectOrientation)};
objectDurationStats = {array2table(contObjectDuration),array2table(McNemobjectDuration)};
%% stats for comparing order effect (within subject) - fisher's exact test
[contTableOrientationOrder,chiOrientationOrder,fisherOrientationOrder] = statsFunction(criticalTable.probeOrder,criticalTable.orientationPerformance,'orientationFirst','durationFirst',1,0); % between group orientation
[contTableDurationOrder,chiDurationOrder,FisherDurationOrder] = statsFunction(criticalTable.probeOrder,criticalTable.durationPerformance,'durationFirst','orientationFirst',1,0); % always put the one you expect better performance (based on your hypothesis) first
orientationOrderStats = {array2table(contTableOrientationOrder),chiOrientationOrder,fisherOrientationOrder};
durationOrderStats = {array2table(contTableDurationOrder),chiDurationOrder,FisherDurationOrder};
%% stats for comparing performance in face and object (between subject)
[contTableStimO,chiStimO,fisherStimO] = statsFunction(criticalTable.groupName,criticalTable.orientationPerformance,'face','object',2,0); % between group orientation
[contTableStimD,chiStimD,fisherStimD] = statsFunction(criticalTable.groupName,criticalTable.durationPerformance,'face','object',2,0);
[contTablePostStimO,chiPostStimO,fisherPostStimO] = statsFunction(firstControlData.groupName,firstControlData.orientationAccuracy,'face','object',2,0);
[contTablePostStimD,chiPostStimD,fisherPostStimD] = statsFunction(firstControlData.groupName,firstControlData.durationAccuracy,'face','object',2,0);
orientationStats = {array2table(contTableStimO),chiStimO,fisherStimO};
durationStats = {array2table(contTableStimD),chiStimD,fisherStimD};
postOrientationStats = {array2table(contTablePostStimO),chiPostStimO,fisherPostStimO};
postDurationStats = {array2table(contTablePostStimD),chiPostStimD,fisherPostStimD};
%% save the stats
pilot1Stats = struct();
pilot1Stats.orientationOrderStats = orientationOrderStats;
pilot1Stats.durationOrderStats = durationOrderStats;
pilot1Stats.orientationGroupComp = orientationStats;
pilot1Stats.orientationPostGroupComp = postOrientationStats;
pilot1Stats.durationGroupComp= durationStats;
pilot1Stats.durationPostGroupComp=postDurationStats;
pilot1Stats.faceOrientation = faceOrientationStats;
pilot1Stats.faceDuration = faceDurationStats;
pilot1Stats.objectOrientation = objectOrientationStats;
pilot1Stats.objectDuration = objectDurationStats;
pilot1StatsName = 'pilot1OnlineStats.mat';
save(fullfile(processedDataOnline,pilot1StatsName),'pilot1Stats');