-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpost_hoc_stats.m
304 lines (256 loc) · 9.33 KB
/
post_hoc_stats.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
% script to do statistics post hoc on data
%%
savePlots = 1;
folderDataBase = '/Users/davidcaldwell/Box/KLEENLAB/David/Results/June results fewer subj/';
folderFiguresCell = {fullfile(folderDataBase,'LL20'),fullfile(folderDataBase,'LL40'),fullfile(folderDataBase,'LL100'),fullfile(folderDataBase,'absDer')};
saveName = {'LL20','LL40','LL100','absDer'};
statsStruct = struct;
outputTable = table;
% load in data
for jj = 1:length(saveName)
processedInt = saveName{jj};
folderFigures = folderFiguresCell{jj};
dataFile = fullfile(folderFigures,[processedInt '.mat']);
load(dataFile);
%%
subjCell = [];
for jjj = 1:length(permResultsCell)
subjCell{end+1} = permResultsCell{jjj}.subj;
end
numEls = length(permResultsCell);
% c= cmocean('thermal',numEls);
c = brewermap(numEls,'Set3');
disp(numEls);
%%
numChannelsVec = [];
meanWidthVec = [];
meanWidthSID = {};
numChannelsVecSub = [];
meanWidthVecSub = [];
numChannelsSID = {};
%
for jjj = 1:length(permResultsCell)
% if sum(strcmp(patientsVetted{jj},patientsInt))
width = permResultsCell{jjj}.meanWidth;
widthSub = permResultsCell{jjj}.meanWidthSub;
num = permResultsCell{jjj}.numSigChannels;
numSub = permResultsCell{jjj}.numSigChannelsSub;
subj = permResultsCell{jjj}.subj;
if ~isnan(width) & ~isnan(widthSub)
meanWidthVec = [meanWidthVec width];
meanWidthVecSub = [meanWidthVecSub widthSub];
meanWidthSID{end+1} = subj;
end
if ~isnan(num) & ~isnan(numSub)
numChannelsVec = [numChannelsVec num];
numChannelsVecSub = [numChannelsVecSub numSub];
numChannelsSID{end+1} = subj;
end
% end
end
%% plot
colorHist = cmocean('thermal',2);
colorParallel = brewermap(numEls,'Set3');
histFig = figure;
tiledlayout(2,2,'TileSpacing','Compact','Padding','Compact');
histFig.Position = [839 109 1408 1229];
nexttile
histogram(meanWidthVec,BinWidth=10)
hold on
histogram(meanWidthVecSub,BinWidth=10)
legend({'High density','Sub-sampled'})
title([processedInt ' Mean Width Histogram'])
xlim([0 max([meanWidthVec(:);meanWidthVecSub(:)])+10])
set(gca,'FontSize',14)
nexttile
histogram(numChannelsVec,BinWidth=1)
hold on
histogram(numChannelsVecSub,BinWidth=1)
legend({'High density','Sub-sampled'})
title([processedInt ' Number of Channels Histogram'])
set(gca,'FontSize',14)
xlim([0 max([numChannelsVec(:);numChannelsVecSub(:)])+3])
colormapSpecificWidth = [];
for jjj = 1:length(subjSpecific)
ind = find(strcmp(subjCell,subjSpecific(jjj)));
colormapSpecificWidth = [colormapSpecificWidth; colorParallel(ind,:)];
end
ax= nexttile;
grid(ax,'on')
xlim([0.5 2.5])
ylim([0 max([meanWidthVec(:);meanWidthVecSub(:)])+10])
hold on
p1=plot([1,2],[meanWidthVec;meanWidthVecSub]','-o','LineWidth',4);
xlabel('High density vs. Sub-sampled')
ylabel('Mean width')
title([processedInt ' mean spike subject wise comparison'])
set(gca,'FontSize',14)
ax.XTickLabel ={'','High density','','Sub-sampled',''};
colororder(gca,colormapSpecificWidth)
for colorInd = 1:length(meanWidthVec)
p1(colorInd).MarkerFaceColor = colormapSpecificWidth(colorInd,:);
end
colormapSpecificNum = [];
for jjj = 1:length(subjSpecific)
ind = find(strcmp(subjCell,subjSpecific(jjj)));
colormapSpecificNum = [colormapSpecificNum; colorParallel(ind,:)];
end
ax = nexttile;
xlim([0.5 2.5])
grid(ax,'on')
ylim([0 max([numChannelsVec(:);numChannelsVecSub(:)])+3])
hold on
p2=plot([1,2],[numChannelsVec;numChannelsVecSub]','-o','LineWidth',4);
ylabel('Number of channels with significant spikes')
xlabel('High density vs. Sub-sampled')
title([processedInt ' number spike channels subject wise comparison'])
set(gca,'FontSize',14)
ax.XTickLabel ={'','High density','','Sub-sampled',''};
colororder(gca,colormapSpecificNum)
for colorInd = 1:length(numChannelsVec)
p2(colorInd).MarkerFaceColor = colormapSpecificNum(colorInd,:);
end
if savePlots
exportgraphics(histFig,fullfile(folderFigures,[processedInt '_2x2.png']),'Resolution',600)
exportgraphics(histFig,fullfile(folderFigures,[processedInt '_2x2.eps']))
end
%% stats
[pNum,hNum,statsNum] = signrank(numChannelsVec,numChannelsVecSub);
[pWidth,hWidth,statsWidth] = signrank(meanWidthVec,meanWidthVecSub);
statsStruct.name{jj} = processedInt;
statsStruct.meanWidthSID{jj} = meanWidthSID;
statsStruct.numChannelsSID{jj} = numChannelsSID;
statsStruct.pNum{jj} = pNum;
statsStruct.pWidth{jj} = pWidth;
statsStruct.meanWidthVec{jj} = meanWidthVec;
statsStruct.meanWidthVecSub{jj} = meanWidthVecSub;
statsStruct.numChannelsVec{jj} = numChannelsVec;
statsStruct.numChannelsVecSubj{jj} = numChannelsVecSub;
statsStruct.meanWidthDiff{jj} = meanWidthVec - meanWidthVecSub;
statsStruct.numChannelsDiff{jj} = numChannelsVec - numChannelsVecSub;
end
%%
figure
tiledlayout(2,1,'TileSpacing','Compact','Padding','Compact');
grid(ax,'on')
nexttile
hold on
for jj = 1:length(saveName)
subjSpecific = statsStruct.meanWidthSID{jj};
colormapSpecific = [];
for jjj = 1:length(subjSpecific)
ind = find(strcmp(subjCell,subjSpecific(jjj)));
colormapSpecific = [colormapSpecific; c(ind,:)];
end
swarmchart(jj,statsStruct.meanWidthDiff{jj},[],colormapSpecific,'filled');
end
title('Differences in Mean Spike Duration by Condition')
xticks([0 1 2 3 4 5])
xticklabels({'','LL20','LL40','LL100','Absolute Derivative',''})
nexttile
grid(ax,'on')
hold on
for jj = 1:length(saveName)
subjSpecific = statsStruct.numChannelsSID{jj};
colormapSpecific = [];
for jjj = 1:length(subjSpecific)
ind = find(strcmp(subjCell,subjSpecific(jjj)));
colormapSpecific = [colormapSpecific; c(ind,:)];
end
swarmchart(jj,statsStruct.numChannelsDiff{jj},[],colormapSpecific,'filled');
end
title('Differences in Number of Channels with Spikes by Condition')
xticks([0 1 2 3 4 5])
xticklabels({'','LL20','LL40','LL100','Absolute Derivative',''})
xlabel('condition')
tempFig = gcf;
if savePlots
exportgraphics(tempFig,fullfile(folderDataBase,['swarm_across_conditions.png']),'Resolution',600)
exportgraphics(tempFig,fullfile(folderDataBase,['swarm_across_conditions.eps']))
end
%%
statsCell = {};
figure
tiledlayout(2,1,'TileSpacing','Compact');
ax = nexttile;
grid(ax,'on')
hold on
for jj = 1:length(saveName)
subjSpecific = statsStruct.meanWidthSID{jj};
colormapSpecific = [];
for jjj = 1:length(subjSpecific)
ind = find(strcmp(subjCell,subjSpecific(jjj)));
colormapSpecific = [colormapSpecific; c(ind,:)];
statsCell{ind}.cmap = c(ind,:);
if jj == 1
statsCell{ind}.data{1} = statsStruct.meanWidthDiff{jj}(jjj);
statsCell{ind}.cond{1} = jj;
else
statsCell{ind}.data{end+1} = statsStruct.meanWidthDiff{jj}(jjj);
statsCell{ind}.cond{end+1} = jj;
end
end
end
for jjj = 1:length(subjCell)
if ~isempty(statsCell{jjj})
linePlotPostHoc(jjj) = plot(cell2mat(statsCell{jjj}.cond),cell2mat(statsCell{jjj}.data),'-o','linewidth',4);
end
end
colororder(colormapSpecific);
for colorInd = 1:length(subjCell)
if ~isempty(statsCell{colorInd})
linePlotPostHoc(colorInd).MarkerFaceColor = c(colorInd,:);
end
end
title('Differences in Mean Spike Duration by Condition')
ylabel('Difference in Mean Spike Duration (ms)')
xticks([0 1 2 3 4 5])
xlim([0 5])
xticklabels({'','','','','',''})
%
ax = nexttile;
grid(ax,'on')
hold on
for jj = 1:length(saveName)
subjSpecific = statsStruct.numChannelsSID{jj};
colormapSpecificN = [];
for jjj = 1:length(subjSpecific)
ind = find(strcmp(subjCell,subjSpecific(jjj)));
colormapSpecificN = [colormapSpecificN; c(ind,:)];
statsCell{ind}.cmapN = c(ind,:);
if jj == 1
statsCell{ind}.dataN{1} = statsStruct.numChannelsDiff{jj}(jjj);
statsCell{ind}.condN{1} = jj;
else
statsCell{ind}.dataN{end+1} = statsStruct.numChannelsDiff{jj}(jjj);
statsCell{ind}.condN{end+1} = jj;
end
end
end
for jjj = 1:length(subjCell)
if ~isempty(statsCell{jjj})
linePlotPostHocN(jjj) = plot(cell2mat(statsCell{jjj}.condN),cell2mat(statsCell{jjj}.dataN),'-o','linewidth',4);
end
end
colororder(colormapSpecificN);
for colorInd = 1:length(subjCell)
if ~isempty(statsCell{colorInd})
linePlotPostHocN(colorInd).MarkerFaceColor = c(colorInd,:);
end
end
title('Differences in Number of Spikes Detected by Condition')
ylabel('Number of channels')
xlabel('Condition')
xticks([0 1 2 3 4 5])
xlim([0 5])
xticklabels({'','LL20','LL40','LL100','Absolute Derivative',''})
tempFig = gcf;
tempFig.Position = [986 636 581 702];
if savePlots
exportgraphics(tempFig,fullfile(folderDataBase,['across_conditions.png']),'Resolution',600)
exportgraphics(tempFig,fullfile(folderDataBase,['across_conditions.eps']))
end
%
%%
saveNameSpecific = 'spikeStats.mat';
save(fullfile(folderDataBase,saveNameSpecific),'statsStruct');