File size: 6,645 Bytes
72417f2 | 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 | % Script to generate GLMs with the matched case info and volume statistics
% from both MRI and photo segmentations
clear all
%% load data
removalLevel = 1;
GLM_RESULTS = ['/home/acasamitjana/Data/UWphoto/PowerAnalysis/GLM/GLMresults_removalLevel_' num2str(removalLevel) '_new.mat'];
load(GLM_RESULTS, 'MRI_GLM_resultsStruct', 'Hrd_GLM_resultsStruct', 'Sft_GLM_resultsStruct', 'Design_mat'); X=Design_mat; clear Design_mat;
ALPHA = 0.05;
POWER = 0.8;
N_COVARIATES = 4;
GAMMAX = inv(X'*X);
%% MRI power analysis
disp('MRI analysis')
PA_MRI.ALPHA = ALPHA;
PA_MRI.POWER = POWER;
N_MRI = MRI_GLM_resultsStruct.N_total;
MRI_results = MRI_GLM_resultsStruct.full;
volume_fields = fieldnames(MRI_results);
MRI_col = zeros(length(volume_fields),1);
for it_volume=1:length(volume_fields)
stats = MRI_results.(volume_fields{it_volume}).stats;
beta = stats.beta(3);
gammaX=GAMMAX(3,3);
sigma2 = sum(stats.resid.*stats.resid);
[nout, tval, pval, power] = computeSampleSize(0, beta, sigma2, gammaX, N_COVARIATES, POWER, ALPHA);
PA_MRI.full.(volume_fields{it_volume}).power = power;
PA_MRI.full.(volume_fields{it_volume}).pval = pval;
PA_MRI.full.(volume_fields{it_volume}).tval = tval;
PA_MRI.full.(volume_fields{it_volume}).sample_size = nout;
% if pval>ALPHA
% disp(['MRI_ALPHA_' volume_fields{it_volume} ])
% end
% if power<POWER
% disp(['MRI_POWER_' volume_fields{it_volume} ])
% end
MRI_col(it_volume) = nout;
end
%% Hard power analysis
disp('Hard analysis')
PA_Hard.ALPHA = ALPHA;
PA_Hard.POWER = POWER;
N_Hard = Hrd_GLM_resultsStruct.N_total;
Hard_results = Hrd_GLM_resultsStruct.full;
volume_fields = fieldnames(Hard_results);
Hard_col = zeros(length(volume_fields),1);
for it_volume=1:length(volume_fields)
stats = Hard_results.(volume_fields{it_volume}).stats;
beta = stats.beta(3);
gammaX=GAMMAX(3,3);
sigma2 = sum(stats.resid.*stats.resid);
[nout, tval, pval, power] = computeSampleSize(0, beta, sigma2, gammaX, N_COVARIATES, POWER, ALPHA);
PA_Hard.full.(volume_fields{it_volume}).power = power;
PA_Hard.full.(volume_fields{it_volume}).pval = pval;
PA_Hard.full.(volume_fields{it_volume}).tval = tval;
PA_Hard.full.(volume_fields{it_volume}).sample_size = nout;
% if pval>ALPHA
% disp(['Hard_ALPHA_' volume_fields{it_volume} ])
% end
% if power<POWER
% disp(['Hard_POWER_' volume_fields{it_volume} ])
% end
Hard_col(it_volume) = nout;
end
%% Soft power analysis
disp('Soft analysis')
PA_Soft.ALPHA = ALPHA;
PA_Soft.POWER = POWER;
N_Soft = Sft_GLM_resultsStruct.N_total;
Soft_results = Sft_GLM_resultsStruct.full;
volume_fields = fieldnames(Soft_results);
Soft_col = zeros(length(volume_fields),1);
for it_volume=1:length(volume_fields)
stats = Soft_results.(volume_fields{it_volume}).stats;
% if strcmp(volume_fields{it_volume}, 'Average_Amygdala')
% pause(0.1)
% end
beta = stats.beta(3);
gammaX=GAMMAX(3,3);
sigma2 = sum(stats.resid.*stats.resid);
[nout, tval, pval, power] = computeSampleSize(0, beta, sigma2, gammaX, N_COVARIATES, POWER, ALPHA);
PA_Soft.full.(volume_fields{it_volume}).power = power;
PA_Soft.full.(volume_fields{it_volume}).pval = pval;
PA_Soft.full.(volume_fields{it_volume}).tval = tval;
PA_Soft.full.(volume_fields{it_volume}).sample_size = nout;
% if pval>ALPHA
% disp(['Soft_ALPHA_' volume_fields{it_volume} ])
% end
% if power<POWER
% disp(['Soft_POWER_' volume_fields{it_volume} num2str(power) ])
% end
Soft_col(it_volume) = nout;
end
%% Plots
INTERESTING_VOLUMES = {'Cerebral_White_Matter', 'Cerebral_Cortex', 'Lateral_Ventricle', 'Thalamus', 'Caudate', 'Putamen', 'Pallidum', 'Hippocampus', 'Amygdala'};
INTERESTING_VOLUMES_PLOT = {'Cerebral-White-Matter', 'Cerebral-Cortex', 'Lateral-Ventricle', 'Thalamus', 'Caudate', 'Putamen', 'Pallidum', 'Hippocampus', 'Amygdala'};
% Interesting table
MRI_interesting_col = zeros(length(INTERESTING_VOLUMES), 4);
Soft_interesting_col = zeros(length(INTERESTING_VOLUMES), 4);
Hard_interesting_col = zeros(length(INTERESTING_VOLUMES), 4);
for it_interesting=1:length(INTERESTING_VOLUMES)
MRI_interesting_col(it_interesting,:) = [PA_MRI.full.(['Average_' INTERESTING_VOLUMES{it_interesting}]).sample_size PA_MRI.full.(['Average_' INTERESTING_VOLUMES{it_interesting}]).tval PA_MRI.full.(['Average_' INTERESTING_VOLUMES{it_interesting}]).pval PA_MRI.full.(['Average_' INTERESTING_VOLUMES{it_interesting}]).power];
Soft_interesting_col(it_interesting,:) = [PA_Soft.full.(['Average_' INTERESTING_VOLUMES{it_interesting}]).sample_size PA_Soft.full.(['Average_' INTERESTING_VOLUMES{it_interesting}]).tval PA_Soft.full.(['Average_' INTERESTING_VOLUMES{it_interesting}]).pval PA_Soft.full.(['Average_' INTERESTING_VOLUMES{it_interesting}]).power];
Hard_interesting_col(it_interesting,:) = [PA_Hard.full.(['Average_' INTERESTING_VOLUMES{it_interesting}]).sample_size PA_Hard.full.(['Average_' INTERESTING_VOLUMES{it_interesting}]).tval PA_Hard.full.(['Average_' INTERESTING_VOLUMES{it_interesting}]).pval PA_Hard.full.(['Average_' INTERESTING_VOLUMES{it_interesting}]).power];
end
TMRI = table(MRI_interesting_col(:,1),MRI_interesting_col(:,2),MRI_interesting_col(:,3),MRI_interesting_col(:,4), 'VariableNames', {'SampleSize','Tval','Pval','Power'});
TSOFT = table(Soft_interesting_col(:,1),Soft_interesting_col(:,2),Soft_interesting_col(:,3),Soft_interesting_col(:,4), 'VariableNames', {'SampleSize','Tval','Pval','Power'});
THARD = table(Hard_interesting_col(:,1),Hard_interesting_col(:,2),Hard_interesting_col(:,3),Hard_interesting_col(:,4), 'VariableNames', {'SampleSize','Tval','Pval','Power'});
TintComplete = table(TMRI,TSOFT,THARD, 'RowNames', INTERESTING_VOLUMES);
Tint = table(MRI_interesting_col(:,1),Soft_interesting_col(:,1),Hard_interesting_col(:,1), 'RowNames', INTERESTING_VOLUMES, 'VariableNames', {'MRI','Soft','Hard'} );
figure
plot(MRI_interesting_col,'b'), hold on
plot(Hard_interesting_col,'r'), hold on
plot(Soft_interesting_col,'k'), hold on
set(gca, 'YScale', 'log')
ylabel('Sample size')
xticklabels(INTERESTING_VOLUMES_PLOT)
xtickangle(90)
legend('MRI', 'Hard', 'Soft')
title(['Power analysis: removal level ' num2str(removalLevel)])
% % Full table
% T = table(MRI_col,Hard_col,Soft_col, 'RowNames', volume_fields );
%
% figure
% plot(MRI_col,'b'), hold on
% plot(Hard_col,'r'), hold on
% plot(Soft_col,'k'), hold on
% set(gca, 'YScale', 'log')
% ylabel('Sample size')
% legend('MRI', 'Hard', 'Soft')
|