-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.m
90 lines (66 loc) · 2.38 KB
/
main.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
clear all
close all
clc
% add helper functions to path
addpath(genpath('fcn'));
% load regional time series
load data/ts.mat
% z-score time series
ts = zscore(ts);
% get dimensions
[ntime,nnodes] = size(ts);
% calculate number of edges
nedges = nnodes*(nnodes - 1)/2;
% indices of unique edges (upper triangle)
[u,v] = find(triu(ones(nnodes),1));
idx = (v - 1)*nnodes + u;
%% calculate static fc
fc = corr(ts);
%% generate edge time series
ets = ts(:,u).*ts(:,v);
%% plot average time averaged edge time series against upper triangle fc
fc_upper_triangle = fc(idx);
figure,plot(fc_upper_triangle,mean(ets),'ko')
xlabel('upper triangle fc matrix');
ylabel('time average of edge time series');
xlim([-1,1]); ylim([-1,1]);
text(0.8,-0.8,sprintf('r = %.2f',corr(fc_upper_triangle,mean(ets)')));
%% calculate event amplitude
% calculate co-fluctuation amplitude at each frame
rms = sum(ets.^2,2).^0.5;
% fraction of high- and low-amplitude frames to retain
frackeep = 0.1;
nkeep = round(ntime*frackeep);
% sort co-fluctuation amplitude
[~,idxsort] = sort(rms,'descend');
% estimate fc using just high-amplitude frames
fctop = corr(ts(idxsort(1:nkeep),:));
% do the same using just low-amplitude
fcbot = corr(ts(idxsort(end - nkeep + 1:end),:));
figure('position',[560,528,700,420])
subplot(3,2,2); plot(rms);
xlabel('frames'); ylabel('rss');
subplot(3,2,1); imagesc(fc,[-1,1]); axis square;
title('fc all time points');
subplot(3,2,3); imagesc(fctop,[-1,1]); axis square;
title('fc high-amplitude time points');
subplot(3,2,4); scatter(fctop(idx),fc(idx),'k.'); xlim([-1,1]); ylim([-1,1]);
text(-1,1,sprintf('r = %.2f',corr(fctop(idx),fc(idx))));
subplot(3,2,5); imagesc(fcbot,[-1,1]); axis square;
title('fc low-amplitude time points');
subplot(3,2,6); scatter(fcbot(idx),fc(idx),'k.'); xlim([-1,1]); ylim([-1,1]);
text(-1,1,sprintf('r = %.2f',corr(fcbot(idx),fc(idx))));
%% calculate similarity of time-averaged fc with high-/low-amplitude frames
rho(1) = corr(fctop(idx),fc(idx));
rho(2) = corr(fcbot(idx),fc(idx));
%% calculate modularity of high-/low-amplitude fc
numiter = 100;
qtop = zeros(numiter,1); qbot = qtop;
for iter = 1:numiter
[~,qtop(iter)] = community_louvain(fctop,[],[],'negative_asym');
[~,qbot(iter)] = community_louvain(fcbot,[],[],'negative_asym');
end
figure;
f = fcn_boxpts([qtop,qbot],[],jet(2));
set(gca,'xtick',1:2,'xticklabel',{'high-amp','low-amp'});
ylabel('modularity, q');