diff --git a/+nla/+net/+test/KolmogorovSmirnovTest.m b/+nla/+net/+test/KolmogorovSmirnovTest.m deleted file mode 100644 index 1207f222..00000000 --- a/+nla/+net/+test/KolmogorovSmirnovTest.m +++ /dev/null @@ -1,68 +0,0 @@ -classdef KolmogorovSmirnovTest < handle - %KOLMOGOROVSMIRNOVTEST Kolmogorov-Smirnov test - properties (Constant) - name = "kolmogorov_smirnov" - display_name = "Kolmogorov-Smirnov" - statistics = ["ks_statistic", "single_sample_ks_statistic"] - ranking_statistic = "ks_statistic" - end - - methods - function obj = KolmogorovSmirnovTest() - end - - function result = run(obj, test_options, edge_test_results, network_atlas, permutations) - %RUN runs the Kolmogorov-Smirnov goodness of fit test - % test_options: The selected values for the test to be run. Formerly input_struct. Options are in nla.net.genBaseInputs - % edge_test_results: Non-permuted edge test results. Formerly edge_result - % network_atlas: Network atlas for data - - import nla.TriMatrix nla.TriMatrixDiag - - number_of_networks = network_atlas.numNets(); - - % Store results in the 'no_permutations' structure if this is the no-permutation test - permutation_results = "no_permutations"; - ks_statistic = "ks_statistic"; - p_value = "uncorrected_two_sample_p_value"; - single_sample_p_value = "uncorrected_single_sample_p_value"; - single_sample_ks_statistic = "single_sample_ks_statistic"; - if isequal(permutations, true) - % Otherwise, add it on to the back of the 'permutation_results' structure - permutation_results = "permutation_results"; - p_value = "two_sample_p_value_permutations"; - ks_statistic = strcat(ks_statistic, "_permutations"); - single_sample_p_value = "single_sample_p_value_permutations"; - single_sample_ks_statistic = strcat(single_sample_ks_statistic, "_permutations"); - end - - result = nla.net.result.NetworkTestResult(test_options, number_of_networks, obj.name, obj.display_name, obj.statistics, obj.ranking_statistic); - - % Double for-loop to iterate through trimatrix. Network is the row, network2 the column. Since - % we only care about the bottom half, second for-loop is 1:network - for network = 1:number_of_networks - for network2 = 1:network - network_rho = edge_test_results.coeff.get(network_atlas.nets(network).indexes,... - network_atlas.nets(network2).indexes); - [~, p, ks] = kstest2(network_rho, edge_test_results.coeff.v); - result.(permutation_results).(p_value).set(network, network2, p); - result.(permutation_results).(ks_statistic).set(network, network2, ks); - - [~, single_sample_p, single_sample_ks] = kstest(network_rho); - result.(permutation_results).(single_sample_p_value).set(network, network2, single_sample_p); - result.(permutation_results).(single_sample_ks_statistic).set(network, network2, single_sample_ks); - end - end - - end - end - - methods (Static) - function inputs = requiredInputs() - inputs = {... - nla.inputField.Integer('behavior_count', 'Test count:', 1, 1, Inf),... - nla.inputField.Number('prob_max', 'Net-level P threshold <', 0, 0.05, 1),... - }; - end - end -end \ No newline at end of file diff --git a/+nla/+qualityControl/checkNormalityWithKS.m b/+nla/+qualityControl/checkNormalityWithKS.m new file mode 100644 index 00000000..58ad6e39 --- /dev/null +++ b/+nla/+qualityControl/checkNormalityWithKS.m @@ -0,0 +1,64 @@ +function checkNormalityWithKS(fig, input_struct, test_pool) + + prog = uiprogressdlg(... + fig, 'Title', 'Checking Normaility', 'Message', 'Running Kolmogorov-Smirnov Test'... + ); + prog.Value = 0.02; + + prog.Value = 0.25; + edge_test_result = test_pool.runEdgeTest(input_struct); + + prog.Value = 0.5; + ks_result = runKolmogorovSmirnovTest(input_struct, edge_test_result); + + prog.Value = 0.75; + qcKSOutput(ks_result.p, input_struct) + +end + +function ks_result = runKolmogorovSmirnovTest(input_struct, edge_result) + import nla.TriMatrix nla.TriMatrixDiag + + ks_result = struct(); + number_of_networks = input_struct.net_atlas.numNets(); + ks_result.p = TriMatrix(number_of_networks, TriMatrixDiag.KEEP_DIAGONAL); + ks_result.ks = TriMatrix(number_of_networks, TriMatrixDiag.KEEP_DIAGONAL); + + for network1 = 1:number_of_networks + for network2 = 1:network1 + network_rho = edge_result.coeff.get(input_struct.net_atlas.nets(network1).indexes,... + input_struct.net_atlas.nets(network2).indexes); + [~, p, ks] = kstest(network_rho); + ks_result.p.set(network1, network2, p); + ks_result.ks.set(network1, network2, ks); + end + end +end + +function qcKSOutput(ks_result_p_value, edge_test_options) + % This will open the qc figure for the KS test + + network_test_options = nla.net.genBaseInputs(); + network_test_options.full_connectome = false; + network_test_options.within_network_pair = false; + network_test_options.fdr_correction = nla.net.mcc.None(); + edge_test_options.prob_max = 0.05; + default_discrete_colors = 1000; + + p_value_max = network_test_options.fdr_correction.correct(edge_test_options.net_atlas,... + edge_test_options, ''); + + color_map = nla.net.result.NetworkResultPlotParameter.getColormap(default_discrete_colors,... + p_value_max); + + fig = nla.gfx.createFigure(); + % Also remember to move this in read the docs + matrix_plot = nla.gfx.plots.MatrixPlot(fig, sprintf("Non-permuted Kolmogorov-Smirnov Test p-value\nSmaller values are less normal"), ks_result_p_value, edge_test_options.net_atlas.nets, nla.gfx.FigSize.LARGE,... + 'lower_limit', 0.00, 'upper_limit', p_value_max, 'color_map', color_map); + matrix_plot.displayImage(); + width = matrix_plot.image_dimensions('image_width'); + height = matrix_plot.image_dimensions('image_height'); + + fig.Position(3) = width; + fig.Position(4) = height; +end \ No newline at end of file diff --git a/NLAQualityControl.mlapp b/NLAQualityControl.mlapp index 335374a3..97ded08b 100644 Binary files a/NLAQualityControl.mlapp and b/NLAQualityControl.mlapp differ diff --git a/docs/source/network_level_tests.rst b/docs/source/network_level_tests.rst index db40d8a8..b9eff44b 100644 --- a/docs/source/network_level_tests.rst +++ b/docs/source/network_level_tests.rst @@ -53,16 +53,6 @@ Provided Tests * :math:`\textstyle E_i = \sum_{}\frac{\text{thresholded & binarized ROIs}}{\text{number of ROIs}} \scriptstyle * (\text{number of ROIs in the network-pair of interest})` * :math:`O_i`: non-permuted, nominally thresholded, and binarized edge-level *p*-values for the network-pair of interest -* **Kolmogorov-Smirnov** - - * MATLAB `kstest2 `_ function. - - *Inputs:* - * Edge-level correlation coefficients for the network-pair of interest - * Edge-level correlation coefficients across the full connectome - - * **Note**: This input is not used for single-sample tests - * **Wilcoxon rank-sum test** * MATLAB `ranksum `_ function. diff --git a/docs/source/quality_control.rst b/docs/source/quality_control.rst new file mode 100644 index 00000000..e69de29b