Skip to content

Commit 110689a

Browse files
committed
Code prepared for cluster TFCE power test
1 parent 439c48a commit 110689a

File tree

2 files changed

+88
-9
lines changed

2 files changed

+88
-9
lines changed

config_files/setparams.m

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
% Params.data_dir = './data/s_abcd_fc_rosenblatt.mat';
3232
Params.data_dir = './data/s_hcp_fc_noble_tasks.mat';
3333
% Params.data_dir = './data/s_hcp_act_noble_1.mat';
34-
Params.output = 'test_tfce_comparison';
34+
Params.output = 'tfce_power_comp';
3535

3636
% Save specifications - if NaN output becomes dataset file name
3737
Params.save_directory = './power_calculator_results/';
@@ -57,9 +57,9 @@
5757

5858
%%% Resampling parameters %%%
5959
Params.parallel = false; % run stuff sequentially or in parallel
60-
Params.n_workers = 25; % num parallel workers for parfor, best if # workers = # cores
61-
Params.n_repetitions = 100; % 500 recommended
62-
Params.batch_size = 25;
60+
Params.n_workers = 10; % num parallel workers for parfor, best if # workers = # cores
61+
Params.n_repetitions = 500; % 500 recommended
62+
Params.batch_size = 10;
6363

6464

6565
%% Skip some tests - change ranges or the function
@@ -68,7 +68,7 @@
6868

6969

7070
%% List of subjects per subset
71-
Params.list_of_nsubset = {80}; % To change this, add more when necessary
71+
Params.list_of_nsubset = {20, 80, 200}; % To change this, add more when necessary
7272
% size of subset is full group size (N=n*2 for two sample t-test or N=n for one-sample)
7373

7474
% Current model (see above design matrix) only designed for t-test
@@ -80,8 +80,8 @@
8080
Params.tpr_dthresh = 0; % Threshold for true positives vs negatives
8181
Params.save_significance_thresh = 0.15;
8282
% Params.all_cluster_stat_types = {'Parametric', 'Size_cpp', 'Fast_TFCE_cpp', 'Constrained_cpp', 'Omnibus_cNBS'};
83-
Params.all_cluster_stat_types = {'Exact_FC_TFCE', 'TFCE_dh1', 'TFCE_dh5', 'TFCE_dh10', 'TFCE_dh25', ...
84-
'Fast_TFCE_dh1', 'Fast_TFCE_dh5', 'Fast_TFCE_dh10', 'Fast_TFCE_dh25'};
83+
Params.all_cluster_stat_types = {'IC_TFCE_FC_cpp_dh1','IC_TFCE_FC_cpp_dh5','IC_TFCE_FC_cpp_dh10', ...
84+
'IC_TFCE_FC_cpp_dh25'};
8585

8686
Params.all_submethods = {'FWER', 'FDR'};
8787

@@ -94,8 +94,8 @@
9494
% Use a small subset of permutations for faster development -- inappropriate for inference
9595

9696
Params.testing = true;
97-
Params.test_n_perms = 1;
98-
Params.test_n_repetitions = 1;
97+
Params.test_n_perms = 2;
98+
Params.test_n_repetitions = 2;
9999
Params.test_n_workers = 1;
100100
Params.test_disable_save = false;
101101

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
classdef IC_TFCE_FC_cpp_dh25
2+
3+
properties
4+
level = "edge";
5+
permutation_based = true;
6+
permutations = 800; % Override permutation number
7+
method_params = IC_TFCE_FC_cpp_dh25.get_fast_tfce_params()
8+
end
9+
10+
methods (Static, Access = private)
11+
function method_params = get_fast_tfce_params()
12+
method_params = struct();
13+
method_params.dh = 0.25;
14+
method_params.H = 3.0;
15+
method_params.E = 0.4;
16+
end
17+
end
18+
19+
methods
20+
21+
function pval = run_method(obj,varargin)
22+
23+
% Applies Threshold-Free Cluster Enhancement (TFCE) and computes p-values
24+
% using a permutation-based approach.
25+
%
26+
% Inputs:
27+
% - STATS: Structure containing statistical parameters, including threshold.
28+
% - edge_stats: Raw test statistics for edges.
29+
% - permutation_edge_data: Precomputed permutation edge statistics.
30+
%
31+
% Outputs:
32+
% - pval: TFCE-corrected p-values.
33+
34+
params = struct(varargin{:});
35+
36+
% Extract relevant inputs
37+
STATS = params.statistical_parameters;
38+
edge_stats = params.edge_stats;
39+
permuted_edge_stats = params.permuted_edge_data; % Explicitly using the new argument
40+
41+
% Convert the edge statistics back into a matrix
42+
test_stat_mat = STATS.unflatten_matrix(edge_stats);
43+
44+
% Apply TFCE transformation to the observed test statistics
45+
cluster_stats_target = apply_tfce_cpp(test_stat_mat, obj.method_params.dh, ...
46+
obj.method_params.H, obj.method_params.E);
47+
cluster_stats_target = STATS.flatten_matrix(cluster_stats_target);
48+
49+
% Ensure permutation data is provided
50+
if isempty(permuted_edge_stats)
51+
error('Permutation data is missing. Ensure precomputed permutations are provided.');
52+
end
53+
54+
% Number of permutations
55+
if size(permuted_edge_stats, 2) < obj.permutations
56+
K = size(permuted_edge_stats, 2);
57+
else
58+
K = obj.permutations;
59+
end
60+
null_dist = zeros(K, 1);
61+
62+
% Apply TFCE transformation to each permutation
63+
for i = 1:K
64+
perm_stat_mat = STATS.unflatten_matrix(permuted_edge_stats(:, i));
65+
tfce_null = apply_tfce_cpp(perm_stat_mat, obj.method_params.dh, ...
66+
obj.method_params.H, obj.method_params.E);
67+
null_dist(i) = max(tfce_null(:)); % Store max TFCE value for permutation
68+
end
69+
70+
% Compute p-values using permutation-based FWER correction
71+
pval = arrayfun(@(stat) (sum(stat <= null_dist)) /K, cluster_stats_target(:));
72+
73+
end
74+
75+
end
76+
77+
end
78+
79+

0 commit comments

Comments
 (0)