function [is_significant,p_value] = testValue(base_distribution,test_value,alpha); % Based on a distribution of slopes, test whether a given test slope % is significant for a given significance level alpha. % % USAGE: is_significant = testSlope(slope_distribution,test_slope,alpha); % % OUTPUT: % is_significant: 1 for significant, 0 for insignificant % % INPUT: % base_distribution: Underlying slope distribution % test_value: Which slope value to test? % alpha: Significance level % ----------------------------------------- % % ESTIMATE CUMULATIVE DISTRIBUTION FUNCTION % % ----------------------------------------- % % sort data in ascending order sorted_data = sort(base_distribution); % "integrate" the sorted data, normalize the integration estimated_cdf = cumsum(sorted_data)./sum(sorted_data); % ---------------------------------------------- % % CALCULATE CRITICAL VALUES FOR A TWO-SIDED TEST % % ---------------------------------------------- % % For a two-sided test, the significance level % is the TOTAL significance level, i.e. the % tail-specific significance level is alpha/2. % A two-sided test is appropriate if the % test statistic might be larger or smaller % than the reference value. % source: https://stats.idre.ucla.edu/other/mult-pkg/faq/general/ % faq-what-are-the-differences-between-one-tailed-and-two-tailed-tests/ % find the two ciritical values crit_levels = [alpha/2 1-alpha/2]; crit_values = zeros(1,2); for c_level = 1:2 use_level = crit_levels(c_level); % where is the closest value in the cdf? [minimum_distance cdf_index] = min(abs(estimated_cdf-use_level)); % what is the corresponding slope value? % this is the critical value crit_values(c_level) = sorted_data(cdf_index); % for: compute both ciritcal levels end % --------------- % % THE ACTUAL TEST % % --------------- % is_significant = ( ( test_value < crit_values(1) ) | ( test_value > crit_values(2) ) );