[FieldTrip] Calculating effect size (cohens d) for an individual cluster in Fieldtrip

Annie Menart amenart at purdue.edu
Thu Sep 25 23:39:58 CEST 2025


Dear Fieldtrippers,
We've been trying to calculate the effect size for the average over the significant cluster (we only have one from our cluster-based permutation analysis) that we've identified. We've looked at the section "Computing the effect size for the average over the cluster"  (https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.fieldtriptoolbox.org%2Fexample%2Fstats%2Feffectsize%2F%23%3A~%3Atext%3DThe%2520effect%2520size%2520is%25201.47%2Cfrom%2520350%2520to%2520550%2520milliseconds&data=05%7C02%7Cfieldtrip%40science.ru.nl%7Cfd34aecc6e8241cab22e08ddfc7c191b%7C084578d9400d4a5aa7c7e76ca47af400%7C1%7C0%7C638944332124205506%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=8wmH%2BtrpYDqyfeaOsI4qD2tsc2jrD0qVhG%2FKxG7VF3I%3D&reserved=0.) and have attempted to implement it in the section of the code "ATTEMPT 2" shown below and got a cohens d of 4.6582, which was a lot higher than expected, so we don't think it's correct.
To solve this, we tried an alternative method to calculate cohens d using ft_freqstatistics, as shown in the section of code "ATTEMPT 1." The outputted cohens d values (shown in the commented sections) seem much more reasonable, but we're not sure that the code makes sense.
Can anyone provide input on calculating effect size over cluster and if either of these attempts at coding it seem accurate?

Here is our code:
%% CALCULATE COHENS D
% get cluster
cluster = squeeze(stat.posclusterslabelmat)==1;

% get the indices for the cluster
cluster_inds = find(cluster);
cluster_inds_size = size(cluster_inds, 1);

% GROUP A
% get number of participants
num_parts_groupA = size(groupA_data.powspctrm,1);

% create empty matrix
groupA_powspctrm_cluster_only = zeros(num_parts_groupA, cluster_inds_size);

% iterate through each participant
for ind=1:num_parts_groupA
% extract their powspctrm matrix
part_mat = squeeze(groupA_data.powspctrm(ind, :, :, :));
% extract the values in the cluster
part_vals_cluster = part_mat(cluster_inds);
% add participant to list of values for all participants
groupA_powspctrm_cluster_only(ind, :) = part_vals_cluster;
End

% GROUP B
% get number of participants
num_parts_groupB = size(groupB_data.powspctrm,1);

% create empty matrix
groupB_powspctrm_cluster_only = zeros(num_parts_groupB, cluster_inds_size);

% iterate through each participant
for ind=1:num_parts_groupB
% extract their powspctrm matrix
part_mat = squeeze(groupB_data.powspctrm(ind, :, :, :));

% extract the values in the cluster
part_vals_cluster = part_mat(cluster_inds);

% add participant to list of values for all participants
groupB_powspctrm_cluster_only(ind, :) = part_vals_cluster;
End

% add back to group_data
groupA_data.powspctrm_cluster_only = groupA_powspctrm_cluster_only;
groupB_data.powspctrm_cluster_only = groupB_powspctrm_cluster_only;
groupA_data.powspctrm_cluster_onlydimord = 'subj_comp';
groupB_data.powspctrm_cluster_onlydimord = 'subj_comp';

% ATTEMPT 1: Calculate effect size (Cohen's d) for the cluster
cfg = [];
cfg.method = 'analytic';
cfg.statistic = 'cohensd';
cfg.parameter = 'powspctrm_cluster_only';
N_groupA = size(groupA_data.powspctrm_cluster_only, 1);
N_groupB = size(groupB_data.powspctrm_cluster_only, 1);
Nsubj = N_groupA + N_groupB;
design = zeros(1, Nsubj);
design(1,1:N_groupA) = 1;
design(1,N_groupA+1:Nsubj) = 2;
cfg.design = design;
cfg.ivar = 1;

cohensD_output = ft_freqstatistics(cfg, groupA_data, groupB_data);
cohensD_avg = mean(cohensD_output.cohensd); % 0.3958
cohensD_max = max(cohensD_output.cohensd); % 0.5312

%% ATTEMPT 2: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.fieldtriptoolbox.org%2Fexample%2Fstats%2Feffectsize%2F&data=05%7C02%7Cfieldtrip%40science.ru.nl%7Cfd34aecc6e8241cab22e08ddfc7c191b%7C084578d9400d4a5aa7c7e76ca47af400%7C1%7C0%7C638944332124235877%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=C5ddhpgsRY8o8InldHRwgrEFnyb66FGnQXiCjp6jo7M%3D&reserved=0

groupA_means = mean(groupA_data.powspctrm_cluster_only, 1);
groupB_means = mean(groupB_data.powspctrm_cluster_only, 1);

x1= groupA_means;
x2 = groupB_means;
cohensd = mean(x1-x2) ./ std(x1-x2); % we get value 4.6582
Thanks!

Annie


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20250925/67e74e3e/attachment.htm>


More information about the fieldtrip mailing list