diff --git a/inst/randtest.m b/inst/randtest.m index e68949bd..b1d2db5b 100755 --- a/inst/randtest.m +++ b/inst/randtest.m @@ -79,6 +79,7 @@ function [pval, stat, fpr, STATS] = randtest (x, y, nreps, func, seed) + % Check if we are running Octave or Matlab info = ver; ISOCTAVE = any (ismember ({info.Name}, 'Octave')); @@ -104,7 +105,7 @@ % Check the number of function arguments if (nargin < 2) - error ('randtest: X and Y must be provided'); + error ('randtest: X and Y must be provided') end if (nargin > 6) error ('randtest: Too many input arguments') diff --git a/inst/randtest1.m b/inst/randtest1.m index df12aea1..13e9a251 100755 --- a/inst/randtest1.m +++ b/inst/randtest1.m @@ -15,21 +15,21 @@ % to ascertain whether data sample in the column vector A comes from a % population with mean equal to the value M. The value returned is a 2- % tailed p-value against the null hypothesis computed using the absolute -% values of the test statistics. This function works by subtracting the -% value M from A +% values of the mean. This function generates resamples by independently +% and randomly flipping the signs of values in (A - M). % % 'PVAL = randtest1 (A, M, NREPS)' specifies the number of resamples to % take in the randomization test. By default, NREPS is 5000. If the number % of possible permutations is smaller than NREPS, the test becomes exact. -% For example, if the number of sampling units in the sample is 12, then -% the number of possible permutations is 2^12 = 4096, so NREPS will be -% truncated at 4096 and sampling will systematically evaluate all possible -% permutations. +% For example, if the number of sampling units (i.e. rows) in the sample +% is 12, then the number of possible permutations is 2^12 = 4096, so NREPS +% will be truncated at 4096 and sampling will systematically evaluate all +% possible permutations. % -% 'PVAL = randtest1 (A, M, NREPS, FUNC)' also specifies a custom -% function calculated on the original samples, and the permuted or -% randomized resamples. Note that FUNC must compute a location parameter -% and should either be a: +% 'PVAL = randtest1 (A, M, NREPS, FUNC)' specifies a custom function +% calculated on the original samples, and the permuted or randomized +% resamples. Note that FUNC must compute a location parameter and +% should either be a: % o function handle or anonymous function, % o string of function name, or % o a cell array where the first cell is one of the above function @@ -37,11 +37,11 @@ % to that function (other than the data arguments). % See the built-in demos for example usage using the mean. % -% 'PVAL = randtest1 (A, M, NREPS, FUNC, SEED)' initialises the -% Mersenne Twister random number generator using an integer SEED value so -% that the results of 'randtest1' results are reproducible when the test -% is approximate (i.e. when using randomization if not all permutations -% can be evaluated systematically). +% 'PVAL = randtest1 (A, M, NREPS, FUNC, SEED)' initialises the Mersenne +% Twister random number generator using an integer SEED value so that +% the results of 'randtest1' are reproducible when the test is approximate +% (i.e. when using randomization if not all permutations can be +% evaluated systematically). % % 'PVAL = randtest1 ([A, GA], M, ...)' also specifies the sampling % units (i.e. clusters) using consecutive positive integers in GA for A. @@ -49,9 +49,9 @@ % for example in the cases of nested experimental designs. Note that when % sampling units contain different numbers of values, function evaluations % after sampling cannot be vectorized. If the parallel computing toolbox -% (Matlab) or package (Octave) is installed and loaded, then the function -% evaluations will be automatically accelerated by parallel processing -% on platforms with multiple processors. +% (Matlab) or parallel package (Octave) is installed and loaded, then the +% function evaluations will be automatically accelerated by parallel +% processing on platforms with multiple processors. % % '[PVAL, STAT] = randtest1 (...)' also returns the test statistic. % @@ -89,7 +89,7 @@ % Check the number of function arguments if (nargin < 2) - error ('randtest1: A and m must be provided'); + error ('randtest1: A and m must be provided') end if (nargin > 5) error ('randtest1: Too many input arguments') @@ -203,6 +203,4 @@ %! pval3 = randtest1 (A, M, 5000); %! pval4 = randtest1 (A, M, [], [], 1); %! pval5 = randtest1 (A, M, [], 'mean', 1); -%! pval6 = randtest1 (A, M, [], {@mean,'omitnan'}, 1); -%! pval7 = randtest1 (A, M, [], {'mean','omitnan'}, 1); -%! pval8 = randtest1 (A, M, [], @smoothmedian, 1); +%! pval6 = randtest1 (A, M, [], @smoothmedian, 1); diff --git a/inst/randtest2.m b/inst/randtest2.m index d4b23735..9e2179b0 100755 --- a/inst/randtest2.m +++ b/inst/randtest2.m @@ -33,9 +33,6 @@ % across A and B corresponds to a pair of matched observations. % Within each pair, the allocation of data to samples A or B is % permuted or randomized. -% See the built-in demo 2 for example usage on how to use 'randtest2' -% with paired == true to perform a one-sample randomization/permutation -% test. % % 'PVAL = randtest2 (A, B, PAIRED, NREPS)' specifies the number of resamples % without replacement to take in the randomization test. By default, NREPS @@ -77,9 +74,9 @@ % and B only where the clusters have the same identifier. Note that when % sampling units contain different numbers of values, function evaluations % after sampling cannot be vectorized. If the parallel computing toolbox -% (Matlab) or package (Octave) is installed and loaded, then the function -% evaluations will be automatically accelerated by parallel processing -% on platforms with multiple processors. +% (Matlab) or Parallel package (Octave) is installed and loaded, then the +% function evaluations will be automatically accelerated by parallel +% processing on platforms with multiple processors. % % '[PVAL, STAT] = randtest2 (...)' also returns the test statistic. % @@ -147,7 +144,7 @@ % Check the number of function arguments if (nargin < 2) - error ('randtest2: A and B must be provided'); + error ('randtest2: A and B must be provided') end if (nargin > 6) error ('randtest2: Too many input arguments') @@ -526,17 +523,6 @@ %! % paired or matching samples (assuming i.i.d and exchangeability). (Note %! % that the log transformation is necessary to make the p-value two-tailed) %! pval = randtest2 (A, B, true, 5000, @(A, B) log (var (A) ./ var (B))) -%! -%! % One-sample randomization test comparing the difference in the mean between -%! % a sample (in this case B) and a population value (in this case 120, which -%! % we have called m). As we can see from this example, a one-sample -%! % randomization/permutation test is a special case of a paired two-sample -%! % test designed to flip the sign of the sample values. Note that the function -%! % should be in mean (as demonstrated below), not the default Wasserstein -%! % metric function. -%! m = 120; % population value of the mean -%! C = B - m; % subtract population value from the sample -%! pval = randtest2 (C, -C, true, 5000, @(A, B) mean (A)) %!demo %! diff --git a/test/test_script.m b/test/test_script.m index 098cad60..442bd61f 100755 --- a/test/test_script.m +++ b/test/test_script.m @@ -127,7 +127,7 @@ bootci (1999, {@mean, y}, 'alpha', 0.1, 'type', 'stud', 'nbootstd', 100); bootci (1999, {@mean, y}, 'alpha', 0.1, 'type', 'cal'); bootci (1999, {@mean, y}, 'alpha', 0.1, 'type', 'cal', 'nbootcal', 199); - g = reshape (repmat ([1:5], 4, 1), 20, []); + g = reshape (repmat ((1:5), 4, 1), 20, []); bootci (1999, {@mean, y}, 'alpha', 0.1, 'strata', []); bootci (1999, {@mean, y}, 'alpha', 0.1, 'type', 'norm', 'strata', g); bootci (1999, {@mean, y}, 'alpha', 0.1, 'type', 'per', 'strata', g); @@ -718,9 +718,7 @@ pval3 = randtest1 (A, M, 5000); pval4 = randtest1 (A, M, [], [], 1); pval5 = randtest1 (A, M, [], 'mean', 1); - pval6 = randtest1 (A, M, [], {@mean,'omitnan'}, 1); - pval7 = randtest1 (A, M, [], {'mean','omitnan'}, 1); - pval8 = randtest1 (A, M, [], @smoothmedian, 1); + pval6 = randtest1 (A, M, [], @smoothmedian, 1); % randtest2:test:1 X = randn (3,1);