-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotSlopesOfChangesInDistinctiveness.m
More file actions
128 lines (101 loc) · 4.34 KB
/
plotSlopesOfChangesInDistinctiveness.m
File metadata and controls
128 lines (101 loc) · 4.34 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
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
% This script plots the slopes of linear mixed models indicating the change in
% distinctiveness per year
close all
clear all
%% Set up paths, files and variables
dataDir = './data/';
figuresDir = './figures/';
fileName = 'RSM_zscore_allChildrenNew_vtc_noSubID';
% indicate if you want to plot data for medial or lateral VTC:
% partition = 'lateral' or partition = 'medial'
partition = 'lateral';
%%
% Load RSM data. Struct is organized by ROI & partition (left and right lateral & medial VTC),
% subject and session
load([dataDir fileName])
% Order of categories in RSM. this order is important
categories= {'Numbers', 'Words', 'Limbs', 'Bodies', 'AdultFaces', 'ChildFaces',...
'Cars', 'StringInstruments', 'Houses', 'Corridors'};
%% Gather data and compute distinctiveness for each session and ROI, Run linear mixed models
rois = {['lh_vtc_' partition], ['rh_vtc_' partition]};
slopeData = [];
lowerCI = [];
upperCI = [];
for c= 1:length(categories)
category = categories{c};
for r=1:length(rois)
roi = rois{r};
% reorganize Data: matrix of the format categories x categories x sessions
[RSMdata3D, age, allSessions, subj, tSNR] = prepareRSMData(RSMnoIDs, roi);
% Compute distinctiveness for this category
distinctiveness = computeCategoryDistinctiveness(RSMdata3D, categories, category);
% Run a linear mixed model with predictors age and tSNR and
% distinctiveness as dependent variable, subject is random effect
% create table first
tbl = table(distinctiveness, age, allSessions, subj, tSNR);
lme = fitlme(tbl, 'distinctiveness ~ age + tSNR + (1| subj)');
allCoefficients.(category).(roi).coeffs = lme.Coefficients;
% extract slope and CI of age predictor frmo LMM
if strcmp(allCoefficients.(category).(roi).coeffs{2,1}, 'age')
slopeData(c,r) = allCoefficients.(category).(roi).coeffs{2,2};
lowerCI(c,r) = allCoefficients.(category).(roi).coeffs{2,7};
upperCI(c,r) = allCoefficients.(category).(roi).coeffs{2,8};
else
fprintf('Check order of predictors in LMM')
end
clearvars RSMdata3D age allSessions subj tSNR distinctiveness lme
end
end
%% Create barplot showing slopes for age of LMM
figure(1)
set(gcf, 'Position', [0 0 1200 500]);
bp=bar(slopeData, 'FaceColor','flat', 'EdgeColor', 'none');
% color bars for each category and hemisphere
bp(1).CData(1,:) = [121/255 134/255 203/255]; % num
bp(1).CData(2,:) = [133/255 193/255 233/255 ]; % word
bp(1).CData(3,:) = [255/255 235/255 59/255]; % limb
bp(1).CData(4,:) = [ 240/255 178/255 122/255 ]; % [255/255 102/255 0/255]; %bodies
bp(1).CData(5,:) = [236/255 112/255 99/255]; % adult faces
bp(1).CData(6,:) = [146/255 43/255 33/255]; % kid faces
bp(1).CData(7,:) = [153/255 0/255 255/255];
bp(1).CData(8,:) = [255/255 152/255 255/255];
bp(1).CData(9,:) = [156/255 204/255 101/255];
bp(1).CData(10,:) = [0/255 105/255 92/255];
bp(2).CData(1,:) = [121/255 134/255 203/255]; % num
bp(2).CData(2,:) = [133/255 193/255 233/255 ]; % word
bp(2).CData(3,:) = [255/255 235/255 59/255]; % limb
bp(2).CData(4,:) = [ 240/255 178/255 122/255 ]; % [255/255 102/255 0/255]; %bodies
bp(2).CData(5,:) = [236/255 112/255 99/255]; % adult faces
bp(2).CData(6,:) = [146/255 43/255 33/255]; % kid faces
bp(2).CData(7,:) = [153/255 0/255 255/255];
bp(2).CData(8,:) = [255/255 152/255 255/255];
bp(2).CData(9,:) = [156/255 204/255 101/255];
bp(2).CData(10,:) = [0/255 105/255 92/255];
hold on
%% add errorbars for grouped bar ploot
ngroups = length(categories);
nbars = length(rois);
% Calculating the width for each bar group
groupwidth = min(0.8, nbars/(nbars + 1.5));
r = refline([0 0]);
r.Color = [0.2 0.2 0.2];
for i = 1:nbars
x = (1:ngroups) - groupwidth/2 + (2*i-1) * groupwidth / (2*nbars);
for pos = 1:length(x)
pl1 = plot([x(pos) x(pos)], [lowerCI(pos,i) upperCI(pos,i)], '-' );
% color errorbars
pl1.Color = [0.5 0.5 0.5];
pl1.LineWidth = 3;
end
end
%% format plot
box off
set(gcf, 'Color', 'w')
ylabel('Change in distinctiveness (per year)', 'FontSize', 12)
xticklabels(categories)
xtickangle(45)
titlestr = [partition ' VTC'];
title(titlestr)
%% save figure
figureName = ['BarPlot_ChangeInDistinctivenessPerYear_' partition];
print(fullfile(figuresDir, figureName), '-dpng', '-r200')