diff --git a/+nla/+net/ResultRank.m b/+nla/+net/ResultRank.m index 1079512b..3732aee4 100644 --- a/+nla/+net/ResultRank.m +++ b/+nla/+net/ResultRank.m @@ -27,75 +27,83 @@ function ranking_result = rank(obj) import nla.TriMatrix nla.TriMatrixDiag + ranking_result = obj.permuted_network_results.copy(); + for test_type = obj.permuted_network_results.test_methods - if ~isequal(test_type, "no_permutations") || ~isequal(obj.permuted_network_results.test_display_name, "Cohen's D") + if ~isequal(test_type, "no_permutations") && ~isequal(obj.permuted_network_results.test_display_name, "Cohen's D") [ranking_statistic, probability, denominator] = obj.getTestParameters(test_type); permutation_results = obj.permuted_network_results.permutation_results; - no_permutation_results = obj.permuted_network_results.no_permutations; + no_permutation_results = obj.nonpermuted_network_results; % Eggebrecht ranking - obj.eggebrechtRank(test_type, permutation_results, no_permutation_results, ranking_statistic,... - probability, denominator) + ranking_result = obj.eggebrechtRank(test_type, permutation_results, no_permutation_results, ranking_statistic,... + probability, denominator, ranking_result); if ~isequal(obj.permuted_network_results.test_name, "hypergeometric") % Winkler Method ranking - obj.permuted_network_results.(test_type).winkler_p_value = TriMatrix(... + ranking_result.(test_type).winkler_p_value = TriMatrix(... obj.number_of_networks, TriMatrixDiag.KEEP_DIAGONAL... ); - obj.winklerMethodRank(test_type, permutation_results, no_permutation_results, ranking_statistic,... - probability, denominator); + ranking_result = obj.winklerMethodRank(test_type, permutation_results, no_permutation_results, ranking_statistic,... + probability, denominator, ranking_result); % Westfall Young ranking - obj.permuted_network_results.(test_type).westfall_young_p_value = TriMatrix(... + ranking_result.(test_type).westfall_young_p_value = TriMatrix(... obj.number_of_networks, TriMatrixDiag.KEEP_DIAGONAL... ); - obj.westfallYoungMethodRank(test_type, permutation_results, no_permutation_results, ranking_statistic,... - probability, denominator); + ranking_result = obj.westfallYoungMethodRank(test_type, permutation_results, no_permutation_results, ranking_statistic,... + probability, denominator, ranking_result); end end end - - ranking_result = obj.permuted_network_results.copy(); end - function eggebrechtRank(obj, test_type, permutation_results, no_permutation_results, ranking_statistic,... - probability, denominator) + function ranking = eggebrechtRank(obj, test_type, permutation_results, no_permutation_results, ranking_statistic,... + probability, denominator, ranking) for index = 1:numel(no_permutation_results.(probability).v) - combined_probabilities = [... - permutation_results.(strcat(probability, "_permutations")).v(:);... - no_permutation_results.(probability).v(index)... - ]; + if isequal(test_type, "full_connectome") + combined_probabilities = [... + permutation_results.(strcat((probability), "_permutations")).v(:);... + no_permutation_results.(probability).v(index)... + ]; + else + combined_probabilities = [... + permutation_results.(strcat((probability), "_permutations")).v(index, :),... + no_permutation_results.(probability).v(index)... + ]; + end [~, sorted_combined_probabilites] = sort(combined_probabilities); - obj.permuted_network_results.(test_type).p_value.v(index) = find(... + ranking.(test_type).(probability).v(index) = find(... squeeze(sorted_combined_probabilites) == 1 + denominator... ) / (1 + denominator); + if ~isequal(obj.permuted_network_results.test_name, "hypergeometric") - combined_statistics = [permutation_results.(strcat(ranking_statistic, "_permutations")).v(:); no_permutation_results.(ranking_statistic).v(index)]; + combined_statistics = [permutation_results.(strcat((ranking_statistic), "_permutations")).v(:); no_permutation_results.(ranking_statistic).v(index)]; [~, sorted_combined_statistics] = sort(combined_statistics); - obj.permuted_network_results.(test_type).statistic_p_value.v(index) = find(... + ranking.(test_type).(strcat("statistic_", (probability))).v(index) = find(... squeeze(sorted_combined_statistics) == 1 + denominator... ) / (1 + denominator); end end end - function winklerMethodRank(obj, test_type, permutation_results, no_permutation_results, ranking_statistic,... - probability, denominator) + function ranking = winklerMethodRank(obj, test_type, permutation_results, no_permutation_results, ranking_statistic,... + probability, denominator, ranking) max_statistic_array = max(abs(permutation_results.(strcat(ranking_statistic, "_permutations")).v)); for index = 1:numel(no_permutation_results.(probability).v) - obj.permuted_network_results.(test_type).winkler_p_value.v(index) = sum(... + ranking.(test_type).winkler_p_value.v(index) = sum(... squeeze(max_statistic_array) >= abs(no_permutation_results.(ranking_statistic).v(index))... ); end - obj.permuted_network_results.(test_type).winkler_p_value.v =... - obj.permuted_network_results.(test_type).winkler_p_value.v ./ denominator; + ranking.(test_type).winkler_p_value.v =... + ranking.(test_type).winkler_p_value.v ./ denominator; end - function westfallYoungMethodRank(obj, test_type, permutation_results, no_permutation_results, ranking_statistic,... - probability, denominator) + function ranking = westfallYoungMethodRank(obj, test_type, permutation_results, no_permutation_results, ranking_statistic,... + probability, denominator, ranking) % sort statistics in ascending order [sorted_no_permutation_results, sorted_statistic_indexes] = sort(... @@ -117,10 +125,10 @@ function westfallYoungMethodRank(obj, test_type, permutation_results, no_permuta end max_per_permutation_reducing_rows(1, :) = permutations_sorted_by_non_permuted(1, :); - obj.permuted_network_results.(test_type).westfall_young.p_value.v = mean(... + ranking.(test_type).westfall_young.p_value.v = mean(... sorted_no_permutation_results < max_per_permutation_reducing_rows, 2); - obj.permuted_network_results.(test_type).westfall_young.p_value.v(sorted_statistic_indexes) =... - obj.permuted_network_results.(test_type).westfall_young.p_value.v; + ranking.(test_type).westfall_young.p_value.v(sorted_statistic_indexes) =... + ranking.(test_type).westfall_young.p_value.v; end function [ranking_statistic, probability, denominator] = getTestParameters(obj, test_type) @@ -129,7 +137,7 @@ function westfallYoungMethodRank(obj, test_type, permutation_results, no_permuta probability = "p_value"; denominator = obj.permutations * obj.number_of_network_pairs; % Only use these for within network pair and not Chi-Squared and Hypergeometric. - if test_type == "within_network_pair" && ~any(... + if isequal(test_type, "within_network_pair") && ~any(... strcmp(obj.permuted_network_results.test_name, obj.permuted_network_results.noncorrelation_input_tests)... ) ranking_statistic = strcat("single_sample_", ranking_statistic); diff --git a/+nla/+net/unittests/NetworkTestResultTestCase.m b/+nla/+net/unittests/NetworkTestResultTestCase.m index 04cd61cf..2e2d4fb9 100644 --- a/+nla/+net/unittests/NetworkTestResultTestCase.m +++ b/+nla/+net/unittests/NetworkTestResultTestCase.m @@ -13,7 +13,7 @@ function loadInputData(testCase) testCase.number_of_networks = 15; testCase.test_data = TriMatrix(testCase.number_of_networks, TriMatrixDiag.KEEP_DIAGONAL); testCase.test_data.v = rand(size(testCase.test_data.v)); - testCase.test_options = struct("within_net_pair", true, "full_conn", true, "nonpermuted", true); + testCase.test_options = struct("within_network_pair", true, "full_connectome", true, "no_permutations", true); testCase.test = WilcoxonTest(); end end diff --git a/+nla/+net/unittests/ResultRankTestCase.m b/+nla/+net/unittests/ResultRankTestCase.m index d99cf649..5d7f758b 100644 --- a/+nla/+net/unittests/ResultRankTestCase.m +++ b/+nla/+net/unittests/ResultRankTestCase.m @@ -73,8 +73,8 @@ function loadInputData(testCase) testCase.network_test_options.d_max = 0.5; testCase.network_test_options.prob_plot_method = nla.gfx.ProbPlotMethod.DEFAULT; testCase.network_test_options.full_connectome = true; - testCase.network_test_options.within_net_pair = true; - testCase.network_test_options.nonpermuted = true; + testCase.network_test_options.within_network_pair = true; + testCase.network_test_options.no_permutations = true; % Basically have to do everything in the TestPool except run the ranking. So, that's what all this is, everything % in TestPool.runPerm up until ranking. Luckily, we're only doing one network test @@ -99,21 +99,17 @@ function loadInputData(testCase) methods (Test) function fullConnectomeRankTest(testCase) - result_ranker = nla.net.ResultRank(testCase.network_test_result{1}, testCase.permuted_network_results{1},... - testCase.number_of_network_pairs); - ranking = testCase.permuted_network_results{1}.copy(); - ranking = result_ranker.fullConnectomeRank(ranking, testCase.permuted_network_results{1}.ranking_statistic); + result_ranker = nla.net.ResultRank(testCase.permuted_network_results{1}, testCase.number_of_network_pairs); + rank_object = result_ranker.rank(); - testCase.verifyEqual(ranking.full_connectome.p_value.v, testCase.ranking.full_connectome.p_value.v); + testCase.verifyEqual(rank_object.full_connectome.p_value.v, testCase.ranking.full_connectome.p_value.v); end function withinNetworkPairTest(testCase) - result_ranker = nla.net.ResultRank(testCase.network_test_result{1}, testCase.permuted_network_results{1},... - testCase.number_of_network_pairs); - ranking = testCase.permuted_network_results{1}.copy(); - ranking = result_ranker.withinNetworkPairRank(ranking, testCase.permuted_network_results{1}.ranking_statistic); - - testCase.verifyEqual(ranking.within_network_pair.p_value.v, testCase.ranking.within_network_pair.p_value.v); + result_ranker = nla.net.ResultRank(testCase.permuted_network_results{1}, testCase.number_of_network_pairs); + rank_object = result_ranker.rank(); + + testCase.verifyEqual(rank_object.within_network_pair.single_sample_p_value.v, testCase.ranking.within_network_pair.single_sample_p_value.v); end end end \ No newline at end of file