-
Notifications
You must be signed in to change notification settings - Fork 1
/
calls_count_analysis.m
434 lines (366 loc) · 14.6 KB
/
calls_count_analysis.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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
%% Get basic info about testing days, number of subjects, etc.
info = inputdlg(["Start day","Interval","End day"], 'double');
start_day = str2num(cell2mat(info(1))); %First recordings on P6
interval = str2num(cell2mat(info(2))); %Record every 2 days
end_day = str2num(cell2mat(info(3))); %Last recordings on P18
n_days = length(start_day:interval:end_day);
[indx_params] = listdlg('ListString',{'count','duration','frequency',...
'slope','tonality'},...
'PromptString',{'Select parameters to analyze'});
[indx_analysis] = listdlg('ListString',{'kruskal-wallis anova','mean ranks multiple comparisons test'...
'plot subject means (error bars)','plot subject means (individuals)'},...
'PromptString',{'Select analyses to run'});
subj_names = unique(cohortfull.ratID);
n_subjects = length(subj_names);
colormap = parula;
colormap_n = colormap(1:256/n_subjects:256,:); %que carajo es esto????
%% Counts analysis
if (any(indx_params==1))
% initialize variables
m_count = []; % mean
se_count = []; % standard error of mean
daily_means = []; % daily means
day_counts = []; % daily ?
% Get daily means for all variables
subj_names = unique(cohortfull.ratNumber);
mycolormap=parula(length(subj_names));
for k=1:n_days
day = (start_day-interval)+(k*interval);
indexes = cohortfull.day==day;
subT = cohortfull(indexes,:); %Subtable containg only day k's data
for n=1:length(subj_names)
indiv_indexes = subT.ratNumber==subj_names(n);
day_counts(n,k) = sum(indiv_indexes);
if sum(indiv_indexes)==0, day_counts(n,k)=nan; end
end
end
daily_means = mean(day_counts, 'omitnan'); %Mean across subjects per day
subject_means = mean(day_counts, 2, 'omitnan'); %Mean across days per subject
se_count = std(day_counts,1,'omitnan');
% Figures
%K-W test
if (any(indx_analysis==1))
[p,tab,stats] = kruskalwallis(day_counts);
hold on; box off;
xticklabels([start_day:interval:end_day]);
title('Number of calls');
xlabel('Postnatal Day');
ylabel('Number of USVs');
end
if (any(indx_analysis==2))
multcompare(stats);
end
% Plot individual and overall means by day, with error bar
if (any(indx_analysis==3))
figure(10); hold on;
errorbar(daily_means,se_count,'k-','LineWidth',1)
%plot(daily_subject_means,'k-','LineWidth',1)
%plotSpread(day_counts);
box off; zoom out;
title('Number of calls');
xlabel('Postnatal Day');
ylabel('Number of USVs');
xticklabels(start_day:interval:end_day);
end
% Plot individual means by day, tracking each subject
if (any(indx_analysis==4))
figure(11); hold on;
day_counts_sorted = sortrows(day_counts,1,'ascend');
for m=1:size(day_counts_sorted,1)
plot(day_counts_sorted(m,:),'Color',mycolormap(m,:),'LineWidth',1.5);
end
box off; zoom out;
title('Number of calls');
xlabel('Postnatal Day');
ylabel('Number of USVs');
xticklabels([start_day:interval:end_day]);
end
end
%% Duration analysis
if (any(indx_params==2))
% initialize variables
m_duration = [];
se_duration = [];
% Get daily means for all variables
subj_means_duration = [];
subj_sds = [];
subj_names = unique(cohortfull.ratNumber);
for k=1:n_days
day = (start_day-interval)+(k*interval);
indexes = cohortfull.day==day;
subT = cohortfull(indexes,:);
m_duration(end+1) = mean(subT.CallLengths);
for n=1:length(subj_names)
indiv_indexes = subT.ratNumber==subj_names(n);
subsubT = subT(indiv_indexes,:);
subj_means_duration(n,k) = mean(subsubT.CallLengths);
subj_sds(n,k) = std(subsubT.CallLengths);
end
m_duration(end) = mean(subT.CallLengths); %Mean duration for all calls that day
end
se_duration = std(subj_sds, 'omitnan');
daily_subject_means_duration = mean(subj_means_duration, 'omitnan'); %Mean across subjects per day
subject_7day_duration = mean(subj_means_duration, 2, 'omitnan'); %Mean across days per subject
% Figures
%K-W test
if (any(indx_analysis==1))
[p,tab,stats] = kruskalwallis(subj_means_duration);
hold on; box off;
xticklabels([start_day:interval:end_day]);
title('Call Duration');
xlabel('Postnatal Day');
ylabel('Mean subject call duration (sec)');
end
if (any(indx_analysis==2))
multcompare(stats);
end
% Plot individual and overall means by day, with error bar
if (any(indx_analysis==3))
figure; hold on;
errorbar(daily_subject_means_duration,se_duration,'k-','LineWidth',1)
%plotSpread(subj_means_duration)
%plot(daily_subject_means,'k-','LineWidth',1)
box off; zoom out;
xticklabels([start_day:interval:end_day]);
title('Call Duration');
xlabel('Postnatal Day');
ylabel('Mean subject call duration (sec)');
end
% Plot individual means by day, tracking each subject
if (any(indx_analysis==4))
figure(21); hold on;
subj_means_duration_sorted = sortrows(subj_means_duration,1,'ascend');
for m=1:length(subj_names)
plot(subj_means_duration_sorted(m,:),'Color',mycolormap(m,:),'LineWidth',1.5);
end
title('Call Duration');
xlabel('Postnatal Day');
ylabel('Mean subject call duration (sec)');
xticklabels([start_day:interval:end_day]);
end
end
%% Frequency analysis
if (any(indx_params==3))
% initialize variables
m_principal = [];
se_principal = [];
m_delta = [];
se_delta = [];
% Get daily means for all variables
subj_means_principal = [];
subj_sds = [];
subj_means_delta = [];
subj_sds_delta = [];
subj_names = unique(cohortfull.ratNumber);
for k=1:n_days
day = (start_day-interval)+(k*interval);
indexes = cohortfull.day==day;
subT = cohortfull(indexes,:);
m_principal(end+1) = mean(subT.PrincipalFrequencykHz);
m_delta(end+1) = mean(subT.DeltaFreqkHz);
for n=1:length(subj_names)
indiv_indexes = subT.ratNumber==subj_names(n);
subsubT = subT(indiv_indexes,:);
subj_means_principal(n,k) = mean(subsubT.PrincipalFrequencykHz);
subj_sds(n,k) = std(subsubT.PrincipalFrequencykHz);
subj_means_delta(n,k) = mean(subsubT.DeltaFreqkHz);
subj_sds_delta(n,k) = std(subsubT.DeltaFreqkHz);
end
m_principal(end) = mean(subT.PrincipalFrequencykHz); %Mean principal freq for all calls that day
m_delta(end) = mean(subT.DeltaFreqkHz); %Mean dFreq for all calls that day
end
se_principal = std(subj_sds, 'omitnan');
se_delta = std(subj_sds, 'omitnan');
daily_subject_means_principal = mean(subj_means_principal, 'omitnan'); %Mean across subjects per day
subject_7day_principal = mean(subj_means_principal, 2, 'omitnan'); %Mean across days per subject
daily_subject_means_delta = mean(subj_means_delta, 'omitnan'); %Mean across subjects per day
subject_7day_delta = mean(subj_means_delta, 2, 'omitnan'); %Mean across days per subject
% Figures
%K-W test
if (any(indx_analysis==1))
[p,tab,stats_pr] = kruskalwallis(subj_means_principal);
hold on; box off;
xticklabels([start_day:interval:end_day]);
title('Principal USV frequency');
xlabel('Postnatal Day');
ylabel('Mean subject principal USV frequency (kHz)');
[p,tab,stats_d] = kruskalwallis(subj_means_delta);
hold on; box off;
xticklabels([start_day:interval:end_day]);
title('USV Delta frequency');
xlabel('Postnatal Day');
ylabel('Mean subject USV dFrequency (kHz)');
end
if (any(indx_analysis==2))
multcompare(stats_pr);
multcompare(stats_d);
end
% Plot individual and overall means by day, with error bar
if (any(indx_analysis==3))
figure(30); hold on;
errorbar(daily_subject_means_principal,se_principal,'k-','LineWidth',1)
%plotSpread(subj_means_principal)
%plot(daily_subject_means,'k-','LineWidth',1)
box off; zoom out;
xticklabels([start_day:interval:end_day]);
title('Principal USV frequency');
xlabel('Postnatal Day');
ylabel('Mean subject principal USV frequency (kHz)');
figure(31); hold on;
errorbar(daily_subject_means_delta,se_delta,'k-','LineWidth',1)
plotSpread(subj_means_delta)
%plot(daily_subject_means,'k-','LineWidth',1)
box off; zoom out;
xticklabels([start_day:interval:end_day]);
title('USV Delta frequency');
xlabel('Postnatal Day');
ylabel('Mean subject USV dFrequency (kHz)');
end
% Plot individual means by day, tracking each subject
if (any(indx_analysis==4))
figure(32); hold on;
subj_means_principal_sorted = sortrows(subj_means_principal,1,'ascend');
for m=1:12
plot(subj_means_principal_sorted(m,:),'Color',colormap12(m,:),'LineWidth',1.5);
end
title('Principal USV frequency');
xlabel('Postnatal Day');
ylabel('Mean subject principal USV frequency (kHz)');
xticklabels([start_day:interval:end_day]);
figure(33); hold on;
subj_means_delta_sorted = sortrows(subj_means_delta,1,'ascend');
for m=1:length(subj_names)
plot(subj_means_delta_sorted(m,:),'Color',mycolormap(m,:),'LineWidth',1.5);
end
title('USV Delta frequency');
xlabel('Postnatal Day');
ylabel('Mean subject USV dFrequency (kHz)');
xticklabels([start_day:interval:end_day]);
end
end
%% Slope analysis
if (any(indx_params==4))
% initialize variables
m_slope = [];
se_slope = [];
% Get daily means for all variables
subj_means_slope = [];
subj_sds = [];
subj_names = unique(cohortfull.ratNumber);
for k=1:n_days
day = (start_day-interval)+(k*interval);
indexes = cohortfull.day==int2str(day);
subT = cohortfull(indexes,:);
m_slope(end+1) = mean(subT.SlopekHzs);
for n=1:length(subj_names)
indiv_indexes = subT.ratNumber==subj_names(n);
subsubT = subT(indiv_indexes,:);
subj_means_slope(n,k) = mean(subsubT.SlopekHzs);
subj_sds(n,k) = std(subsubT.SlopekHzs);
end
m_slope(end) = mean(subT.SlopekHzs); %Mean slope for all calls that day
end
se_slope = std(subj_sds, 'omitnan');
daily_subject_means = mean(subj_means_slope, 'omitnan'); %Mean across subjects per day
subject_7day = mean(subj_means_slope, 2, 'omitnan'); %Mean across days per subject
% Figures
%K-W test
if (any(indx_analysis==1))
[p,tab,stats] = kruskalwallis(subj_means_slope);
hold on; box off;
xticklabels([start_day:interval:end_day]);
title('USV slope');
xlabel('Postnatal Day');
ylabel('Mean subject USV slope (kHz/s)');
end
if (any(indx_analysis==2))
multcompare(stats);
end
% Plot individual and overall means by day, with error bar
if (any(indx_analysis==3))
figure(40); hold on;
errorbar(daily_subject_means,se_slope,'k-','LineWidth',1)
plotSpread(subj_means_slope)
%plot(daily_subject_means,'k-','LineWidth',1)
box off; zoom out;
title('USV slope');
xlabel('Postnatal Day');
ylabel('Mean subject USV slope (kHz/s)');
xticklabels([start_day:interval:end_day]);
end
% Plot individual means by day, tracking each subject
if (any(indx_analysis==4))
figure(41); hold on;
subj_means_slope_sorted = sortrows(subj_means_slope,1,'ascend');
for m=1:length(subj_names)
plot(subj_means_slope_sorted(m,:),'Color',mycolormap(m,:),'LineWidth',1.5);
end
title('USV slope');
xlabel('Postnatal Day');
ylabel('Mean subject USV slope (kHz/s)');
xticklabels([start_day:interval:end_day]);
end
end
%% Tonality analysis
if (any(indx_params==5))
% initialize variables
m_tonality = [];
se_tonality = [];
% Get daily means for all variables
subj_means_tonality = [];
subj_sds = [];
subj_names = unique(cohortfull.ratNumber);
for k=1:n_days
day = (start_day-interval)+(k*interval);
indexes = cohortfull.day==day;
subT = cohortfull(indexes,:);
m_tonality(end+1) = mean(subT.Tonality);
for n=1:length(subj_names)
indiv_indexes = subT.ratNumber==subj_names(n);
subsubT = subT(indiv_indexes,:);
subj_means_tonality(n,k) = mean(subsubT.Tonality);
subj_sds(n,k) = std(subsubT.Tonality);
end
m_tonality(end) = mean(subT.Tonality); %Mean tonality for all calls that day
end
se_tonality = std(subj_sds, 'omitnan');
daily_subject_means = mean(subj_means_tonality, 'omitnan'); %Mean across subjects per day
subject_7day = mean(subj_means_tonality, 2, 'omitnan'); %Mean across days per subject
% Figures
%K-W test
if (any(indx_analysis==1))
[p,tab,stats] = kruskalwallis(subj_means_tonality);
hold on; box off;
xticklabels([start_day:interval:end_day]);
title('Tonality');
xlabel('Postnatal Day');
ylabel('Mean subject USV tonality (dB/kHz)');
end
if (any(indx_analysis==2))
multcompare(stats);
end
% Plot individual and overall means by day, with error bar
if (any(indx_analysis==3))
figure(50); hold on;
errorbar(daily_subject_means,se_tonality,'k-','LineWidth',1)
%plotSpread(subj_means_tonality)
%plot(daily_subject_means,'k-','LineWidth',1)
box off; zoom out;
title('Tonality');
xlabel('Postnatal Day');
ylabel(sprintf('Mean subject \n USV tonality (dB/kHz)'));
xticklabels([start_day:interval:end_day]);
end
% Plot individual means by day, tracking each subject
if (any(indx_analysis==4))
figure(51); hold on;
subj_means_tonality_sorted = sortrows(subj_means_tonality,1,'ascend');
for m=1:length(subj_names)
plot(subj_means_tonality_sorted(m,:),'Color',mycolormap(m,:),'LineWidth',1.5);
end
title('Tonality');
xlabel('Postnatal Day');
ylabel('Mean subject USV tonality (dB/kHz)');
xticklabels([start_day:interval:end_day]);
end
end