Skip to content

Commit 4076a9b

Browse files
committed
Added tests for automatic test type inference function
1 parent 2f5029f commit 4076a9b

15 files changed

Lines changed: 372 additions & 40 deletions

.DS_Store

2 KB
Binary file not shown.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
function check_multivariate_group(RP)
2+
%% check_multivariate_group
3+
% Validates the multivariate grouping against the selected methods.
4+
% - If a multivariate method is selected, a grouping must exist.
5+
% - When a grouping exists, it must be n_groups x n_var so each column
6+
% corresponds to one variable (edge/voxel).
7+
%
8+
% **Author**: Fabricio Cravo
9+
10+
has_group = ~isequaln(RP.multivariate_group, NaN);
11+
12+
% A multivariate method needs a grouping to run
13+
if RP.has_mvm && ~has_group
14+
error('check_multivariate_group:missingGroup', ...
15+
['A multivariate method was selected but no multivariate ' ...
16+
'grouping is available. Set RP.atlas_file or provide ' ...
17+
'RP.multivariate_group.']);
18+
end
19+
20+
% No grouping and no multivariate method -> nothing to check
21+
if ~has_group
22+
return
23+
end
24+
25+
% Grouping present -> column count must match n_var
26+
n_cols = size(RP.multivariate_group, 2);
27+
if n_cols ~= RP.n_var
28+
error('check_multivariate_group:sizeMismatch', ...
29+
['Multivariate group has %d columns but RP.n_var = %d. ' ...
30+
'Each column must correspond to one variable (edge/voxel).'], ...
31+
n_cols, RP.n_var);
32+
end
33+
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function mvg = mvg_shen_network(Params)
2+
3+
mvg = 'Pass';
4+
5+
end
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
function [mvg_group, n_groups_mvm] = set_multivariate_group(RP)
2+
3+
% Explicit matrix supplied -> use as-is
4+
if ~isequaln(RP.multivariate_group, NaN)
5+
mvg_group = RP.multivariate_group;
6+
n_groups_mvm = size(mvg_group, 1);
7+
return
8+
end
9+
10+
% No atlas / no groups -> nothing to build
11+
if isempty(RP.edge_groups) || RP.n_networks == 0
12+
mvg_group = NaN;
13+
n_groups_mvm = 0;
14+
return
15+
end
16+
17+
% Reuse the same flatten that builds Y's rows -> guaranteed alignment
18+
edge_labels = RP.flat_matrix_fun(RP.edge_groups); % same order as Y rows
19+
edge_labels = edge_labels(:)';
20+
group_ids = unique(edge_labels(edge_labels > 0)); % drop 0 = unassigned
21+
mvg_group = sparse(group_ids(:) == edge_labels); % n_groups x n_edges logical
22+
n_groups_mvm = numel(group_ids);
23+
24+
end

power_calculator_test_script.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@
3535
% tests subs_data_from_score_condition function
3636
test_subs_score_retrieval()
3737

38+
% Test automatic test type retrieval function
39+
test_type_inference_tests()
40+
3841
% test if calculation status is proper
3942
test_check_calculation_status()
4043

41-
42-
4344
clean_test_directories()
4445

4546
create_test_fc_data_set()

power_calculator_tools/check_stat_method_class_validity.m

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function Params = check_stat_method_class_validity(Params)
1+
function [Params, has_mvm] = check_stat_method_class_validity(Params)
22
% check_stat_method_class_validity - Validates properties of statistical method classes.
33
%
44
% Checks that method classes in Params.all_cluster_stat_types:
@@ -96,7 +96,18 @@
9696
error('Method %s has more local permutations defined than can be prepared by setparams', method_name)
9797
end
9898
end
99+
100+
%% Check if multivariate method exists
101+
102+
has_mvm = false;
103+
for i = 1:numel(Params.all_cluster_stat_types)
104+
method_obj = feval(Params.all_cluster_stat_types{i});
99105

106+
if strcmp(method_obj.level,'multivariate')
107+
has_mvm = true;
108+
break
109+
end
100110

111+
end
101112

102113
end

power_calculator_tools/extract_stat_level.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
case 'network'
1212
level = 'network';
13+
14+
case 'multivariate'
15+
level = 'multivariate';
1316

1417
case 'node'
1518
level = 'variable';

power_calculator_tools/infer_test_from_data.m

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@
4242

4343
test_score_set = get_test_score_set(TestData);
4444

45-
if length(test_score_set) == 1 && ~isnan(test_score_set)
45+
if length(test_score_set) == 1
4646
% if all scores are equal to the same number - t test
4747
test_type = 't';
48+
test_type_origin = 'score_cond';
4849

4950
elseif length(test_score_set) > 2
5051
% if score is continuous -> r
@@ -59,9 +60,18 @@
5960
[index_cond_1, index_cond_2] = get_index_matching_score(TestData.score, ...
6061
test_score_set);
6162

62-
sub_ids_cond1 = BrainData.(TestData.reference_condition).sub_ids(index_cond_1);
63-
sub_ids_cond2 = BrainData.(TestData.reference_condition).sub_ids(index_cond_2);
63+
% resolve to actual subject IDs in TestData's own frame first
64+
sub_ids_test_cond1 = TestData.sub_ids(index_cond_1);
65+
sub_ids_test_cond2 = TestData.sub_ids(index_cond_2);
66+
67+
% now cross into BrainData's via ID matching
68+
index_b_data_c1 = ismember(BrainData.(TestData.reference_condition).sub_ids, sub_ids_test_cond1);
69+
index_b_data_c2 = ismember(BrainData.(TestData.reference_condition).sub_ids, sub_ids_test_cond2);
6470

71+
% Get the ids for the condition
72+
sub_ids_cond1 = BrainData.(TestData.reference_condition).sub_ids(index_b_data_c1);
73+
sub_ids_cond2 = BrainData.(TestData.reference_condition).sub_ids(index_b_data_c2);
74+
6575
%% TODO: Divided by the two - focus on group sizes
6676
n_equal = numel(intersect(sort(sub_ids_cond1), sort(sub_ids_cond2)));
6777
n_unique = numel(setxor(sub_ids_cond1, sub_ids_cond2));

power_calculator_tools/initialize_global_pvals.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
method_struct.(full_method_name) = zeros(length(unique(RP.edge_groups)) - 1, RP.n_repetitions);
6060
case "variable"
6161
method_struct.(full_method_name) = zeros(RP.n_var, RP.n_repetitions);
62+
case "multivariate"
63+
method_struct.(full_method_name) = zeros(RP.n_multivariate, RP.n_repetitions);
6264
otherwise
6365
error("Unknown statistic level: %s", method_instance.level);
6466
end

power_calculator_tools/process_repetition_batches.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ function process_repetition_batches(X, Y, RP, UI)
9292
STATS.is_permutation_based = RP.is_permutation_based;
9393
STATS.thresh = RP.tthresh_first_level;
9494
STATS.alpha = RP.pthresh_second_level;
95+
STATS.multivariate_group = RP.multivariate_group;
9596

9697
% **Loop through missing repetitions**
9798
STATSc = parallel.pool.Constant(STATS);

0 commit comments

Comments
 (0)