-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmetaAnalysis_GUI_160917.m
1543 lines (1318 loc) · 67.3 KB
/
metaAnalysis_GUI_160917.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
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
%17.09.17 trouble shoot exclusion analysis
function metaAnalysis_GUI_160917(input)
clearvars('-except', 'input');
% METAANALYSIS conduct general meta-analysis
%
% conducts meta-analysis on DATACOLLECTION datasets and
% saves results in FILE. Summary effect size is calculated as EFFECTSIZE
% and transformed as DATATRANSFORMATION. Any necessary
% backtransformations are computed using LOG2RAW method. Random effect
% model is computed using interstudy variance estimated by TAU2ESTIMATOR
% and confidence intervals are constructed using CIESTIMATOR. Studies
% excluded from analysis are specified by EXCLUDESTUDIES and single study
% subgroups are handled according to SINGLESTUDYSUBGORUSP. Study-level
% forestplot uses weighting scheme specified by FORESTPLOTWEIGHTS, and
% plotted data tranformation is specified by FORESTPLOTTRANSFORMATION.
% Forestplot marker sizes are specified by MARKERSIZERANGE and optionally
% effect sizes can be ordered if specified by SORTFOREST.
%
% Input Arguments
%-----------------------
%
% DATACOLLECTION
% String specifying name of input data colection (see PREPDATA). (ex. 'myDataCollection')
% FILE String that specifies the name of the file to write results. (ex. 'myResults.xlsx')
% EXPORT
% logical (TRUE/FALSE). Specifies whether results are saved to FILE.
% EFFECTSIZE
% String specifying effect measure of interest.
% EFFECTSIZE can be:
% 'absolute' - evaluates absolute effect. If difference computed
% if negative control is reported (Default)
% 'standardized' - evaluates standardized effect (Hedge's g).
% 'normalized' - evaluates normalized effect.
% 'ratio' - evaluated response ratio
% DATATRANSFORMATION
% String that specifies data transformation
% DATATRANSFORMATION can be:
% 'raw' - no transformation (Default)
% 'log' - log10 transformation
% LOG2RAW
% String that specifies back-transformation method.
% Available back-transformation methods:
% 'geometric' - geometric mean
% result on raw scale will be approximation of
% data median
% 'naive' - naive transformation (Default)
% Arithmetic mean on raw scale.
% Adhoc approximation of variance
% 'tailor' - tailor series variance approximation
% same estimate as naive transformation. Variance
% approximation is handled differently.
% 'bias' - bias correction method
% empirically derived correction factor for
% back-transformed estimate.
% TAU2ESTIMATOR
% String that specifies which tau2 estimator is used in
% random effect model
% TAU2ESTIMATOR can be:
% 'FE' - Assume fixed effects model. Tau2 = 0.
% 'DL' - DerSimonian-Laird estimator (Default)
% 'HS' - Hunter-Schmidt estimator
% 'H' - Hedges estimator
% 'HM' - Hatung-Makambi estimator
% 'SJ' - Sidik-Jonkman estimator
% CIESTIMATOR
% String that specifies which confidence interval estimator is
% used to construct 95% confidence band. Options specify how
% critical value is estimated
% 'z' - z-distribution (Default)
% 't' - t-distribution
% 'QA' - quantile approximation
% EXCLUDESTUDIES
% Numeric array specifying which studies to exclude from overall analysis.
% If no studies are excluded, EXCLUDESTUDIES = [].
% SINGLESTUDYSUBGROUPS
% logical (TRUE/FALSE). specifies whether single study subgroups are allowed (not recommended)
% FORESTPLOTWEIGHTS
% String specifying forest plot weighting scheme.
% Weighting options are:
% 'FE' - fixed effects weighting scheme
% 'RE' - random effects weighting scheme
% FORESTPLOTTRANSFORMATION
% String that specifies data transformation
% FORESTPLOTTRANSFORMATION can be:
% 'raw' - no transformation (Default)
% 'log' - log10 transformation
% MARKERSIZERANGE
% 'numerical array. size(1,2). specifies min and max marker size.
% *Adjust if forest plot markers are disproportional (Default [3,20]);
% SORTFOREST
% Logical (TRUE/FALSE) specifying whether forst plot effect sizes
% are sorted in order.
% CORRECTION
% Logical (TRUE/FALSE) specifying whether Bonferroni correction is applied to
% obtain adjusted confidence intervals during subgroup analysis
% WEIGHTS
% String specifying the precision measure used for effect size
% weighting. options:
% 'IV' - inverse variance (default)
% 'IVS' - inverse standardized variance
% 'MC' - monte carlo resampling, pseudo raw data is
% randomly drawn from distribution defined by
% aggregate data statistics. Fixed effects not
% available for this option.
%
% Updated 01.11.17
try;
input % summary of user inputs
% analysis properties
try; properties.effectSize = input.effectSize; catch; properties.effectSize = 'absolute'; end
try; properties.dataTransformation = input.dataTransformation; catch; properties.dataTransformation = 'raw'; end
try; properties.log2raw_method =input.log2raw_method; catch; properties.log2raw_method = 'naive'; end
try; properties.tau2estimator =input.tau2estimator; catch; properties.tau2estimator = 'DL';end
try; properties.CIestimator = input.CIestimator; catch; properties.CIestimator = 'z';end
try; properties.export = input.export; catch;properties.export = false; end
try; properties.excludeStudies = input.excludeStudies; catch; properties.excludeStudies = [];end
try; properties.forestPlotWeights = input.forestPlotWeights; catch; properties.forestPlotWeights = 'FE'; end
try; properties.forestPlotTransformation = input.forestPlotTransformation; catch; properties.forestPlotTransformation = 'raw'; end
try; properties.markerSizeRange = input.markerSizeRange; catch; properties.markerSizeRange = [2, 5]; end
try; properties.dataCollection = input.dataCollection; catch; error('input data not specified'); end % specify dataset for meta analysis
try; properties.file = [input.file{1} '.xlsx']; catch; if properties.export; error('export file not specified'); end; end % specify filename where results will be written
try; properties.sortForest = input.sortForest; catch; properties.sortForest = 0; end
try; properties.singleStudySub = input.singleStudySub; catch; properties.singleStudySub = false; end
try; properties.correction = input.correction; catch; properties.correction = false; end;
try; properties.weights = input.weights; catch; properties.weights = 'IV'; end
properties % summary of final analysis properties
load(properties.dataCollection); % load data (generated by PREPDATA module)
for k = 1:length(D) % iterate through all available data sets
%% part 1: data extraction
SheetName = D(k).description; % dataset name
data = dataExtraction(D(k).data, [properties.excludeStudies]); % extact dataset
assignin('base',... % assign dataset to workspace
'extractedData',...
dataExtraction(D(k).data,...
[properties.excludeStudies]));
display('part1: data extraction complete');
%% part 2: compute effect size with appropriate transformations
switch properties.effectSize
case 'absolute'
data = AbsoluteDifference(data); % absolute difference/effect
case 'normalized'
data = NormalizedDifference(data); % normalized difference
case 'standardized'
data = hedgesG(data); % standardized difference
case 'ratio'
data = respRatio(data); % response ratio
end
data = raw2log (data, properties, SheetName); % make logarithmic transformation if necessary
display('part2: study-level effect size computation complete');
assignin('base', 'data', data);
%% part 3: partition data into defined subgroups
subgroup = subGroupPartition(data, D(k).covariates, properties); % partition data into subgroups (if covariates present)
display('part3: subgroup partitioning complete');
%% part 4: conduct meta-analysis
if properties.singleStudySub; minSize = 1; else; minSize = 2; end % assign minimum subgroup size
for i = 1:length(subgroup) % iterate through each subgroup
if length([subgroup(i).y]) >= (minSize) % analyse only if size of subgroup is sufficient
S.subgroup = subgroup(i).subgroup; % specify subgroup name
S = dataSummary(subgroup(i), S, properties);
S = EffectSizeEstimator(S, properties); % summary effect size and related statistics
try; FINAL = [FINAL S]; catch; FINAL = S; end % store results in final structure
end;
end
% perform backtransformation if analyzed on log scale
switch properties.dataTransformation
case 'log'; FINAL = log2raw(FINAL, properties); end
display('part4: meta analysis complete');
% generate study-level forest plot
[singS] = studyLevelForestPlot (data, FINAL, properties, SheetName);
%save results to spreadsheet
FINAL = saveResults(properties, FINAL, SheetName, data);
display(['Progress: ' num2str(100*k/(length(D))) '%']) % print progress (% of datasets analysed)
try; results{k} = FINAL; catch; results{1} = FINAL; end; clear('FINAL');
end
clear D i k r singleStudies subgroup S minLen Sheet data singS; % clear unnecessary variables
assignin('base','results', results); % assign final results to workspace
catch e;
disp(e)
assignin('base','e',e);
msgbox({'Error while running meta-analysis module',...
' ',...
'Ensure inputs are complete and correct'},'Error', 'Error');
end
end
%% FUNCTIONS
% generates study-level forest plot
function [singS] = studyLevelForestPlot(data, FINAL, properties, Sheet);
switch properties.weights
case 'MC'
offset = 2;
case 'N'
offset = 2;
otherwise
offset = 4;
end
switch properties.dataTransformation % prep data according to desired transformation
case 'raw'
singS(1).study = {'Random Effects'}; singS(2).study = ' ';
singS(1).ES = [FINAL(1).ESre ]; singS(2).ES = nan;
singS(1).SE = [FINAL(1).SEre ]; singS(2).SE = nan;
singS(1).xlo = singS(1).ES - (1.96*FINAL(1).SEre); singS(2).xlo = nan;
singS(1).xhi = singS(1).ES + (1.96*FINAL(1).SEre); singS(2).xhi = nan;
singS(1).Ni = [(FINAL(1).df+1)]; singS(2).Ni =nan;
switch properties.weights
case 'MC'
case 'N'
otherwise
singS(3).study = {'Fixed Effects'}; singS(4).study = ' ';
singS(3).ES = [FINAL(1).ESfe ]; singS(4).ES = nan;
singS(3).SE = [FINAL(1).SEfe ]; singS(4).SE = nan;
singS(3).xlo = singS(3).ES - (1.96*FINAL(1).SEfe); singS(4).xlo = nan;
singS(3).xhi = singS(3).ES + (1.96*FINAL(1).SEfe); singS(4).xhi = nan;
singS(3).Ni = [(FINAL(1).df+1)]; singS(4).Ni = nan;
end
for i = 1:length(data);
singS(i+offset).study = num2str(data(i).ID);
singS(i+offset).ES = data(i).fESi;
singS(i+offset).SE = data(i).fSEi;
singS(i+offset).xlo = singS(i+offset).ES - (1.96*data(i).fSEi);
singS(i+offset).xhi = singS(i+offset).ES + (1.96*data(i).fSEi);
singS(i+offset).Ni = data(i).Ni;
end
case 'log'
switch properties.forestPlotTransformation
case 'raw'
% not elegant, but it'll get the job done.
%raw-scale random effect estimate
singS(1).study = {'Random Effects'}; singS(2).study = ' ';
singS(1).ES = [FINAL(1).ESre_raw ]; singS(2).ES = nan;
singS(1).SE = nan; singS(2).SE = nan;
singS(1).xlo =[FINAL(1).ciLre_raw]; singS(2).xlo = nan;
singS(1).xhi = [FINAL(1).ciUre_raw]; singS(2).xhi = nan;
singS(1).Ni = [(FINAL(1).df+1)]; singS(2).Ni =nan;
switch properties.weights
case 'MC'
case 'N'
otherwise
% raw-scale fixed effects estimate
singS(3).study = {'Fixed Effects'}; singS(4).study = ' ';
singS(3).ES = [FINAL(1).ESfe_raw ]; singS(4).ES = nan;
singS(3).SE = nan; singS(4).SE = nan;
singS(3).xlo = [FINAL(1).ciLfe_raw]; singS(4).xlo = nan;
singS(3).xhi = [FINAL(1).ciUfe_raw]; singS(4).xhi = nan;
singS(3).Ni = [(FINAL(1).df+1)]; singS(4).Ni = nan;
end
for i = 1:length(data); % iterate through all data, assign to forest plot structure
singS(i+offset).study = data(i).ID; % study ID
singS(i+offset).ES = data(i).ESi; % study-level effect size
singS(i+offset).SE = data(i).SEi; % study-level standard error
singS(i+offset).xlo = singS(i+offset).ES - (1.96*data(i).SEi); % lower bound confidence interval (z-dist)
singS(i+offset).xhi = singS(i+offset).ES + (1.96*data(i).SEi); % upper bound confidence interval (z-dist)
singS(i+offset).Ni = data(i).Ni; % study-level sample size
end
case 'log'
% log-transformed Random effects estimate
singS(1).study = {'Random Effects'}; singS(2).study = ' ';
singS(1).ES = [FINAL(1).ESre ]; singS(2).ES = nan;
singS(1).SE = [FINAL(1).SEre ]; singS(2).SE = nan;
singS(1).xlo = singS(1).ES - (1.96*FINAL(1).SEre); singS(2).xlo = nan;
singS(1).xhi = singS(1).ES + (1.96*FINAL(1).SEre); singS(2).xhi = nan;
singS(1).Ni = [(FINAL(1).df+1)]; singS(2).Ni =nan;
% log-transformed fixed effects estimate
switch properties.weights
case 'MC'
case 'N'
otherwise
singS(3).study = {'Fixed Effects'}; singS(4).study = ' ';
singS(3).ES = [FINAL(1).ESfe ]; singS(4).ES = nan;
singS(3).SE = [FINAL(1).SEfe ]; singS(4).SE = nan;
singS(3).xlo = singS(3).ES - (1.96*FINAL(1).SEfe); singS(4).xlo = nan;
singS(3).xhi = singS(3).ES + (1.96*FINAL(1).SEfe); singS(4).xhi = nan;
singS(3).Ni = [(FINAL(1).df+1)]; singS(4).Ni = nan;
end
for i = 1:length(data); % iterate through all data, assign to forest plot structure
singS(i+offset).study = data(i).ID; % study ID
singS(i+offset).ES = data(i).fESi; % study-level effect size
singS(i+offset).SE = data(i).fSEi; % study-level standard error
singS(i+offset).xlo = singS(i+offset).ES - (1.96*data(i).fSEi); % lower bound confidence interval (z-dist)
singS(i+offset).xhi = singS(i+offset).ES + (1.96*data(i).fSEi); % upper bound confidence interval (z-dist)
singS(i+offset).Ni = data(i).Ni; % study-level sample size
end
end
end
% sort study-level effect sizes (optional)
SE = [singS((offset+1):end).SE]; % extract only study-level standard errors
ES = [singS((offset+1):end).ES]; % extract only study-level effect sizes
if properties.sortForest % if sort selected
[ES, sorted] = sort(ES, 'descend'); SE = SE(sorted); % sort study-level effect sizes and associated standard errors
holdThis = singS(1:offset);
for i = 1:length(sorted)
holdThis = [holdThis singS(sorted(i)+offset)];
end
clear('singS'); singS = holdThis; clear('holdThis');
end
% % get marker weights according to specified weighting scheme
switch properties.forestPlotWeights % specifies marker weighting scheme
case 'FE'; w = 1 ./ (SE.^2); % fixed effects
case 'RE'; w = 1 ./ ((SE.^2) + FINAL(1).t2); % random effects
end
markerSizeRange = properties.markerSizeRange; % constraints on marker size range
height = [1:(length(w))+offset]; % height of forest plot is length of weights and estimates
%plot forest plot
[minX, maxX, xlo, xhi, ESerrorX, ESerrorY, h] = plotSkeleton([singS.ES], [singS.SE],height, w, FINAL(1).df, 'n', [singS.xlo], [singS.xhi], markerSizeRange, [singS.study], offset, properties);
% ESerrorXr = ESerrorX; ESerrorYr = ESerrorY;
% apply confidence interval coverage for random effects
[cover1, minX1, maxX1] = applyCoverage (ESerrorX, ESerrorY, minX, maxX, 'red');
% apply confidence interval coverage for fixed effects
switch properties.weights
case 'MC'
case 'N'
otherwise
ESerrorX{1}(1) = ESerrorX{3}(1); ESerrorX{1}(end) = ESerrorX{3}(end);
[cover2, minX2, maxX2] = applyCoverage (ESerrorX, ESerrorY, minX, maxX, 'blue');
end
gca(); title([Sheet ' forest plot (study-level)']); % name the plot
xlabel(['Effect Size (' properties.forestPlotTransformation ')']); % label x axis
end
% evaluate coverage of meta-analysis model
function FINAL = rawModelEvaluation(FINAL);
%first check model coverage of raw data (i.e. data from studies)
for i = 1:length(FINAL) % iterate through results
ES = []; ciU =[]; ciL = []; ESi = [];
ciLi = []; ciUi = []; coverage = []; cover = [];
% assign data
ES = FINAL(i).ES_raw;
ciU = FINAL(i).ciU_raw;
ciL = FINAL(i).ciL_raw;
ESi = [FINAL(i).ESi_raw];
ciLi = [FINAL(i).ciLi_raw];
ciUi = [FINAL(i).ciUi_raw];
% compute coverage according to interval overlap
for j = 1:length (ESi)
cover(j) = 1;
if ciL > ciUi(j); cover(j) = 0; end;
if ciLi(j) > ciU; cover(j) = 0; end;
end
% store coverage results
coverage = 100*sum(cover)/length(ESi);
FINAL(i).studyCoverage_raw = coverage;
end
end
% backtransform log-transformed results
function FINAL = log2raw(FINAL, properties)
transformationMethod = properties.log2raw_method; % specify transformation metod
for i = 1:length(FINAL) % iterate through results
zr = []; szr2 = []; n = []; szr = [];
% extract fixed effects estimates
try;
zf = []; szf2 = []; szf = [];
zf = FINAL(i).ESfe;
szf = FINAL(i).SEfe;
szf2 = FINAL(i).SEfe^2;
catch;
end
% extract random effects estimates
zr = FINAL(i).ESre;
szr = FINAL(i).SEre;
szr2 = FINAL(i).SEre^2;
n = FINAL(i).df + 1; % study-level sample size
crit = FINAL(i).critValue; % CI critical value
if properties.correction
adjCrit = FINAL(i).adjCritValue; % bonferroni-correctedCI critical value
end
% conduct back-transformation according to specified method
switch transformationMethod
case 'tailor' % Higgins (2008) % tailor series approximation method
xr = 10^(zr+(szr2/2)); % z to x
% standard error & confidence backtransform (random effects)
varXr = (1/n)* ((10.^((2*zr)+(szr2))) * (szr2) * (1+((szr2)/2)));
sxr = sqrt(varXr);
xlor = xr - (crit * sxr); xhir = xr + (crit * sxr);
adj_xlor = xr - (adjCrit * sxr); adj_xhir = xr + (adjCrit * sxr);
% standard error & confidence backtransform (fixed effects)
try;
xf = 10^(zf+(szf2/2));
varXf = (1/n)* ((10.^((2*zf)+(szf2))) * (szf2) * (1+((szf2)/2)));
sxf = sqrt(varXf);
xlof = xf - (crit * sxf); xhif = xf + (crit * sxf);
adj_xlof = xf - (adjCrit * sxf); adj_xhif = xf + (adjCrit * sxf);
catch; end
transMeth = 'tailor approximation'; % store back-transformation method
case 'bias' % bias corrected approximation, P.Rothery (1988)
% standard error approximation (random effects)
xr = (10.^zr) + ((1.15 * szr.^2).*(n-1 ./(n))); % z to x
zlor = zr - (crit*szr); zhir = zr + (crit*szr);
xlor = (10.^zlor) + ((1.15 * szr.^2).*(n-1 ./(n)));
xhir = (10.^zhir) + ((1.15 * szr.^2).*(n-1 ./(n)));
sxr = (xhir-xlor)/(2*crit);
adj_zlor = zr - (adjCrit*szr); adj_zhir = zr + (adjCrit*szr);
adj_xlor = (10.^adj_zlor) + ((1.15 * szr.^2).*(n-1 ./(n)));
adj_xhir = (10.^adj_zhir) + ((1.15 * szr.^2).*(n-1 ./(n)));
% standard error approximation (fixed effects)
try;
xf = (10.^zf) + ((1.15 * szf.^2).*(n-1 ./(n)));
zlof = zf - (crit*szf); zhif = zf + (crit*szf);
xlof = (10.^zlof) + ((1.15 * szf.^2).*(n-1 ./(n)));
xhif = (10.^zhif) + ((1.15 * szf.^2).*(n-1 ./(n)));
sxf = (xhif-xlof)/(2*crit);
adj_zlof = zf - (adjCrit*szf); adj_zhif = zf + (adjCrit*szf);
adj_xlof = (10.^adj_zlof) + ((1.15 * szf.^2).*(n-1 ./(n)));
adj_xhif = (10.^adj_zhif) + ((1.15 * szf.^2).*(n-1 ./(n)));
catch; disp('problem with confidence intervals'); end
transMeth = 'bias correction'; % store back-transformation method
case 'naive' % naive back-transformation
% random effect backtransformation
sxr = (10^((2*zr) + szr2))* (10^(szr2) - 1); % standard error (log to raw)
xr = 10^(zr+(szr2/2)); % effect size (log to raw)
zlor = zr - (crit*szr); zhir = zr + (crit*szr); % confidence intervals (log)
xlor = 10^(zlor+(szr2/2)); xhir = 10^(zhir+(szr2/2)); % confidence intervals (raw)
if properties.correction
adj_zlor = zr - (adjCrit*szr); adj_zhir = zr + (adjCrit*szr); % bonferroni correct confidence intervals (log)
adj_xlor = 10^(adj_zlor+(szr2/2)); % bonferroni correct confidence intervals (raw)
adj_xhir = 10^(adj_zhir+(szr2/2));
end
% fixed effect backtransformation
try;
sxf = (10^((2*zf) + szf2))* (10^(szf2) - 1);
xf = 10^(zf+(szf2/2));
zlof = zf - (crit*szf); zhif = zf + (crit*szf);
xlof = 10^(zlof+(szf2/2));xhif = 10^(zhif+(szf2/2));
if properties.correction
adj_zlof = zf - (adjCrit*szf); adj_zhif = zf + (adjCrit*szf);
adj_xlof = 10^(adj_zlof+(szf2/2));adj_xhif = 10^(adj_zhif+(szf2/2));
end
catch; end
transMeth = 'naive transformation'; % store back-transformation method
case 'geometric' % geometric mean method
% random effects back-transformation
xr = 10^(zr); % z to x
zlor = zr - (crit*szr); zhir = zr + (crit*szr);
xlor = 10^(zlor); xhir = 10^(zhir);
sxr = (xhir-xlor)/(2*crit);
if properties.correction
adj_zlor = zr - (adjCrit*szr); adj_zhir = zr + (adjCrit*szr);
adj_xlor = 10^(adj_zlor); adj_xhir = 10^(adj_zhir);
end
% fixed effects back-transformation
try;
xf = 10^(zf);
zlof = zf - (crit*szf); zhif = zf + (crit*szf);
xlof = 10^(zlof); xhif = 10^(zhif);
sxf = (xhif-xlof)/(2*crit);
if properties.correction
adj_zlof = zf - (adjCrit*szf); adj_zhif = zf + (adjCrit*szf);
adj_xlof = 10^(adj_zlof); adj_xhif = 10^(adj_zhif);
end
catch; end
transMeth = 'geometric mean'; % store back-transformation method
end
% store back-transformed results (random effects)
FINAL(i).ESre_raw = xr; % effect size (raw)
FINAL(i).SEre_raw = sxr; % standard error (raw)
FINAL(i).ciLre_raw = xlor; % lower bound confidence interval (raw)
FINAL(i).ciUre_raw = xhir; % upper bound confidence interval (raw)
if properties.correction
FINAL(i).adjCiLre_raw = adj_xlor; % adjusted lower bound confidence interval (raw)
FINAL(i).adjCiUre_raw = adj_xhir; % adjusted upper bound confidence interval (raw)
end
% store back-transformed results (fixed effects)
try;
FINAL(i).ESfe_raw = xf;
FINAL(i).SEfe_raw = sxf;
FINAL(i).ciLfe_raw = xlof;
FINAL(i).ciUfe_raw = xhif;
if properties.correction
FINAL(i).adjCiLfe_raw = adj_xlof;
FINAL(i).adjCiUfe_raw = adj_xhif;
end
catch; end
FINAL(i).log2rawMethod = transMeth; % store transformation method
end
end
% returns heterogeneity statistics
function S = dataSummary(subgroup, S, properties)
% extract data
ES = [subgroup.y]; % study-level effect sizes
SEM = [subgroup.se]; % study-level standard errors
Ni = [subgroup.n]; % study-level sample sizes
indicatorNum = [subgroup.indicatorNumber]; % study IDs
try; nSubgroups = round(mean([subgroup.nSubgroups])); % number of subgroups per given covariate
catch; nSubgroups = 1; end
df = length(ES) - 1; % degree of freedom
if df > 0 % if there is atleast 2 studies
% heterogeneity statistics
switch properties.weights
case 'IV'
W_fix = 1./(SEM.^2);
ES_fix = sum(W_fix.*ES) / sum(W_fix);
case 'IVS'
CVi = abs(SEM./ES); SEM = [];
W_fix = 1./(CVi.^2);
SEM = abs(CVi * (sum((W_fix.*ES))/sum(W_fix)));
W_fix = 1./(SEM.^2);
ES_fix = sum(W_fix.*ES) / sum(W_fix);
case 'N'
W_fix = [Ni];
ES_fix = sum(W_fix.*ES) / sum(W_fix);
case 'MC'
W_fix = 1./(SEM.^2);
ES_fix = sum(W_fix.*ES) / sum(W_fix);
end
Q = sum((W_fix).*((ES - ES_fix).^2)); % Q-statistic
p_Q = 1-(round(1000*chi2cdf(Q,df))/1000); % p-value for Q-test
H2 = Q / df; % higgins & thompson 2002, AKA Birge's ratio (Birge 1932).
if Q > df; I = 100*(H2 - 1)/H2; % I2 statistic
else; I = 0; end
% confidence intrevals for h2 and I2
if Q > df+1; SE_lnH = (0.5)*((log(Q)-log(df))/((sqrt(2*Q))-(sqrt((2*(df+1))-3))));
else; SE_lnH = sqrt((1/(2*(df-1)))*(1-(1/(3*((df-1)^2))))); end
H2_ciU = exp((log(H2) + (1.96 * SE_lnH)));
H2_ciL = exp((log(H2) - (1.96 * SE_lnH)));
I_ciU = real(100*(H2_ciU - 1)/H2_ciU);
I_ciL = real(100*(H2_ciL - 1)/H2_ciL);
if I_ciU < 0; I_ciU = 0; end; if isnan(I_ciU); I_ciU = 0; end
if I_ciL < 0; I_ciL = 0; end; if isnan(I_ciL); I_ciL = 0; end
else; % doesn't compute heterogeneity statistics for 1 study
try; W_fix = 1./(SEM.^2);I = []; I_ciL = []; I_ciU = []; Q = []; H2 = [];p_Q = [];
catch; I = []; I_ciL = []; I_ciU = []; Q = []; W_fix = []; H2 = []; p_Q = []; end
end
% store statistics to structure
S.I2 = I; % I2 heterogeneity statistic
S.I2lo = I_ciL; % lower bound I2 CI
S.I2hi = I_ciU; % upper bound I2 CI
S.H2 = H2; % H2 heterogeneity statistic
S.df = df; % degrees of freedom
S.Q = Q; % Q heterogeneity statistic
S.Qp = p_Q; % p-value for Q-test
S.xi = ES; % study-level effect sizes for given subgroup
S.wi_fe = W_fix; % study-level weights for given subgroup
S.sei_fe = SEM; % study-level standard errors for given subgroup
S.ni = Ni; % study-level sample sizes for given subgroup
S.id = indicatorNum; % study IDs for given subgroup
S.nSubgroups = nSubgroups; % total number of subgroups for given covariate
end
% partition data into subgroups, according to covariates
function subgroup = subGroupPartition(dataConstruct, covariates, properties);
nameHolder = dataConstruct; clear('dataConstruct');
if properties.singleStudySub; minSubSize = 1; else; minSubSize = 2; end % specifies minimum subgroup size
% declare matrices
y = zeros(length(nameHolder),1 ); y(y == 0) = nan; % produce effect size array filled with nan
semy = zeros(length(nameHolder),1 ); semy(semy == 0) = nan; % produce standard error array filled with nan
Ni = zeros(length(nameHolder),1 ); Ni(Ni == 0) = nan; % produce sample size array filled with nan
% assign data to matrices
for i = 1:length (nameHolder); % populate arrays from above with available data
indicatorNumber(i) = nameHolder(i).ID;
if ~isempty(nameHolder(i).fESi); y(i) = nameHolder(i).fESi; end
if ~isempty(nameHolder(i).fSEi); semy(i) = nameHolder(i).fSEi; end
if ~isempty(nameHolder(i).Ni); Ni(i) = nameHolder(i).Ni; end
end
allFields = fieldnames(nameHolder); % extract all structure field names
assignin('base', 'allFields', allFields); % assign structure field names to workspace
assignin('base', 'covariates', covariates); % assign covariate names to workspace
% find location of covariates of interest
n = 1;
for i = 1:length(covariates) % iterate through known covariates
for j = 1:length(allFields) % iterate through datastructure field names
if strcmp(covariates{i}, allFields{j}); % identify indicies at which covariate is stored in structure
keepIndex(n) = j; n = n + 1;
end
end
end
% remove unecesary fields in structure (only covariates and results remain)
try; keepIndex; catch; keepIndex = []; end % check if covariates are present
for k = 1:length(allFields)
if ~any(k == keepIndex)
try; nameHolder = rmfield(nameHolder, allFields{k}); % remove non-covariate fields
catch; display([ field2rmv{k} ' could not be removed from subgroup analysis because it does not exist']); end
end
end
try; nameHolder = rmfield(nameHolder, 'ISR'); catch; end;
% group data by covariate subgroups
fnames = fieldnames(nameHolder); % extract field names (corresponding to only covariates)
n = 1;
for i = 1:length(fnames) % iterate through each covariate
temp{i} = [nameHolder.(fnames{i})]; % extract covariate values
temp{i} = temp{i}(~isnan(temp{i})); % remove missing/not available data
try; temp{i} = str2num( temp{i}); catch; end % ensure covariate values are numerical
uniq{i} = unique (temp{i}); % find unique covariate subgroups
% for each subgroup, extract data.
reported = [];
startN = n; % start index for given covariate
mSub = 0; % track number of subgroups per covariate
for k = 1:length(uniq{i}) % iterature through each subgroup for given covariate
included = [];
count = 1;
try; headers{n} = [fnames{i} '_' num2str(uniq{i}(k))]; % name for covariate subgroup assigned
y_sg = []; sd_sg = []; se_sg = []; n_sg = [];
yraw_sg = []; stdyraw_sg = []; semyraw_sg = []; id_sg = [];
for m = 1:length(nameHolder) %iterate through entire data structure
if uniq{i}(k) == nameHolder(m).(fnames{i}) % extract effect size and associate statistics if part of given subgroup.
cont = 1; % flag specifyig inclusion of data in subgroup
% ensure subgroup data is reported and valid
if isnan(y(m)); cont = 0; end;
if y(m) == 0; cont = 0; end;
if isempty(y(m)); cont = 0; end
if isnan(semy(m)); cont = 0; end; if isempty(semy(m)); cont = 0; end;
if isnan(Ni(m)); cont = 0; end; if isempty(Ni(m)); cont = 0; end
% assign data to subgroup
if cont == 1 % if all conditions are fullfilled, assign data.
reported = [reported m];
id_sg(count) = indicatorNumber(m);
y_sg(count) = y(m);
se_sg(count) = semy(m);
n_sg(count) = Ni(m);
count = count + 1;
included(count) = m; % track which studies are assigned to subgroup
end
end
end
% if subgroup is not empty, assign data to subgroup structure
if ~isempty(y_sg) & length(y_sg) >= minSubSize
subgroup(n).subgroup = headers{n};
subgroup(n).indicatorNumber = id_sg;
subgroup(n).y = y_sg;
subgroup(n).se = se_sg;
subgroup(n).n = n_sg;
mSub = mSub+1;
n = n + 1;
else
reported = setdiff(reported, included); % identify which studies did report covariate
end
catch ME;
getReport(ME)
end
end
count = 1;
% create additional subgroup for given covariate that pools remainder
% of studies that did not report covariate
try; headers{n} = [fnames{i} '_nr']; % characteristic not reported for this set of subgroups
y_sg = []; sd_sg = []; se_sg = []; n_sg = []; yraw_sg = [];
stdyraw_sg = []; semyraw_sg = []; id_sg = [];
for m = 1:length(nameHolder)
if ~ismember(m, reported) % determine which study haven't been assigned to subgroup
cont = 1;
if isnan(y(m)); cont = 0; end;
if y(m) == 0; cont = 0; end;
if isempty(y(m)); cont = 0; end
if isnan(semy(m)); cont = 0; end; if isempty(semy(m)); cont = 0; end;
if isnan(Ni(m)); cont = 0; end; if isempty(Ni(m)); cont = 0; end
if cont == 1 % if all conditions are fullfilled, assign data.
id_sg(count) = indicatorNumber(m);
y_sg(count) = y(m);
se_sg(count) = semy(m);
n_sg(count) = Ni(m);
count = count + 1;
end
end
end
% store not-reported subgroup to final subgroup structure
if ~isempty(y_sg)
subgroup(n).subgroup = headers{n};
subgroup(n).indicatorNumber = id_sg;
subgroup(n).y = y_sg;
subgroup(n).se = se_sg;
subgroup(n).n = n_sg;
mSub = mSub+1;
n = n + 1;
end
catch ME;
getReport(ME)
end
for nRange = startN:n
subgroup(nRange).nSubgroups = mSub; % tracks number of subgroups per covariate, for later error rate correction
end
end
% assign total set of data (with no subgroup partition) to subgroup structure
count = 1;
for m = 1:length(y);
cont = 1;
if isnan(y(m)); cont = 0; end; if y(m) == 0; cont = 0; end
if isnan(semy(m)); cont = 0; end
if isnan(Ni(m)); cont = 0; end
if cont == 1;
idTotal(count) = indicatorNumber(m);
yTotal(count) = y(m);
seTotal(count) = semy(m);
nTotal(count) = Ni(m);
count = count + 1;
end
end
total.subgroup = 'Total';
total.indicatorNumber = idTotal;
total.y = yTotal;
total.se = seTotal;
total.n = nTotal;
total.nSubgroups = 1;
try; subgroup = [total subgroup]; catch
subgroup = [total]; end
end
function modelEval = modelEvaluation(ES, ciWidth, ESi, SEi);
ciU = ES+ciWidth;
ciUi = ESi ;
ciL = ES-ciWidth;
ciLi = ESi ;
cover = ones(1,length(ESi));
cover(ciL > ciUi) = 0;
cover(ciLi > ciU) = 0;
coverage = 100*sum(cover)/length(ESi);
modelEval.coverage = coverage;
end
function data = raw2log (data, properties, Sheet);
switch properties.dataTransformation
case 'log';
for i = 1:length(data);
if ~isempty(data(i).SEi) && ~isempty(data(i).ESi) && data(i).ESi > 0;
sx(i) = data(i).SEi; Ni(i) = data(i).Ni;
ESi(i) = data(i).ESi;
sz(i) = sqrt(log10(((sx(i)^2 )/ (ESi(i)^2)) + 1));
z(i) = log10((ESi(i)^2)/sqrt((sx(i)^2)+(ESi(i)^2)));
% Wz(i)= 1/ sz(i)^2;
data(i).fSEi = sz(i) ;
% data(i).fWi = Wz(i);
data(i).fESi = z(i);
end
end
figure;
ESi = ESi (ESi~=0); z = z (z~=0);
subplot(121); h1 = histogram(ESi); title([Sheet ' raw distribution']); ylabel('unweighted count'); xlabel('ESi, raw');
subplot(122); h2 = histogram(z); title([Sheet ' log-transformed distribution']); ylabel ('unweighted count'); xlabel('ESi, log10 scale');
set(h1, 'FaceColor' , 'k', 'EdgeColor', 'k');
set(h2, 'FaceColor' , 'k', 'EdgeColor', 'k');
case 'raw'
for i = 1:length(data);
if ~isempty(data(i).SEi) && ~isempty(data(i).ESi)
z(i) = data(i).ESi;
data(i).fSEi = data(i).SEi;
% data(i).fWi = data(i).Wi;
data(i).fESi = data(i).ESi;
end
end
figure;
z = z (z~=0);
h = histogram(z); title([Sheet ' raw distribution']); ylabel('unweighted count'); xlabel('ESi, raw');
set(h, 'FaceColor' , 'k', 'EdgeColor', 'k');
end
keeper = 1;
for i = 1:length(data);
if ~isempty(data(i).fESi) && ~isnan(data(i).fESi) && data(i).fSEi~=0
temp(keeper) = data(i);
keeper = keeper + 1;
end
end
data = []; data = temp; clear ('temp');
end
%% absolute difference
function data = AbsoluteDifference(data)
for i = 1:length(data);
if ~isempty(data(i).nc) && ~isempty(data(i).sec) && ~isempty(data(i).xc)
nr(i) = data(i).nr; nc(i) = data(i).nc;
sec(i) = data(i).sec; ser(i) = data(i).ser;
xr(i) = data(i).xr; xc(i) = data(i).xc;
if ~isnan(nr(i)) && ~isnan(nc(i)); N(i) = nr(i) + nc(i); end
if ~isnan(nr(i)) && isnan(nc(i)); N(i) = nr(i) + nr(i); end
if isnan(nr(i)) && ~isnan(nc(i)); N(i) = nc(i) + nc(i); end
sdc(i) = sec(i) * sqrt(nc(i)); sdr(i) = ser(i) * sqrt(nr(i));
sp(i) = sqrt((((nc(i)-1)*(sdc(i)^2))+((nr(i)-1)*(sdr(i)^2)))/(N(i)-2));
se(i) = sqrt ((N(i)*(sp(i)^2))/(nr(i)*nc(i)));
es(i) = xr(i) - xc(i); % absolute difference
% w(i) = 1/(se(i)^2);
% esw(i) = es(i)*w(i);
data(i).Ni = N(i);
data(i).SEi = se(i);
data(i).ESi = es(i);
% data(i).Wi = w(i);
% data(i).ESWi = esw(i);
else
try;
nr(i) = data(i).nr;
ser(i) = data(i).ser;
xr(i) = data(i).xr;
N(i) = nr(i);
sdr(i) = ser(i) * sqrt(nr(i));
sp(i) = sdr(i);
se(i) =sp(i) / sqrt(N(i));
es(i) = xr(i); % absolute difference
% w(i) = 1/(se(i)^2);
% esw(i) = es(i)*w(i);
data(i).Ni = N(i);
data(i).SEi = se(i);
data(i).ESi = es(i);
% data(i).Wi = w(i);
catch ME
data(i).Ni = [];
data(i).SEi = [];
data(i).ESi = [];
% data(i).Wi = [];
end
end
end
end
%% normalized difference
function data = NormalizedDifference(data)
for i = 1:length(data);
try;
nr(i) = data(i).nr; nc(i) = data(i).nc;
sec(i) = data(i).sec; ser(i) = data(i).ser;
xr(i) = data(i).xr; xc(i) = data(i).xc;
if ~isnan(nr(i)) && ~isnan(nc(i)); N(i) = nr(i) + nc(i); end
if ~isnan(nr(i)) && isnan(nc(i)); N(i) = nr(i) + nr(i); end
if isnan(nr(i)) && ~isnan(nc(i)); N(i) = nc(i) + nc(i); end
sdc(i) = (sec(i) * sqrt(nc(i)))/xc(i);
sdr(i) = (ser(i) * sqrt(nr(i)))/xr(i); %noramlized SD
se(i) = sqrt (((sdc(i)^2)/nc(i)) + ((sdr(i)^2)/nr(i))); % normalized SE
es(i) = (xr(i) - xc(i))/xc(i); % normalized difference
% w(i) = 1/(se(i)^2);
% esw(i) = es(i)*w(i);
if isinf(es(i)); es(i) = nan(); end
data(i).Ni = N(i);
data(i).SEi = se(i);
data(i).ESi = es(i);
% data(i).Wi = w(i);
catch ME;
end
end
end
%standard difference according to Hedges
function data = hedgesG(data)
for i = 1:length(data);
try;
nr(i) = data(i).nr; nc(i) = data(i).nc;
sec(i) = data(i).sec; ser(i) = data(i).ser;
xr(i) = data(i).xr; xc(i) = data(i).xc;
if ~isnan(nr(i)) && ~isnan(nc(i)); N(i) = nr(i) + nc(i); Np(i) = nr(i) * nc(i);end
if ~isnan(nr(i)) && isnan(nc(i)); N(i) = nr(i) + nr(i); Np(i) = nr(i) * nr(i); end
if isnan(nr(i)) && ~isnan(nc(i)); N(i) = nc(i) + nc(i); Np(i) = nc(i) * nc(i);end
sdc(i) = (sec(i) * sqrt(nc(i)));
sdr(i) = (ser(i) * sqrt(nr(i)));
sp(i) = sqrt((((nc(i)-1)*(sdc(i)^2))+((nr(i)-1)*(sdr(i)^2)))/(N(i)-2));
es(i) = ((xr(i)-xc(i))/sp(i)) * (1-(3/((4*N(i))-9)));
se(i) = sqrt((N(i)/Np(i))+((es(i)^2)/(2*(N(i)-3.94))));
%
% w(i) = 1/(se(i)^2);
% esw(i) = es(i)*w(i);
data(i).Ni = N(i);
data(i).SEi = se(i);
data(i).ESi = es(i);
% data(i).Wi = w(i);
catch ME;
end
end
end
%% data extraction from structure
function [data] = dataExtraction(data, exStudies);
n = 1;
xr = []; nr = []; ser = []; xc = []; sec = []; nc = [];
for i = 1:length(data)
if ~isempty(exStudies); exclude = any(exStudies == data(i).indicatorNumber); else; exclude = 0; end
if ~isempty(data(i).nr) && ~isempty(data(i).ser) && ~isempty(data(i).xr) && ~isnan(data(i).nr) && ~isnan(data(i).ser) && ~isnan(data(i).xr) && exclude == 0;
nr(n) = data(i).nr;
ser(n) = data(i).ser;
xr(n) = data(i).xr;
data(i).xr = xr(n);
data(i).nr = nr(n);
data(i).ser = ser(n);
end
try;
if ~isempty(data(i).xc) && ~isempty(data(i).nc) && ~isempty(data(i).sec) && ~isnan(data(i).xc) && ~isnan(data(i).nc) && ~isnan(data(i).sec) && exclude == 0;
xc(n) = data(i).xc;
try; nc(n) = data(i).nc; catch; nc(n) = nr(n); end
sec(n) = data(i).sec;
data(i).xc = xc(n);
data(i).sec = sec(n);