-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExtraGroupANOVAs.m
248 lines (224 loc) · 11.8 KB
/
ExtraGroupANOVAs.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
%% ANALYSIS #1 (3 GROUP ANOVA FOR POST COLLAPSED ACROSS CONDITIONS)
% COMPUTING 3-GROUP ANOVA FOR THE PRE-MANIPULATION RESTING STATE SCANS
% STEP 1 = CREATE VARIABLES OF THE MEAN CORRELATION OF ALL PAIN REGIONS
% FOR EACH GROUP OF THE PRE SCANS ACROSS BOTH VISITS
postPainHC = mean(painnet(i1,2,:),3); % MEAN OF HC
postPainCLBP = mean(painnet(i2,2,:),3); % MEAN OF CLBP
postPainFM = mean(painnet(i3,2,:),3); % MEAN OF FM
gpNames = {'HC post','CLBP post','FM post'}; % VARIABLE OF GROUP NAMES
% STEP 2 = CREATE AN ARRAY OF THE COMBINED VARIABLES FROM ABOVE
% THE ARRAY NEEDS TO BE PADDED BECAUSE OF UNEVEN GROUP SIZES
% IDENTIFY THE LARGEST GROUP
A = max([length(i1),length(i2),length(i3)]);
A = zeros(A,3); % INITIALIZE ARRAY OF ALL ZEROS FOR LARGEST GROUP
A(A == 0) = NaN; % CONVERT ALL '0' TO 'NaN' (MISSING VALUES)
A(1:length(postPainHC),1) = postPainHC; % HC TO COLUMN 1
A(1:length(postPainCLBP),2) = postPainCLBP; % CLBP TO COLUMN 2
A(1:length(postPainFM),3) = postPainFM; % FM TO COLUMN 3
% STEP 3 = RUNNING THE ANOVA AND MULTIPLE COMPARISONS
% CREATE A TABLE OF OVERALL F-TEST
[p,tbl,stats] = anova1(A,gpNames,'off'); % TABLE OF OVERALL RESULTS
ftestNames = tbl(1,:); % VARIABLE NAMES FOR THE TABLE
ftestNames{1,6} = 'Prob_F'; % FIX THE SYMBOL ISSUE
tableFtest = array2table(tbl(2:4,:),'VariableNames',ftestNames);
figure;
%[~,~,stats] = anova1(A,gpNames); % I AM NOT SURE WHAT THIS DOES ...
[c,~,~,gnames] = multcompare(stats); % EVALUATE MULTIPLE COMPARISONS
% STEP 4 = PREPARING STATS OUTPUT
% CREATE AN ARRAY OF ANOVA OUTPUT
anovaPostOutput = [gnames(c(:,1)), gnames(c(:,2)), num2cell(c(:,3:6))];
% INITIAL ORDER OF OUTPUT FROM THE MULTICOMPARISON STEP
% COLUMNS 1-6 = {'gp1','gp2','lCI','gpDiff','uCI','pval'}
% CHANGING THE VARIABLE ORDER IN THE OUTPUT ARRAY TO
% COLUMNS 1-6 = {'gp1','gp2', 'pval','gpDiff','lCI','uCI'}) AND THEN
% CREATE A TABLE OF THE MULTICOMPARISON OUTPUT
anovaPostOutput = anovaPostOutput(:,[1 2 6 4 3 5]);
tableAnovaPost = array2table(anovaPostOutput, 'VariableNames',{'gp1','gp2', 'pval','gpDiff','lCI','uCI'});
%% ANALYSIS #2 (3 GROUP ANOVA FOR POST NEGAVIVE MANIPULATION)
% COMPUTING 3-GROUP ANOVA FOR THE PRE-MANIPULATION RESTING STATE SCANS
% STEP 1 = CREATE VARIABLES OF THE MEAN CORRELATION OF ALL PAIN REGIONS
% FOR EACH GROUP OF THE PRE SCANS ACROSS BOTH VISITS
postNegPainHC = mean(painnet(i1,2,1),3); % MEAN OF HC
postNegPainCLBP = mean(painnet(i2,2,1),3); % MEAN OF CLBP
postNegPainFM = mean(painnet(i3,2,1),3); % MEAN OF FM
gpNames = {'HC neg','CLBP neg','FM neg'}; % VARIABLE OF GROUP NAMES
% STEP 2 = CREATE AN ARRAY OF THE COMBINED VARIABLES FROM ABOVE
% THE ARRAY NEEDS TO BE PADDED BECAUSE OF UNEVEN GROUP SIZES
% IDENTIFY THE LARGEST GROUP
A = max([length(i1),length(i2),length(i3)]);
A = zeros(A,3); % INITIALIZE ARRAY OF ALL ZEROS FOR LARGEST GROUP
A(A == 0) = NaN; % CONVERT ALL '0' TO 'NaN' (MISSING VALUES)
A(1:length(postNegPainHC),1) = postNegPainHC; % HC TO COLUMN 1
A(1:length(postNegPainCLBP),2) = postNegPainCLBP; % CLBP TO COLUMN 2
A(1:length(postNegPainFM),3) = postNegPainFM; % FM TO COLUMN 3
% STEP 3 = RUNNING THE ANOVA AND MULTIPLE COMPARISONS
% CREATE A TABLE OF OVERALL F-TEST
[p,tbl,stats] = anova1(A,gpNames,'off'); % TABLE OF OVERALL RESULTS
ftestNames = tbl(1,:); % VARIABLE NAMES FOR THE TABLE
ftestNames{1,6} = 'Prob_F'; % FIX THE SYMBOL ISSUE
tableFtest = array2table(tbl(2:4,:),'VariableNames',ftestNames);
figure;
%[~,~,stats] = anova1(A,gpNames); % I AM NOT SURE WHAT THIS DOES ...
[c,~,~,gnames] = multcompare(stats); % EVALUATE MULTIPLE COMPARISONS
% STEP 4 = PREPARING STATS OUTPUT
% CREATE AN ARRAY OF ANOVA OUTPUT
anovaPostNegOutput = [gnames(c(:,1)), gnames(c(:,2)), num2cell(c(:,3:6))];
% INITIAL ORDER OF OUTPUT FROM THE MULTICOMPARISON STEP
% COLUMNS 1-6 = {'gp1','gp2','lCI','gpDiff','uCI','pval'}
% CHANGING THE VARIABLE ORDER IN THE OUTPUT ARRAY TO
% COLUMNS 1-6 = {'gp1','gp2', 'pval','gpDiff','lCI','uCI'}) AND THEN
% CREATE A TABLE OF THE MULTICOMPARISON OUTPUT
anovaPostNegOutput = anovaPostNegOutput(:,[1 2 6 4 3 5]);
tableAnovaNegPost = array2table(anovaPostNegOutput, 'VariableNames',{'gp1','gp2', 'pval','gpDiff','lCI','uCI'});
%% ANALYSIS #3 (3 GROUP ANOVA FOR POST POSITIVE MANIPULATION)
% COMPUTING 3-GROUP ANOVA FOR THE PRE-MANIPULATION RESTING STATE SCANS
% STEP 1 = CREATE VARIABLES OF THE MEAN CORRELATION OF ALL PAIN REGIONS
% FOR EACH GROUP OF THE PRE SCANS ACROSS BOTH VISITS
postPosPainHC = mean(painnet(i1,2,2),3); % MEAN OF HC
postPosPainCLBP = mean(painnet(i2,2,2),3); % MEAN OF CLBP
postPosPainFM = mean(painnet(i3,2,2),3); % MEAN OF FM
gpNames = {'HC pos','CLBP pos','FM pos'}; % VARIABLE OF GROUP NAMES
% STEP 2 = CREATE AN ARRAY OF THE COMBINED VARIABLES FROM ABOVE
% THE ARRAY NEEDS TO BE PADDED BECAUSE OF UNEVEN GROUP SIZES
% IDENTIFY THE LARGEST GROUP
A = max([length(i1),length(i2),length(i3)]);
A = zeros(A,3); % INITIALIZE ARRAY OF ALL ZEROS FOR LARGEST GROUP
A(A == 0) = NaN; % CONVERT ALL '0' TO 'NaN' (MISSING VALUES)
A(1:length(postPosPainHC),1) = postPosPainHC; % HC TO COLUMN 1
A(1:length(postPosPainCLBP),2) = postPosPainCLBP; % CLBP TO COLUMN 2
A(1:length(postPosPainFM),3) = postPosPainFM; % FM TO COLUMN 3
% STEP 3 = RUNNING THE ANOVA AND MULTIPLE COMPARISONS
% CREATE A TABLE OF OVERALL F-TEST
[p,tbl,stats] = anova1(A,gpNames,'off'); % TABLE OF OVERALL RESULTS
ftestNames = tbl(1,:); % VARIABLE NAMES FOR THE TABLE
ftestNames{1,6} = 'Prob_F'; % FIX THE SYMBOL ISSUE
tableFtest = array2table(tbl(2:4,:),'VariableNames',ftestNames);
figure;
%[~,~,stats] = anova1(A,gpNames); % I AM NOT SURE WHAT THIS DOES ...
[c,~,~,gnames] = multcompare(stats); % EVALUATE MULTIPLE COMPARISONS
% STEP 4 = PREPARING STATS OUTPUT
% CREATE AN ARRAY OF ANOVA OUTPUT
anovaPostPosOutput = [gnames(c(:,1)), gnames(c(:,2)), num2cell(c(:,3:6))];
% INITIAL ORDER OF OUTPUT FROM THE MULTICOMPARISON STEP
% COLUMNS 1-6 = {'gp1','gp2','lCI','gpDiff','uCI','pval'}
% CHANGING THE VARIABLE ORDER IN THE OUTPUT ARRAY TO
% COLUMNS 1-6 = {'gp1','gp2', 'pval','gpDiff','lCI','uCI'}) AND THEN
% CREATE A TABLE OF THE MULTICOMPARISON OUTPUT
anovaPostPosOutput = anovaPostPosOutput(:,[1 2 6 4 3 5]);
tableAnovaPosPost = array2table(anovaPostPosOutput, 'VariableNames',{'gp1','gp2', 'pval','gpDiff','lCI','uCI'});
%% ANALYSIS #4 (T-TEST, HC vs. CLBP [pre, both visits])
% to compute a compound "pre" score
% ttest2(group-1, pre/post, neg/post, group-2, pre/post, neg/post)
% Below = (HC, pre, both visits vs. CLBP, pre, both visits)
[h, p, ci, stats] = ttest2(mean(painnet(i1, 1, :), 3), mean(painnet(i2, 1, :), 3), ...
'tail', 'both', 'vartype', 'unequal');
% p
% stats
Gps = (['HC v CLBP']);
pval = ([p]);
tVal = ([stats.tstat]);
scanSet = (['combined pre']);
cond = (['both']);
Hy = ([h]);
%% ANALYSIS #5 (T-TEST [HC v CLBP], COMPARING PRE FROM THE NEG VISITS, NOT OVERLY USEFUL)
% to then run differences in group tests HC vs. CLBP
% ttest2(group-1, pre/post, neg/post, group-2, pre/post, neg/post)
% Below = (HC, pre, neg vs. CLBP, pre, neg)
[h, p, ci, stats] = ttest2(painnet(i1, 1, 1), painnet(i2, 1, 1), ...
'tail', 'both', 'vartype', 'unequal');
% p
% stats
Gps = ([Gps;{'HC v CLBP'}]);
pval = ([pval;p]);
tVal = ([tVal;stats.tstat]);
scanSet = ([scanSet;{'pre'}]);
cond = ([cond;{'neg'}]);
Hy = ([Hy;h]);
%% ANALYSIS #6 (T-TEST [HC v CLBP], COMPARING PRE FROM THE POS VISITS, NOT OVERLY USEFUL)
% ttest2(group-1, pre/post, neg/post, group-2, pre/post, neg/post)
% Below = (HC, pre, pos vs. CLBP, pre, pos)
[h, p, ci, stats] = ttest2(painnet(i1, 1, 2), painnet(i2, 1, 2), ...
'tail', 'both', 'vartype', 'unequal');
Gps = ([Gps;{'HC v CLBP'}]);
pval = ([pval;p]);
tVal = ([tVal;stats.tstat]);
scanSet = ([scanSet;{'pre'}]);
cond = ([cond;{'pos'}]);
Hy = ([Hy;h]);
%% ANALYSIS #7 (T-TEST [HC v CLBP], POST > PRE (NEG), WHAT DID THE NEG MANIPULATION INCREASE)
% TO TEST GROUP DIFFERENCES IN POST-PRE IN THE NEGATIVE CONDITION
% THAT IS, GROUP DIFFERENCES IN HOW MUCH THE NEGATIVE MOOD MANIPULATION
% INCREASED ACTIVITY IN THE ROIs
[h, p, ci, stats] = ttest2(painnet(i1, 2, 1) - painnet(i1, 1, 1), painnet(i2, 2, 1) - painnet(i2, 1, 1), ...
'tail', 'both', 'vartype', 'unequal');
Gps = ([Gps;{'HC v CLBP'}]);
pval = ([pval;p]);
tVal = ([tVal;stats.tstat]);
scanSet = ([scanSet;{'post > pre'}]);
cond = ([cond;{'neg'}]);
Hy = ([Hy;h]);
%% ANALYSIS #8 (T-TEST [HC v CLBP], POST > PRE (POS), WHAT DID THE POS MANIPULATION INCREASE)
% TO TEST GROUP DIFFERENCES IN POST-PRE IN THE POSITIVE CONDITION
% THAT IS, GROUP DIFFERENCES IN HOW MUCH THE POSITIVE MOOD MANIPULATION
% INCREASED ACTIVITY IN THE ROIs
[h, p, ci, stats] = ttest2(painnet(i1, 2, 2) - painnet(i1, 1, 2), painnet(i2, 2, 2) - painnet(i2, 1, 2), ...
'tail', 'both', 'vartype', 'unequal');
Gps = ([Gps;{'HC v CLBP'}]);
pval = ([pval;p]);
tVal = ([tVal;stats.tstat]);
scanSet = ([scanSet;{'post > pre'}]);
cond = ([cond;{'pos'}]);
Hy = ([Hy;h]);
%% ANALYSIS #9 (T-TEST [HC v FM], POST > PRE (NEG), WHAT DID THE NEG MANIPULATION INCREASE)
% TO TEST GROUP DIFFERENCES IN POST-PRE IN THE NEGATIVE CONDITION
% THAT IS, GROUP DIFFERENCES IN HOW MUCH THE NEGATIVE MOOD MANIPULATION
% INCREASED ACTIVITY IN THE ROIs
[h, p, ci, stats] = ttest2(painnet(i1, 2, 1) - painnet(i1, 1, 1), painnet(i3, 2, 1) - painnet(i3, 1, 1), ...
'tail', 'both', 'vartype', 'unequal');
Gps = ([Gps;{'HC v FM'}]);
pval = ([pval;p]);
tVal = ([tVal;stats.tstat]);
scanSet = ([scanSet;{'post > pre'}]);
cond = ([cond;{'neg'}]);
Hy = ([Hy;h]);
%% ANALYSIS #10 (T-TEST [HC v FM], POST > PRE (POS), WHAT DID THE POS MANIPULATION INCREASE)
% TO TEST GROUP DIFFERENCES IN POST-PRE IN THE POSITIVE CONDITION
% THAT IS, GROUP DIFFERENCES IN HOW MUCH THE POSITIVE MOOD MANIPULATION
% INCREASED ACTIVITY IN THE ROIs
[h, p, ci, stats] = ttest2(painnet(i1, 2, 2) - painnet(i1, 1, 2), painnet(i3, 2, 2) - painnet(i3, 1, 2), ...
'tail', 'both', 'vartype', 'unequal');
Gps = ([Gps;{'HC v FM'}]);
pval = ([pval;p]);
tVal = ([tVal;stats.tstat]);
scanSet = ([scanSet;{'post > pre'}]);
cond = ([cond;{'pos'}]);
Hy = ([Hy;h]);
%% CREATING A TABLE OF OUTPUT VARIABLES
tableTtest = table(Gps,scanSet,cond,Hy,pval,tVal,'VariableNames',{'group','scanSet','Condition','Sig','pvalue','tvalue'});
writetable(tableTtest,'t-tests.txt','Delimiter',' ');
%% SAVE WORKSPACE
ROIFCstatsOutput = ['ROIFCstats_',datestr(now, 'yyyy-mm-dd'),'.mat']
save(ROIFCstatsOutput);
% % Below = (HC, pre, neg vs. CLBP, pre, pos)
% [h, p, ci, stats] = ttest2(painnet(i1, 1, 1), painnet(i2, 1, 1), ...
% 'tail', 'both', 'vartype', 'unequal');
%
%% EXTRA STUFF
% pval2 = p;
%Qs = ([Qs;Q2]);
%Qs = ([Qs;{'HC ver CLBP'}]);
% % to compute a "difference" for pre-post neg treatment (between groups)
% %[h, p, ci, stats] = ttest2(painnet(i1, 2, 1) - painnet(i1, 1, 1), painnet(i2, 1, 2) - painnet(i2, 1, 1), ...
% [h, p, ci, stats] = ttest2(painnet(i1, 2, 1) - painnet(i1, 1, 1), painnet(i2, 2, 1) - painnet(i2, 1, 1), ...
% 'tail', 'both', 'vartype', 'unequal');
% p
% stats
%pval = {pval;p};
% as a paired t-test (across all participants)
% [h, p, ci, stats] = ttest(painnet(:, 1, 1), painnet(:, 1, 2), ...
% 'tail', 'both');
% p
% stats
% pval = ([pval;p]);
% tVal = ([tVal;stats.tstat]);
% pval3 = p;